把您的 amazon lex chatbot 與訊息服務集成

37
© 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

Upload: amazon-web-services

Post on 21-Jan-2018

770 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: 把您的 Amazon Lex Chatbot 與訊息服務集成

© 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

Page 2: 把您的 Amazon Lex Chatbot 與訊息服務集成

Sponsor

Page 3: 把您的 Amazon Lex Chatbot 與訊息服務集成

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

Page 4: 把您的 Amazon Lex Chatbot 與訊息服務集成

The Need for Amazon Lex

Amazon LexGraphical User Interface

Conversational Interface

Page 5: 把您的 Amazon Lex Chatbot 與訊息服務集成

Text and Speech Language Understanding

SpeechRecognition

Natural Language Understanding

Powered by the same Deep Learning technology as Alexa

Page 6: 把您的 Amazon Lex Chatbot 與訊息服務集成

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

Page 7: 把您的 Amazon Lex Chatbot 與訊息服務集成

“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?

Page 8: 把您的 Amazon Lex Chatbot 與訊息服務集成

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

Page 9: 把您的 Amazon Lex Chatbot 與訊息服務集成

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

Page 10: 把您的 Amazon Lex Chatbot 與訊息服務集成

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 ….

Page 11: 把您的 Amazon Lex Chatbot 與訊息服務集成

Lex Console: Designed for Builders

Page 12: 把您的 Amazon Lex Chatbot 與訊息服務集成

Serverless, event-driven compute service

AWS Lambda = microservice without servers

AWS Lambda

Page 13: 把您的 Amazon Lex Chatbot 與訊息服務集成

Components of AWS Lambda

• An AWS Lambda function (that you write) • An event source• The AWS Lambda service• The function networking environment

Page 14: 把您的 Amazon Lex Chatbot 與訊息服務集成

Amazon API Gateway

Create Configure Publish

Maintain Monitor Secure

Fully Managed Service for Your APIs

Page 15: 把您的 Amazon Lex Chatbot 與訊息服務集成
Page 16: 把您的 Amazon Lex Chatbot 與訊息服務集成

Built-in integrating Amazon Lex with Facebook

Page 17: 把您的 Amazon Lex Chatbot 與訊息服務集成

#1: Create Facebook App

http://docs.aws.amazon.com/lex/latest/dg/fb-bot-association.html

Page 18: 把您的 Amazon Lex Chatbot 與訊息服務集成

#2: Create Page

Page 19: 把您的 Amazon Lex Chatbot 與訊息服務集成

#3: Create Page Access Token

Page 20: 把您的 Amazon Lex Chatbot 與訊息服務集成

#4: Create Lex Bot

Page 21: 把您的 Amazon Lex Chatbot 與訊息服務集成

#5: Setup Facebook Channel

Page 22: 把您的 Amazon Lex Chatbot 與訊息服務集成

#6: Setup Webhook

Page 23: 把您的 Amazon Lex Chatbot 與訊息服務集成

Testing the Integration

Page 24: 把您的 Amazon Lex Chatbot 與訊息服務集成

Integrating Amazon Lex with Twilio SMS

Page 25: 把您的 Amazon Lex Chatbot 與訊息服務集成

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/

Page 26: 把您的 Amazon Lex Chatbot 與訊息服務集成

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”

Page 27: 把您的 Amazon Lex Chatbot 與訊息服務集成

#1: Creating an Amazon Lex bothttps://console.aws.amazon.com/lex/home?region=us-east-1

Page 28: 把您的 Amazon Lex Chatbot 與訊息服務集成

#2: Setting up a Twilio Phone Numberhttps://www.twilio.com/try-twilio

Page 29: 把您的 Amazon Lex Chatbot 與訊息服務集成

#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());

}

});

Page 30: 把您的 Amazon Lex Chatbot 與訊息服務集成

#4: HTTPS Endpoint using Amazon API Gateway

Page 31: 把您的 Amazon Lex Chatbot 與訊息服務集成

#5: Configuring the Twilio Webhook

https://www.twilio.com/console

Page 32: 把您的 Amazon Lex Chatbot 與訊息服務集成

Your bot can now text!

Page 33: 把您的 Amazon Lex Chatbot 與訊息服務集成

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

Page 34: 把您的 Amazon Lex Chatbot 與訊息服務集成

Getting Started

https://console.aws.amazon.com/lex

Page 35: 把您的 Amazon Lex Chatbot 與訊息服務集成

Remember to complete your evaluations!

Page 36: 把您的 Amazon Lex Chatbot 與訊息服務集成
Page 37: 把您的 Amazon Lex Chatbot 與訊息服務集成

Thank you!Get Started: https://aws.amazon.com/lexLex Console: https://console.aws.amazon.com/lex