Reference implementation on building a conversational Amazon Lex Bot.
Moviepedia Bot is a chat bot that helps you query information about a movie of your choice. We will be using AWS Lambda, which supports either of Node (0.10 or 4.3), Python (2.7), or Java (8) runtimes. This bot has been written in NodeJS and utilizes. TMDB for quering movies and returing desired information.
Use this end point to upload the lambda code from s3: https://s3-us-west-2.amazonaws.com/re-invent-botworkshop/samples/moviePedia/moviePedia.zip
Zip the code that you downloaded. Note compress the files together not the folder. Now, go to AWS Lambda console. Create a new lambda function. Select "Blank Fuction" as a blueprint. in "Configure triggers" section press next. Now configure your lambda function.
1. Name your lambda function : moviePediaLogic
2. Add Description - Lambda function for Moviepedia bot logic
3. Runtime - Node.js4.3
4. Code Entry - Upload the zip you downloaded
5. Handler Section - Leave as default
6. Select an existing role - lambda_basic_execution
4. Set time to 30 secs
Configure the following test event to test your lambda function.
{
"messageVersion": "1.0",
"invocationSource": "FulfillmentCodeHook",
"userId": "user-1",
"sessionAttributes": {},
"bot": {
"name": "movieInfoApp",
"alias": "$LATEST",
"version": "$LATEST"
},
"outputDialogMode": "Text",
"currentIntent": {
"name": "movieInfo",
"slots": {
"name": "Suicide Squad",
"summary": "Director"
},
"confirmationStatus": "None"
}
}
{
"sessionAttributes": {},
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "Director of Suicide Squad is/are: David Ayer"
}
}
}
Go to Identity and Access Management (IAM) console. In role name, use a name that is unique within your AWS account (for example, lex-exec-role).
In Select Role Type, choose AWS Service Roles, and then choose AWS Lambda.
Note In the current implementation, Amazon Lex service role is not available. Therefore, you first create a role using the AWS Lambda as the AWS service role. After you create the role, you update the trust policy and specify Amazon Lex as the service principal to assume the role. In Attach Policy, choose Next Step (that is, you create a role without any permissions).
Choose the role you created and update policies as follows:
In the Permissions tab, choose Inline Policies, and then attach the following custom policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:InvokeFunction"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
In the Trust Relationships tab, choose Edit Trust Relationship, and specify the Amazon Lex service principal ("lex.amazonaws.com"). The updated policy should look as shown:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lex.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Go to Amazon Lex console on create your Amazon lex bot page. Select custom app and provide the following information, then choose Create.
1. Bot Name: moviePediaInfo
2. Choose an output voice - Salli
3. Set Session Timeout - 5 mins
4. Add AMazon lex basic role to your Bot app - lex-exec-role
In this section you create the two slots types for our ChatBot.
Our first slot type is for the user to input a movie name he wants to inquire on.
Slot Type Name : moviePediaInfomovieName
Click on the slot type you created in the previous step and then add description to your slot type. Let's add in some sample movie names as values here.
Now that you have configured your Slot save your Slot configuration.
Our second slot type is for the user to input what information is he looking for. In this example, our lambda function where the bot logic sits is quering omdb to return values for ratings, votes, actors, plot, director, year of release.
Slot Type Name : moviePediaInfomovieDetails
Click on the slot type you created in the previous step and then add description to your slot type. Let's add in values for our queries here.
Now that you have configured your Slot save your Slot configuration.
Intents help us map our conversations to our slots. Our MoviePedia Chatbox requires creation of a single intent.
Configure some sample utterances for you to start interacting with the bot.
1. Hi
2. Hello Moviepedia
3. Tell me about a movie
4. Tell me about a {name}
Add the following name, slot type and prompt for our ChatBot. Note the sequence. Enter the values for the slot type corresponding to moviename first.
Name Slot Type Prompt
name moviePediaInfomovieName Welcome to MoviePedia! Confirm the movie name you want to know about?
Name Slot Type Prompt
summary moviePediaInfomovieDetails What information are you looking for? Year, Plot, All?
We need to link our Chatbot to the lambda function. Type in an appropiate goodbye message for your users.
Now that you have configured your Intent scroll up and save your Intent configuration.
We will be customizing the error message for our bot users. Click on
error handling. You will notice there are default values set there.
Delete the default values and add in a customized message like. Add this
to the Prompts
section:
Welcome to Moviepedia. Type "Tell me about a movie"
Once you have configured your moviePedia chatbot. Click on build to build your chatbot.
Your browser does not support the video tag.
As, the build suceeds it's time for you to test the chatbot.
Once your Bot is build and tested the next step is to publish our Bot and make it avaialble on Slack, Facebook etc. In this example we will be deploying our Bot on Facebook. To publish your Bot you need to create an Alias. In this example we create an alias for "prod".