java - 无法构造 IntentResponse 实例,已验证的对象为 null

标签 java aws-lambda amazon-lex

我一直在关注 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”时的响应。因此,请更改代码中所需的内容,以便响应返回以下内容:

 {  
    "dialogAction": {
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {
            "contentType": "PlainText",
            "content": "command recieved by OrgBotchatbot is delete asd"
        }
    }
};

关于java - 无法构造 IntentResponse 实例,已验证的对象为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705215/

相关文章:

java - 在 Java 中使用 For 循环中的 Var

java - Twitter Future 超时不适用于整个 flatMap 链

google-chrome - google chrome headless browser 能否用于向最终用户提供 PDF

aws-lambda - 将 "AWS::Lambda::Function"转换为 "AWS::Serverless::Function"

amazon-web-services - 将 AWS Lex 与 Skype 集成

java - Android-关闭其他应用

amazon-web-services - "DependsOn": [] means in cloudformation 是什么意思

chatbot - 如何在lex中创建开放式插槽

python - Amazon Lex 到 Amazon Alexa 或 Google Assistant 的后备功能

java - 高效的树排序