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



这是我在调用 AWS Lambda 函数后收到的错误:

发生错误:无效的 Lambda 响应:

收到来自 Lambda 的无效响应:无法构造 IntentResponse:没有字符串参数构造函数/工厂方法可以从字符串值反序列化("谢谢,您的披萨已订购"(,位于 [来源:"谢谢,您的披萨已订购。

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;
};

看起来您是从其中一个示例文档中获取的回复:

"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."
} 
}

最新更新