1
votes

I'm trying to develop a chatbot using AWS Lex. But unfortunately, I'm getting an error while building the chat on Lex. I'm using one intent and 2 slots. For some reason, when the lambda function is connected to the chat, the second value of the slot is saved as null. But when I run it in lambda as a test case, it's successful. Right now, all I want to do is show a response message after the details of the slot is entered.

This is my code

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

And this is the error I'm getting in 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]

3

3 Answers

1
votes

If you are using amazon lexv2, then amazon lex expecting a different JSON response compared to lexv1.

Sample lambda response which is accpeted by lex:

{
  "sessionState": {
    "dialogAction": {
      "type": "Close"
    },
    "intent": {
      "confirmationState": "Confirmed",
      "name": "SearchProducts",
      "state": "Fulfilled",
      
    },
    
  },
  "messages": [
    {
      "contentType": "PlainText",
      "content": "Select from the list",
      
    }
  ]
}

Check here for the full response structure https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html

0
votes

According to the docs, below is the correct format for constructing the final response:

{
        "sessionAttributes": session_attributes,
        "dialogAction":{
            "type":"Close",
            "fulfillmentState":"Fulfilled",
            "message":{
                "contentType":"PlainText",
                "content":message
            }
        }
    }

Use this format for constructing the response to avoid the error.

0
votes

You spelled "fulfilled" incorrectly - you typed "Fullfiled" as pasted in below: DialogAction dialogAction = new DialogAction("Close", "Fullfiled", message);