Search code examples
amazon-web-servicesaws-lambdaamazon-lex

Obtaining error while using amazon lex "Invalid Lambda Response: Received invalid response from Lambda"


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]


Solution

  • 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.