Я пытаюсь создать чат-бота, который использует карточки ответов в одном из своих слотов. Я хочу попробовать обновить карточки ответов на AWS lambda, а не на amazon lex, поскольку мне не нужны изображения в карточках. Но когда я пытаюсь запустить его, он выдает ошибку «Недопустимый лямбда-ответ: получен ответ об ошибке от лямбда-выражения: не обработано». Слот, который я хочу иметь для карточек ответа, - это слот сектора. Что-то не так с моим кодом?
Ниже мой код.
def multiply(intent_request):
invoice = try_ex(lambda: intent_request['currentIntent']['slots']['Invoice'])
advance = try_ex(lambda: intent_request['currentIntent']['slots']['CashAdvance'])
datedue = try_ex(lambda: intent_request['currentIntent']['slots']['DueDate'])
sector = try_ex(lambda: intent_request['currentIntent']['slots']['Sector'])
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
last_confirmed_loan = try_ex(lambda: session_attributes['lastConfirmedLoan'])
if last_confirmed_loan:
last_confirmed_loan = json.loads(last_confirmed_loan)
confirmation_context = try_ex(lambda: session_attributes['confirmationContext'])
loan = json.dumps({
'Invoice': invoice,
'CashAdvance': advance,
'DueDate': datedue,
'Sector': sector
})
session_attributes['currentLoan'] = loan
if intent_request['invocationSource'] == 'DialogCodeHook':
# Validate any slots which have been specified. If any are invalid, re-elicit for their value
validation_result = validate_loan_details(intent_request['currentIntent']['slots'])
if not validation_result['isValid']:
slots = intent_request['currentIntent']['slots']
slots[validation_result['violatedSlot']] = None
return elicit_slot(
session_attributes,
intent_request['currentIntent']['name'],
slots,
validation_result['violatedSlot'],
validation_result['message']
)
if sector is not None:
return {
'dialogAction': {
'type': 'elicit_slot',
'fulfillmentState': 'ElicitSlot',
'message': {
'contentType': 'PlainText',
'content': 'What sector?'
},
'responseCard': {
"version": 3,
"contentType": "application/vnd.amazonaws.card.generic",
"genericAttachments": [
{
"title": "Company Sectors",
"subtitle": "Select one",
"buttons": [
{
"text": "Company A",
"value": "32"
},
{
"text": "Company B",
"value": "33"
},
{
"text": "Company C",
"value": "34"
}
]
}
]
}
}
}
session_attributes['currentLoan'] = loan
return delegate(session_attributes, intent_request['currentIntent']['slots'])
logger.debug('LoanDetails under={}'.format(loan))
try_ex(lambda: session_attributes.pop('currentLoan'))
session_attributes['lastConfirmedLoan'] = loan
return close(
session_attributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': 'Multiply can purchase your invoice at $' + invoice + ' for a fee of $_________, are you down for it?'
}
)