1
votes

I've followed tutorials to setup Lex&Lambda. My lambda function returns

return {
            "dialogAction": {
                "type": "ConfirmIntent",
                "intentName": "GetPersonInfo",
                "message": {
                    "contentType": "PlainText",
                    "content": ""
                }
            }
        }

and Lex displays it as single message. When I'm building my bot on aws site I can setup multiple messages as answer(without using lambda) and I would like to do that with lambda function just like on img: https://docs.aws.amazon.com/lex/latest/dg/images/default-response-25a.png.

On aws site I've prepared output for multiple messages and it look like this:

{
  "dialogState": "Fulfilled",
  "intentName": "GetPersonInfo",
  "message": "{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"siema siemanko\"},{\"type\":\"CustomPayload\",\"group\":2,\"value\":\"{\\\"moj\\\":\\\"json\\\"}\"}]}",
  "messageFormat": "Composite",
...
}

I've noticed that Lex expect "dialogAction" as lambda output and multiple message feature is used in "PostText" and "PostContent". I know, that dialogAction is used to build PostText/PostContent object.

I also would like to send different message to speech, different to display as text and another as a JSON (for my Frontend). Right now my solution is to send everything as PlainText message in dialogAction object and then via my front end execute Polly to read message prepared for speach. Is this possible to do such stuff just with Lex and lambda?

1

1 Answers

0
votes

The only way I know to display multiple messages is to do that via Lex configuration on AWS Lex side. As an example: 1. You create an intent with an utterance I want to get information about user {UserEmailAddress}. 2. You create a required slot UserEmailAddress and non-required UserFirstName and UserLastName. 3. Once the first slot is filled by an utterance you send a request to your backend API within Lambda exports function to get information about that user via his email address and fill other slots (the code is applicable to Node 8.10 you may create your own Python version): `

exports.handler = async (event, context) => {
    ...
    return context.succeed({
        event.sessionAttributes,
        dialogAction: {
            type: "Delegate",
            {
                ...event.currentIntent.slots,
                UserFirstName: httpResponse.firstName,
                UserLastName: httpResponse.lastName
            }
        }
    })
}

` 4. In "Response" section of your intent you add multiple messages: Here is the information for the user {UserEmailAddress} His first name is {UserFirstName} and his last name is {UserLastName}. 5. Add a response card with the question that contains an utterance as one/many of responses. For example, the question "What do you want to do next?" and a button: Button title: "Get his address", Button value: ""

Ideally the dialog should look like this:

User: I want to get information about user [email protected]
Bot: Here is the information about user [email protected]
Bot: His first name is Simon his last name is Anderson
Bot: What do you want to do next?
     [Get his address]

And when you click the button it will look the same as the ordinary response for a slot.