【问题标题】:Obtaining error while using amazon lex "Invalid Lambda Response: Received invalid response from Lambda"使用 amazon lex 时出现错误“无效的 Lambda 响应:收到来自 Lambda 的无效响应”
【发布时间】:2018-02-28 05:40:43
【问题描述】:

我正在尝试使用 AWS Lex 开发聊天机器人。但不幸的是,我在 Lex 上构建聊天时遇到了错误。我正在使用一个意图和 2 个插槽。由于某种原因,当lambda函数连接到聊天时,槽的第二个值被保存为null。但是当我在 lambda 作为测试用例运行它时,它是成功的。 现在,我要做的就是在输入槽的详细信息后显示一条响应消息。

这是我的代码

public class LexBot implements RequestHandler<Map<String, Object>, Object> {

    @Override
    public Object handleRequest(Map<String, Object> input, Context context) {
        // LexRequest lexRequest = LexRequestFactory.createLexRequest(input);

        String content = "Request came from the bot: ";
        Message message = new Message("PlainText", content);
        DialogAction dialogAction = new DialogAction("Close", "Fullfiled", message);

        return new LexRespond(dialogAction);
    }
}

这是我在 AWS Lex 中遇到的错误:

发生错误:无效的 Lambda 响应:收到无效 来自 Lambda 的响应:无法构造消息实例,问题: 内容在 [来源: {"dialogAction":{"type":"Close","message":{"contentType":"PlainText","some_respond_message":"请求 来自机器人:“}}};行:1,列:122]

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-lex


    【解决方案1】:

    根据docs,下面是构造最终响应的正确格式:

    {
            "sessionAttributes": session_attributes,
            "dialogAction":{
                "type":"Close",
                "fulfillmentState":"Fulfilled",
                "message":{
                    "contentType":"PlainText",
                    "content":message
                }
            }
        }
    

    使用此格式构建响应以避免错误。

    【讨论】:

      【解决方案2】:

      您拼写错误“已完成” - 您输入了“已完成”,如下所示: DialogAction dialogAction = new DialogAction("Close", "Fullfiled", message);

      【讨论】:

        【解决方案3】:

        如果您使用的是 amazon lexv2,那么 amazon lex 期望的 JSON 响应与 lexv1 不同。

        lex 接受的示例 lambda 响应:

        {
          "sessionState": {
            "dialogAction": {
              "type": "Close"
            },
            "intent": {
              "confirmationState": "Confirmed",
              "name": "SearchProducts",
              "state": "Fulfilled",
              
            },
            
          },
          "messages": [
            {
              "contentType": "PlainText",
              "content": "Select from the list",
              
            }
          ]
        }
        

        在此处查看完整的响应结构https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-10-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多