SUBASH E
SUBASH E

Reputation: 13

Lex V1 group message

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

Upvotes: 1

Views: 332

Answers (1)

Kera
Kera

Reputation: 75

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 (Lex's designer UI). This is different than returning multiple messages through a Lambda function.

Adding the responses in the content designer

enter image description here

A preview of how the responses will look

enter image description here

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 from the Lambda and you cannot return more than one at a time.

The only way you can make Lex V1 appear like it is returning multiple messages is to use a custom front end. 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.

enter image description here

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

Upvotes: 2

Related Questions