【问题标题】:Response cards in aws lambdaaws lambda 中的响应卡
【发布时间】:2018-03-15 04:49:18
【问题描述】:

我正在尝试创建一个在其中一个插槽中使用响应卡的聊天机器人。我想尝试在 AWS lambda 而不是 amazon lex 上更新响应卡,因为我不希望卡中的图像。但是当我尝试运行它时,它会发出错误“无效的 Lambda 响应:收到来自 Lambda 的错误响应:未处理”。我想要响应卡的插槽是扇区插槽。我的代码有问题吗?

下面是我的代码。

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?'
        }
    )

【问题讨论】:

  • 您遇到的错误是什么?在什么话语上?请举例
  • 它在扇区插槽之后发出错误“无效的 Lambda 响应”。我已使用以下详细信息更新了我的问题
  • 您检查过您的 Lambda 函数的 CloudWatch 错误日志吗?您可能会在那里获得详细的日志。

标签: python aws-lambda amazon-lex


【解决方案1】:

看看response structure documented for Amazon Lex。看起来您对 dialogAction "type" 和 "fulfillmentState" 的使用不正确。

类型可以设置为:

  • 关闭
  • 确认意向
  • 委托
  • 引出意图
  • ElicitSlot(不是你的“elicit_slot”)

fulfillmentState 可以设置为:

  • 已完成
  • 失败
当类型设置为关闭时,应使用

fulfillmentState。 可能还有其他语法问题,但这些问题很突出。

【讨论】:

    猜你喜欢
    • 2020-09-27
    • 2018-02-28
    • 2020-03-15
    • 2015-12-04
    • 2021-01-02
    • 2021-02-17
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    相关资源
    最近更新 更多