AWS Machine Learning Blog
Enhance Your Amazon Lex Chatbots with Responses
You can now add responses to your Amazon Lex chatbots directly from the AWS Management Console. Use responses to set up dynamic, engaging interactions with your users.
Using responses
Responses are the final element of a bot’s intent, and are displayed to users after the fulfillment of the intent is complete. A response might include anything from a simple goodbye message, to a carousel of pictures with different buttons that invoke another intent, to a prompt. Responses can even be the main element of an intent for some use cases, such as an intent that helps guide the user toward different bot functions.
A response consists of messages that are dynamically selected from a group of predefined messages, which are created by the developer. For example, in a reservation bot, your first message group could contain different ways that the bot can greet the user: “Hello,” “Hi,” and “Greetings.” The second message group could contain different forms of introduction: “I am the reservation bot” and “This is the reservation bot.” A third message group could communicate capabilities: “I can help with car rentals and hotel reservations,” and so on. Amazon Lex uses a message from each of the message groups to dynamically build the responses in a conversation. For example, one conversation could include the following messages:
Another conversation might include these messages:
A response could be just that simple, suggesting that the user respond with a statement that triggers another intent. For example, the user might respond “Car rental.” If “Car rental” matches the utterance for an intent to help rent cars, that intent is triggered seamlessly.
Responses can have as many as three components:
- Messages (every response requires at least one message)
- If the user’s answer to a question in a response is “No,” a closing message
- Response cards
Responses are available in the Amazon Lex console and through the Amazon Lex SDK. Let’s walk through the components to show how to build a response.
Messages
In the Amazon Lex console, the first component in the Responses section is a message or a message group. In the editor, a message group looks like this:
You can create one or more message groups for a response which may help craft a more natural conversation flow. Messages are sent to the client marked by message group (message group one, message group two, and so on), so each group is automatically displayed on separate lines for supported Amazon Lex channels, such as Facebook Messenger, Slack, and Kik. To display messages similarly on custom clients, you can opt to write logic to keep this behavior consistent.
Response messages also can accept custom formatting, enabling you to define a message payload to meet the needs of your application. In the console, choose the format, Message or Custom Markup, for each message group in the message group header. Choosing Custom Markup opens an editor where you can type the message payload:
To apply custom formatting with the Amazon Lex SDK, use the CustomPayload parameter. You can set the format for each message group individually, allowing you to alternate between formats.
A closing response
You can set up your bot to ask a follow-up question in a response. For example, in the preceding example of a reservation bot, you could create a fourth message group with questions such as the following:
For responses that can have “No” as a reply, you can create a closing message. This is also a nice way to conclude the conversation if the user is finished.
To create a closing message, choose Wait for user reply in the Responses section in the console. You are prompted to type the message or messages to be sent when the user replies “No” to an additional interaction. For example, in the trip reservation intent, you might provide a message like the following:
With the Amazon Lex SDK, when creating a follow-up prompt in a response, specify a message that is sent to the user when the reply is “No.”
Response cards
Response cards are the next component in the Responses section of the Amazon Lex console. A response card contains a set of appropriate responses that a user can select from and an image or graphic. Response cards can enrich and simplify interactions for your users, while increasing your bot’s accuracy.
For example, in a hotel booking application, you can configure each button in the response card for a different room type. When the user chooses one of these buttons, the button value for that room type is returned to Amazon Lex to trigger a new intent.
To let the user scroll through options, you can enable a carousel of response cards. In our hotel booking example, each card in the carousel could represent a different hotel, city, or popular resort.
Preview mode
To review your responses, use preview mode.
For example, after building the reservation bot from the earlier example, you can immediately preview the response:
If your message groups contain multiple messages, you can see another response by choosing Refresh response. To return to the editor, choose Exit preview.
Getting started
Responses work natively across the supported Amazon Lex channels (messaging platforms), such as Facebook Messenger, Slack, and Kik. You can also program your custom clients and mobile applications to use responses, including response cards.
To create responses in the console, choose a bot (or create a new one), and fill out the Responses section at the bottom of each intent. All responses require at least one message group with at least one message.
For more information on building responses in Amazon Lex, see the Amazon Lex documentation and FAQs.
Want to learn more about developing chatbots with Amazon Lex? Learn how to build better bots with our two part tutorial!
About the Author
John Reed is a Senior Product Manager with AWS Deep Learning and AI Consoles. He works across AWS AI technologies to improve the user and developer experience. In his spare time, he enjoys tinkering with gadgets, skiing, backpacking, and other outdoor activities.