Lex V1 group message

Viewed 105

I am working on chat bot in Amazon lex v1 ,In that I want to display two messages when the client invoke the bot. But I am facing issue .with lambda

        var messageToUse = {
        contentType : "Composite",
        content :{"messages":[{"type":"PlainText","group":1,"value":"welcome"},{"type":"PlainText","group":2,"value":"To GAC"}]}
        };
  const response = {
        "dialogAction": 
        {"type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": messageToUse
            
    }

}; callback(response);

Expected Result should be this

1 Answers

Lex V1 is limited when it comes to working with the API for message groups. The tutorial you were following was able to get multiple messages by using message groups in the content designer:

Unfortunately, the JSON for messages was not a list/array in Lex V1. It only supported key value pairs. This means that a Lex V1 Bot only expects a single message. If you plan on using a custom front end, you can parse the message.content JSON into different message bubbles yourself.

If you would like to be able to set message groups through a lambda function, I recommend you try using Lex V2. The JSON for messages in Lex V2 expects a list, meaning that you can return multiple messages at once and they will appear in separate bubbles in the Lex V2 test console.

Here is an example of how to do this in Lex V2:

 return {
    "sessionState": {
        "dialogAction": {
            "type": "Close"
        },
        "intent": {
            "confirmationState": "None",
            "name": "TestIntent",
            "state": "Fulfilled"
        }
    },
    "messages": [ 
        { "contentType": "PlainText", "content": "Hi" }, 
        { "contentType": "PlainText", "content": "How are you?" }, 
        { "contentType": "PlainText", "content": "How may I help?" } 
    ]}; 

And also how they appear in the test console.

I'm sorry this isn't the answer you were hoping for but I hope it helps anyway.

Related