使用 amazon lex "Invalid Lambda Response: Received invalid response from Lambda" 时出现错误
Obtaining error while using amazon lex "Invalid Lambda Response: Received invalid response from Lambda"
我正在尝试使用 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 中遇到的错误:
An error has occurred: Invalid Lambda Response: Received invalid
response from Lambda: Can not construct instance of Message, problem:
content must not be blank at [Source:
{"dialogAction":{"type":"Close","message":{"contentType":"PlainText","some_respond_message":"Request
came from the bot: "}}}; line: 1, column: 122]
根据 docs,以下是构造最终响应的正确格式:
{
"sessionAttributes": session_attributes,
"dialogAction":{
"type":"Close",
"fulfillmentState":"Fulfilled",
"message":{
"contentType":"PlainText",
"content":message
}
}
}
使用此格式构建响应以避免错误。
您拼错了“fulfilled”- 您输入的是粘贴在下面的“Fullfiled”:
DialogAction dialogAction = new DialogAction("Close", "Fullfiled", message);
如果您使用的是 amazon lexv2,那么与 lexv1 相比,amazon lex 期待不同的 JSON 响应。
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
我正在尝试使用 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 中遇到的错误:
An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of Message, problem: content must not be blank at [Source: {"dialogAction":{"type":"Close","message":{"contentType":"PlainText","some_respond_message":"Request came from the bot: "}}}; line: 1, column: 122]
根据 docs,以下是构造最终响应的正确格式:
{
"sessionAttributes": session_attributes,
"dialogAction":{
"type":"Close",
"fulfillmentState":"Fulfilled",
"message":{
"contentType":"PlainText",
"content":message
}
}
}
使用此格式构建响应以避免错误。
您拼错了“fulfilled”- 您输入的是粘贴在下面的“Fullfiled”: DialogAction dialogAction = new DialogAction("Close", "Fullfiled", message);
如果您使用的是 amazon lexv2,那么与 lexv1 相比,amazon lex 期待不同的 JSON 响应。
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