【发布时间】:2017-07-06 03:01:37
【问题描述】:
在 Eclipse AWS SDK 中使用 Java8,我创建并上传了一个 lambda 函数,该函数在实现我的 lex 意图时挂钩。 Lambda 接收 JSON 请求并解析没有问题。 然后,我格式化一个简单的“关闭”dialogAction 响应并发送回 lex,并从 lex 控制台中的 Test Bot 页面收到以下错误:
An error has occurred: Received invalid response from Lambda:
Can not construct instance of IntentResponse:
no String-argument constructor/factory method to deserialize
from String value
('{"dialogAction
{"type":"Close","fulfillmentState":"Fulfilled","message":
{"contentType":"PlainText","content":"Thanks I got your info"}}}')
at [Source: "{\"dialogAction\":
{\"type\":\"Close\",\"fulfillmentState\":\"Fulfilled\",\"message\":
{\"contentType\":\"PlainText\",\"content\":\"Thanks I got your
info\"}}}";line: 1, column: 1]
格式(第 1 行,第 1 列)似乎马上就有问题,但我的 JSON 字符串看起来没问题。在handleRequest java函数中返回输出字符串之前,我将它写入Cloudwatch日志,它写如下:
{
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "Thanks I got your info"
}
}
}
我尝试过的事情:
- 删除不需要的消息元素
- 添加非必需属性,如 sessionAttributes, 响应卡等
- 去掉双引号
- 用单引号代替双引号
- 从文档中的示例响应格式消息硬编码 json
是否在 http 标头级别隐藏了某些内容,或者 java8 对 JSON 执行了一些不可见的操作?
【问题讨论】:
-
这个帖子似乎在解决同样的问题:stackoverflow.com/questions/44756575/…
-
类似,是的,但我的问题是 Lex 处理来自 Lambda 的响应,而不是 Lambda 处理来自 Lex 的请求(我能够做到)。
标签: aws-lambda amazon-lex