从 Lambda 收到无效响应:无法构造 IntentResponse 实例

Received invalid response from Lambda: Can not construct instance of IntentResponse

我一直在 aws lex 上尝试 lambda codehook,这就是我将返回的响应的样子

response = {
            "dialogAction" : {
                "type": "ElicitSlot",
                "message": {    
                    "contentType": "PlainText",
                    "content": "Please make enter value of slot1 first before proceeding."
                },
              "intentName": "AWSLexIntentName",
              "slots": {
                    "slot1" : null,
                    "slot2" : null,
                    "slot3" : null,
                    "slot4" : null,
                    "slot5" : null
              },
              "slotToElicit" : "slot1"
            }
        }

我已经尝试使用 lambda 测试事件对其进行测试,但是在 Lex 上进行测试时,我一直收到错误

An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse, problem: The validated object is null at [Source: {}; line: 1, column: 2]

我还是亚马逊网络服务的新手,并没有那么多编程知识,但我无法追溯这个错误,因为这是 "Source" key isn't found in我的任何代码或亚马逊文档。也感谢您花时间阅读本文。

好的,我明白了为什么 Lex 机器人没有获得任何价值。在我的 lambda 处理程序中,我收到了一个函数的承诺,该函数解析了我需要的响应。在处理程序中,我通过使用 promise.then(data, function(){//do stuff}) 接收此解析,在 then 函数中,我返回包含响应的数据值。

这导致处理程序返回一个未定义的值,所以我所做的是,我没有返回,而是使用了 lambda 的回调功能。

如果解释令人困惑,我很抱歉,因为我也很困惑为什么以及如何工作。

我遇到了同样的错误。所以,我的问题是我使用了 lex v2 但使用了 lex v1 响应格式。 lex v2 具有不同的响应格式,即

{
  "sessionState": {
    "dialogAction": {
      "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
    },
    "intent": {
      "confirmationState": "Confirmed",
      "name": "IntentName",
      "state": "Failed | Fulfilled | InProgress | ReadyForFulfillment",
      
    },
    
  },
  "messages": [
    {
      "contentType": "PlainText",
      "content": "Select from the list",
      
    }
  ]
}

了解更多详情aws lex v2 response