CoffeeBot Creation Instructions

Date:  2017-08-30

This document can be found at: 


Code samples related to Building Better Bots published on the AI Blog


CoffeeBot is a transactional chat bot that can help one order a mocha (relies on AWS Mobile Hub and Android).

Consider this conversation that we would like to support in our bot:

User: May I have a mocha?

CoffeeBot:   What size? small, medium, large?

User:   small

CoffeeBot:   Would you like that iced or hot?

User:   hot

CoffeeBot:   You'd like me to order a small mocha. Is that right?

User:   Make it a large mocha

CoffeeBot:   You'd like me to order a large mocha. Is that right?

User:   yeah

CoffeeBot:   Great! Your mocha will be available for pickup soon. Thanks for using CoffeeBot!

Let's build this voice bot, an Android App that talks to you using Amazon Polly and Amazon Lex. You'll need the following in addition to your AWS account:

First, we'll create the Amazon Lex bot. Then, we'll add some Lambda Functions to bring it to life. Finally, we'll put it all together with Mobile Hub and the Lex Android SDK.

Amazon Lex bot

1. Create bot

  1. From the Amazon Lex console, create a Custom bot with these settings (you can see these in the "Settings" tab later)
  1. Click “Save”.

2. Review the Error handling settings

3. Create Order Beverage Intent

From the left, add a new Intent called cafeOrderBeverageIntent with the following settings and click "Save Intent" to save the Intent.

To work independently in a shared environment, use your initials in the Intent name (e.g., cafeOrderBeverageIntentXXX).

  1. Sample Utterances: add these to the list of sample utterances so the bot recognizes similar phrases (each entry on a separate line)
  1. I would like a {BeverageSize} {BeverageType}
  2. Can I get a {BeverageType}
  3. May I have a {BeverageSize} {Creamer} {BeverageType}
  4. Can I get a {BeverageSize} {BeverageTemp} {Creamer} {BeverageType}
  5. Let me get a {BeverageSize} {Creamer} {BeverageType}
  1. Lambda initialization and validation (leave unchecked)
  2. Skip the Slots section for now.  We’ll create them after we create Slot Types.
  3. Confirmation prompt: You'd like me to order a {BeverageSize} {BeverageType}. Is that right? to confirm and Okay. Nothing to order this time. See you next time! to cancel.
  4. Fulfillment: choose "Return parameters to client" for now

3. Create Slot Types

Add the following Slot types (each value should be a separate entry); remember to "Save slot type" as you go along. To work independently in a shared environment, use your initials in the names (e.g., cafeBeverageTypeXXX).

Note: Although they are saved with the AWS Account, Slot Types will only show up in the list when they are associated in the next step.

Slot type name


Values (each entry on a separate line)


Slot types are shared at the account level so text would help other developers determine if they can reuse this Slot type.

coffee; cappuccino; latte; mocha; chai; espresso; smoothie


kids; small; medium; large; extra large; six ounce; eight ounce; twelve ounce; sixteen ounce; twenty ounce


two percent; skim milk; soy; almond; whole; skim; half and half


kids; hot; iced

4. Add Slots to the Intent

Add the following entries to the list of Slots, choosing the Slot Types created above. Click "Save Intent".



Slot type





What kind of beverage would you like? For example, mocha, chai, etc.




What size? small, medium, large?




What kind of milk or creamer?




Would you like that iced or hot?

6. Test

Build the app and test some of the Utterances in the Test Bot dialog at the bottom right of the Amazon Lex Console. For example, if you say May I have a chai?, does Lex correctly map chai to the BeverageType slot?

Lambda Function

  1. Navigate to the AWS Lambda service web console.
  2. Click on the [Create Function] button.
  3. Click on the [Author from scratch] button.
  4. Ignore the additing of a trigger -- our Lex chatbot will do the triggering.  Just click the [Next] button.
  5. In the Configure function form, and in the Basic Information panel, enter
  1. In the Lambda function code editor panel, clear out the starting code.  Now visit the  cafeOrderCoffee_lambda.js code (source here), copy all of the code into your clipboard (cut!), and finally paste into the editor panel.  To work independently in a shared AWS environment, use your initials in the function name (e.g., cafeOrderCoffeeXXX)
  2. In the Lambda function handler and role panel, choose an IAM role that includes the AWSLambdaBasicExecutionRole Managed Policy.
  1. Skip the Tags panel and the Advanced Settings panel.  Just click [Next]
  2. On the Review form, jump to the bottom and click [Create Function]
  3. After the function has been successfully created, click the Actions drop-down and select Configure the Test event.  Visit the test event JSON code (source here) and cut and paste into the Input test event web form, replacing the staring code already in the editor.
  4. Next, click the [Save and Test] button.  If you successfully cut and paste the lambda function and the test event code, you should see “Execution result: succeeded”
  5. You'll notice that the function checks the bot name it receives (if ( !== 'CoffeeBot')); remember to change this value in the function and in the test event to match the name you used for your bot

Test the bot

  1. From the Lex Console, select the CoffeeBot bot and choose Latest from the version drop down to make changes
  2. Modify the cafeOrderBeverageIntent Intent
  1. Build the bot
  2. Test using the Amazon Lex Console; do you see any responses when you ask May I have a mocha?

Android App

  1. Navigate to the Mobile Hub web console on AWS,
  2. Create a new project called CoffeeBot.
  3. Add the "Conversational Bots" feature to the project.
  4. When prompted, import CoffeeBot.  Mobile Hub takes care of a number of important details behind the scenes. A new Amazon Cognito Federated Identity Pool is created for this new app along with roles so that the users can interact with Lex (using voice and text).
  5. Source code for the new app is immediately available for download.
  6. Select the [Android] option, and then in the next web page select [Download the Sample App]
  7. After unzipping the download, follow the instructions in the READ_ME/index.html file to setup, compile, and run the app.