把您的 amazon lex chatbot 與訊息服務集成
TRANSCRIPT
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Jhen-Wei Huang (黃振維)Solutions Architect, AWS
Integrate Your Amazon Lex Chatbot with Any Messaging Service
October 12, 2017
Sponsor
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
The Need for Amazon Lex
Amazon LexGraphical User Interface
Conversational Interface
Text and Speech Language Understanding
SpeechRecognition
Natural Language Understanding
Powered by the same Deep Learning technology as Alexa
Lex Bot Structure
UtterancesSpoken or typed phrases that invoke your intent
BookHotelIntentsAn Intent performs an action in response to natural language user input
SlotsSlots are input data required to fulfill the intent
FulfillmentFulfillment mechanism for your intent
“Book a Hotel”
Book HotelTaipei
“Book a Hotel in Taipei”
Automatic Speech Recognition
Hotel Booking
Taipei City
Natural Language Understanding
Intent/Slot Model
UtterancesHotel BookingCity Taipei CityCheck In Nov 30th
Check Out Dec 2nd
“Your hotel is booked for Nov 30th”
Amazon Polly
Confirmation: “Your hotel is booked for Nov 30th”
ain
“Can I go ahead with the booking?
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
Save, Build, Test, and Publish
Save BuildPreserve the current state on the server
Create versions you can test
PublishCreate a version of your bot with an alias for your clients
TestTest your bot in a chat window on the console
Amazon Lex: Use Cases
Informational BotsManage everyday consumer requests
Application BotsBuild powerful interfaces to mobile applications
• News updates• Weather information• FAQs ….
• Book tickets• Order food• Manage bank accounts ….
Enterprise Productivity BotsStreamline enterprise work activities
• Check sales numbers• Marketing performance• Inventory status ….
Internet of Things (IoT) BotsEnable conversational interfaces for device interactions
• Wearables• Appliances• Auto ….
Lex Console: Designed for Builders
Serverless, event-driven compute service
AWS Lambda = microservice without servers
AWS Lambda
Components of AWS Lambda
• An AWS Lambda function (that you write) • An event source• The AWS Lambda service• The function networking environment
Amazon API Gateway
Create Configure Publish
Maintain Monitor Secure
Fully Managed Service for Your APIs
Built-in integrating Amazon Lex with Facebook
#1: Create Facebook App
http://docs.aws.amazon.com/lex/latest/dg/fb-bot-association.html
#2: Create Page
#3: Create Page Access Token
#4: Create Lex Bot
#5: Setup Facebook Channel
#6: Setup Webhook
Testing the Integration
Integrating Amazon Lex with Twilio SMS
Amazon LexLambdaFunction
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/
Multi-Bot Design
“Concierge” Bot
AWS LambdaFunction
Amazon API Gateway
End User Multiple Messaging Services
AmazonDynamoDB
“Flight-Booking” Bot
“Cruise-Booking” Bot
user-id current-intent
bot ttl
867-5309 BookCruise Cruise-Booking 1494013599
“I want to book a cruise”
#1: Creating an Amazon Lex bothttps://console.aws.amazon.com/lex/home?region=us-east-1
#2: Setting up a Twilio Phone Numberhttps://www.twilio.com/try-twilio
#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());
}
});
#4: HTTPS Endpoint using Amazon API Gateway
#5: Configuring the Twilio Webhook
https://www.twilio.com/console
Your bot can now text!
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
Getting Started
https://console.aws.amazon.com/lex
Remember to complete your evaluations!
Thank you!Get Started: https://aws.amazon.com/lexLex Console: https://console.aws.amazon.com/lex