Skip to content

Latest commit

 

History

History

04_TwilioSMSIntegration

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Module 4: Integrate Amazon Lex with Twilio Programmable SMS

Amazon Lex offers built-in integration with Facebook, Slack, and Twilio SMS. In this module you will integrate your Amazon Lex bot with the Twilio Programmable SMS platform. With this integraton in place, you'll be able to interact with your bot over SMS. You will need to create a Twilio trial account and set up a Twilio SMS-enabled phone number.

Implementation Instructions

Each of the following sections provide an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console and Twilio SMS or you want to explore the services yourself without following a walkthrough.

Signup for a new Twilio trial account

If you don't already have an account, sign up here.

Next, set up a Twilio SMS-enabled phone number where users can send SMS messages to interact with your bot. If you don’t already have a Twilio account, you can sign-up for a trial account, which includes a free phone number. Make sure that your Twilio number has SMS capability turned on, and that you verify your own phone number with Twilio for testing. Remember, Twilio trial account has some limitations for example for the phone number you choose you will be able to interact with verified phone numbers only. Which means in order to test you bot with Twilio integration you have to verify your phone number by adding to Verified Caller ID's in the Twilio console.

On the Twilio Console, note your Twilio Account SID and your Auth Token (Live credentials, not Test).

Step-by-step instructions (expand for details)

  1. Once you sign up for the trial account, take a note of the Twilio Account SID and the Twilio Auth Token under Dashboard - Settings - General settings (note: you likely need to create a Learn & Explore project to get started).

  2. Under Phone Numbers, pick a phone number. This phone number will be the SMS phone number which your bot users will use to interact with the Lex bot you created. Please choose a US number because Twilio supports SMS for US numbers only at this time.

    Twilio Manage Phone Numbers screenshot
  3. Under Verified Caller IDs section, verify the phone number you will use for testing. (For example, this is your mobile number if you intend to use that device to test your bot over SMS.)

Integrate the Twilio Messaging Service Endpoint with the Amazon Lex Bot

To associate the Amazon Lex bot with your Twilio programmable SMS endpoint, create a channel association in the Amazon Lex console. When the channel association has been activated, Amazon Lex returns a callback URL. Record this callback URL for later.

Step-by-step instructions (expand for details)

  1. Open the Amazon Lex console and choose the InternationalPlan bot

  2. Choose the Channels tab; then Twilio SMS

  3. Provide the following information:

    • Channel name: SMSTest
    • Channel description: Twilio SMS channel for dev bot
    • KMS key: aws/lex
    • Alias: dev
    • Use the Auth Token and Account SID from earlier
    • Activate; note the endpoint created for Twilio SMS
    Amazon Lex - Twilio SMS Channel activation
  4. Next, we need to connect the Twilio SMS endpoint to the Amazon Lex bot using the Twilio Console

  5. From Manage Numbers - Active Numbers, select the number to configure the Messaging webhook with the callback URL provided by Amazon Lex above

    Twilio - Update messaging webhook

Test your Amazon Lex bot using Twilio SMS

Test the bot with Twilio SMS enabled (remember to verify your number with Twilio first). Send a message and check the response. Do you see it logged in Twilio? In Amazon Lex? Does it get through to the code hook? When asked for your pin code enter the last four digits of the mobile number you are calling from.

Twilio - Test bot