如何正确地反序列化响应格式

问题描述 投票:0回答:1

这是我调用AWS Lambda函数后得到的错误。

发生了一个错误。Invalid Lambda Response: 收到来自Lambda的无效响应。无法构造IntentResponse实例:没有String-argument constructorfactory方法从String值('Thanks, your pizza has been ordered.')反序列化在[Source: "Thanks, your pizza has been ordered."; line: 1, column: 1]。

    exports.handler = async (event) => {

    const response = {

        "dialogAction": {
    "type": "Close",
    "fulfillmentState": "Fulfilled or Failed",
    "message": {
      "contentType": "PlainText or SSML",
      "content": "Thanks, your pizza has been ordered."
    } 
  }
    };
    return response.dialogAction.message.content;
};
javascript node.js amazon-web-services aws-lambda amazon-lex
1个回答
1
投票

看起来你的响应是从一个示例文档中获取的。

"dialogAction": {
    "type": "Close",
    "fulfillmentState": "Fulfilled or Failed",
    "message": {
      "contentType": "PlainText or SSML",
      "content": "This example won't work as is."
    } 
}

很多人都犯了同样的错误,但是对于这两个人来说 fulfillmentStatecontentType您必须选择其中之一或其他示例值,并完全按照所示的正确大写。

所以要说明的是

设置 fulfillmentState 到任一 FulfilledFailed

还有

设置 contentType 的信息,到任何 PlainTextSSML

"dialogAction": {
    "type": "Close",
    "fulfillmentState": "Fulfilled",
    "message": {
      "contentType": "PlainText",
      "content": "This is a proper example response."
    } 
}
© www.soinside.com 2019 - 2024. All rights reserved.