无法构造 IntentResponse 实例,已验证对象为空
Can not construct instance of IntentResponse, The validated object is null
我一直在关注 youtube 教程:https://www.youtube.com/watch?v=HkMi5xPyz1g&t=1533s
public Object handleRequest(Map<String,Object> input, Context context) {
LexRequest lexRequest= LexRequestFactory.createLexRequest(input);
String orgbotcommand= lexRequest.getCommand()+" "+lexRequest.getOld_variable();
String content = String.format("command recieved by %s is %s",
lexRequest.getBotName(),
orgbotcommand);
Message message = new Message("Plain text",content);
DialogueAction dialogueAction = new DialogueAction("Close", "Fulfilled or Failed", message );
System.out.println(dialogueAction);
return new LexRespond(dialogueAction);
}
以上是我正在使用的 java 代码。
它在使用 lambda 函数测试事件进行测试时为我提供了所需的输出,但是当我尝试从我的 lex bot 调用此 lambda 函数时,它抛出以下错误:
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: {"dialogueAction":
{"type":"Close","fulfillmentState":"Fulfilled or Failed","message":
{"contentType":"Plain text","content":"command recieved by OrgBot is Delete asd"}}}; line: 1, column: 168]
lambda 测试事件的输出是:
{
"dialogueAction": {
"type": "Close",
"fulfillmentState": "Fulfilled or Failed",
"message": {
"contentType": "Plain text",
"content": "command recieved by OrgBotchatbot is delete asd"
}
}
}
我是 Amazan lex 和 lambda 的新手。请告诉我我做错了什么
这可能只是您的回复格式问题。查看 Response Format Docs.
首先,contentType
需要'PlainText'或'SSML'。
所以把'Plain text'
改成'PlainText'
Message message = new Message("PlainText",content);
其次,fulfillmentState
需要 'Fulfulled' 或 'Failed'。
所以从 DialogueAction
行中删除 'or Failed'
为:
DialogueAction dialogueAction = new DialogueAction("Close", "Fulfilled", message );
第三,dialogAction
。 Lex 必须是美国人,因为它只接受将 'Dialogue' 拼写为 'Dialog' 时的响应。因此,在代码中更改您需要的内容,以便响应 returns this:
{
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "command recieved by OrgBotchatbot is delete asd"
}
}
};
输出格式必须遵循特定的最小布局。
我使用以下两个函数来简化它。
当您准备好告诉 Lex 时,只需从任何函数调用它们
//SessionAttributes any session variables
//fulfillmentState - 'Fulfilled' or 'Failed' depending on if successful or not
//message - the actual response text you want lex to say/type
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
function delegate(sessionAttributes, slots) {
return {
sessionAttributes,
dialogAction: {
type: 'Delegate',
slots,
},
};
}
如果您使用的是 Lex v2,则预期的响应格式与 v1 不同。
见https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-response-format
{
"sessionState": {
"activeContexts": [
{
"name": "string",
"contextAttributes": {
"key": "value"
},
"timeToLive": {
"timeToLiveInSeconds": number,
"turnsToLive": number
}
}
],
"sessionAttributes": {
"string": "string"
},
"dialogAction": {
"slotToElicit": "string",
"type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
},
"intent": {
"confirmationState": "Confirmed | Denied | None",
"name": "string",
"slots": {
"string": {
"value": {
"interpretedValue": "string",
"originalValue": "string",
"resolvedValues": [
"string"
]
}
},
"string": {
"shape": "List",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
},
"values": [
{
"shape": "Scalar",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
}
},
{
"shape": "Scalar",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
}
}
]
}
}
},
"state": "Failed | Fulfilled | InProgress | ReadyForFulfillment"
},
"messages": [
{
"contentType": "CustomPayload | ImageResponseCard | PlainText | SSML",
"content": "string",
"imageResponseCard": {
"title": "string",
"subtitle": "string",
"imageUrl": "string",
"buttons": [
{
"text": "string",
"value": "string"
}
]
}
}
],
"requestAttributes": {
"string": "string"
}
}
我一直在关注 youtube 教程:https://www.youtube.com/watch?v=HkMi5xPyz1g&t=1533s
public Object handleRequest(Map<String,Object> input, Context context) {
LexRequest lexRequest= LexRequestFactory.createLexRequest(input);
String orgbotcommand= lexRequest.getCommand()+" "+lexRequest.getOld_variable();
String content = String.format("command recieved by %s is %s",
lexRequest.getBotName(),
orgbotcommand);
Message message = new Message("Plain text",content);
DialogueAction dialogueAction = new DialogueAction("Close", "Fulfilled or Failed", message );
System.out.println(dialogueAction);
return new LexRespond(dialogueAction);
}
以上是我正在使用的 java 代码。
它在使用 lambda 函数测试事件进行测试时为我提供了所需的输出,但是当我尝试从我的 lex bot 调用此 lambda 函数时,它抛出以下错误:
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: {"dialogueAction":
{"type":"Close","fulfillmentState":"Fulfilled or Failed","message":
{"contentType":"Plain text","content":"command recieved by OrgBot is Delete asd"}}}; line: 1, column: 168]
lambda 测试事件的输出是:
{
"dialogueAction": {
"type": "Close",
"fulfillmentState": "Fulfilled or Failed",
"message": {
"contentType": "Plain text",
"content": "command recieved by OrgBotchatbot is delete asd"
}
}
}
我是 Amazan lex 和 lambda 的新手。请告诉我我做错了什么
这可能只是您的回复格式问题。查看 Response Format Docs.
首先,contentType
需要'PlainText'或'SSML'。
所以把'Plain text'
改成'PlainText'
Message message = new Message("PlainText",content);
其次,fulfillmentState
需要 'Fulfulled' 或 'Failed'。
所以从 DialogueAction
行中删除 'or Failed'
为:
DialogueAction dialogueAction = new DialogueAction("Close", "Fulfilled", message );
第三,dialogAction
。 Lex 必须是美国人,因为它只接受将 'Dialogue' 拼写为 'Dialog' 时的响应。因此,在代码中更改您需要的内容,以便响应 returns this:
{
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "command recieved by OrgBotchatbot is delete asd"
}
}
};
输出格式必须遵循特定的最小布局。 我使用以下两个函数来简化它。
当您准备好告诉 Lex 时,只需从任何函数调用它们
//SessionAttributes any session variables
//fulfillmentState - 'Fulfilled' or 'Failed' depending on if successful or not
//message - the actual response text you want lex to say/type
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
function delegate(sessionAttributes, slots) {
return {
sessionAttributes,
dialogAction: {
type: 'Delegate',
slots,
},
};
}
如果您使用的是 Lex v2,则预期的响应格式与 v1 不同。
见https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-response-format
{
"sessionState": {
"activeContexts": [
{
"name": "string",
"contextAttributes": {
"key": "value"
},
"timeToLive": {
"timeToLiveInSeconds": number,
"turnsToLive": number
}
}
],
"sessionAttributes": {
"string": "string"
},
"dialogAction": {
"slotToElicit": "string",
"type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
},
"intent": {
"confirmationState": "Confirmed | Denied | None",
"name": "string",
"slots": {
"string": {
"value": {
"interpretedValue": "string",
"originalValue": "string",
"resolvedValues": [
"string"
]
}
},
"string": {
"shape": "List",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
},
"values": [
{
"shape": "Scalar",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
}
},
{
"shape": "Scalar",
"value": {
"originalValue": "string",
"interpretedValue": "string",
"resolvedValues": [
"string"
]
}
}
]
}
}
},
"state": "Failed | Fulfilled | InProgress | ReadyForFulfillment"
},
"messages": [
{
"contentType": "CustomPayload | ImageResponseCard | PlainText | SSML",
"content": "string",
"imageResponseCard": {
"title": "string",
"subtitle": "string",
"imageUrl": "string",
"buttons": [
{
"text": "string",
"value": "string"
}
]
}
}
],
"requestAttributes": {
"string": "string"
}
}