3. Overview
• “Alexa, What is Amazon Lex?”
• Going Serverless (AWS Lambda & Amazon API
Gateway)
• Integrating with Facebook
• Teach Your Bot How to Text with Twilio SMS
• Can we talk? Adding Support for Voice
4. The Need for Amazon Lex
Amazon Lex
Graphical User
Interface
Conversational
Interface
5. Text and Speech Language Understanding
Speech
Recognition
Natural Language
Understanding
Powered by the same Deep Learning technology as Alexa
6. Lex Bot Structure
Utterances
Spoken or typed phrases that invoke
your intent
BookHotel
Intents
An Intent performs an action in
response to natural language user
input
Slots
Slots are input data required to fulfill
the intent
Fulfillment
Fulfillment mechanism for your intent
7. “Book a Hotel”
Book Hotel
Taipei
“Book a Hotel in
Taipei”
Automatic Speech
Recognition
Hotel Booking
Taipei City
Natural Language
Understanding
Intent/Slot
Model
Utterances
Hotel Booking
City Taipei City
Check In Nov 30th
Check Out Dec 2nd
“Your hotel is booked for
Nov 30th”
Amazon Polly
Confirmation: “Your hotel
is booked for Nov 30th”
a
in
“Can I go ahead
with the booking?
8. Versioning and Alias Support
AliasVersioning
v1 v2 v3 latest
• Supported for Intents, Slots and Bots
• Enables multi-developer environment
• Rollback to previous versions
v1 Dev
v2 Stage
v3 Prod
• Deploy different aliases to different platforms
• Run different stacks for dev, stage and prod
environments
• Target different user groups with different
aliases
9. Save, Build, Test, and Publish
Save Build
Preserve the current
state on the server
Create versions
you can test
Publish
Create a version of your bot
with an alias for your clients
Test
Test your bot in a chat
window on the console
10. Amazon Lex: Use Cases
Informational Bots
Manage everyday consumer requests
Application Bots
Build powerful interfaces to mobile applications
• News updates
• Weather information
• FAQs ….
• Book tickets
• Order food
• Manage bank accounts ….
Enterprise Productivity Bots
Streamline enterprise work activities
• Check sales numbers
• Marketing performance
• Inventory status ….
Internet of Things (IoT) Bots
Enable conversational interfaces for device interactions
• Wearables
• Appliances
• Auto ….
13. Components of AWS Lambda
• An AWS Lambda function (that you write)
• An event source
• The AWS Lambda service
• The function networking environment
14. Amazon API Gateway
Create Configure Publish
Maintain Monitor Secure
Fully Managed Service for Your APIs
25. Amazon LexLambda
Function
Amazon API
Gateway
End User Twilio
Programmable
SMS
Architecture / Message Flow
https://aws.amazon.com/blogs/ai/integrate-your-amazon-lex-bot-with-any-messaging-service/
26. Multi-Bot Design
“Concierge” Bot
AWS
Lambda
Function
Amazon API
Gateway
End User Multiple
Messaging
Services
Amazon
DynamoDB
“Flight-Booking”
Bot
“Cruise-Booking”
Bot
user-id current-
intent
bot ttl
867-5309 BookCruise Cruise-Booking 1494013599
“I want to book a cruise”
27. #1: Creating an Amazon Lex bot
https://console.aws.amazon.com/lex/home?region=us-east-1
28. #2: Setting up a Twilio Phone Number
https://www.twilio.com/try-twilio
29. #3: IAM Policy & the AWS Lambda Function
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"lex:PostText"
],
"Resource": [
"*"
]
}
]
}
AWS.config.region = 'us-east-1';
var lexruntime = new AWS.LexRuntime();
var userNumber = twilioSMS.From.replace('+', '');
var params = {
botAlias: process.env.BOT_ALIAS,
botName: process.env.BOT_NAME,
inputText: twilioSMS.Body,
userId: userNumber,
sessionAttributes: {
}
};
lexruntime.postText(params, function(err, data) {
var twimlResponse = new twilio.TwimlResponse();
if (err) {
console.log(err, err.stack); // an error occurred
twimlResponse.message('Sorry, we ran into a problem at our end.');
callback(err, twimlResponse.toString());
} else {
console.log(data); // got something back from Amazon Lex
twimlResponse.message(data.message);
callback(null, twimlResponse.toString());
}
});
33. Adding Support for Voice
• Amazon Lex can support both Text and Voice
• Use the Twilio <record> verb to prompt/record user input
• Utilize Amazon Lex’s PostContent API call (instead of
PostText)
• Accept: text/plain
• Convert to TwiML and send back to Twilio