Amazon Lex - Developer Guide

Transcription

Amazon LexDeveloper Guide

Amazon Lex Developer GuideAmazon Lex: Developer GuideCopyright Amazon Web Services, Inc. and/or its affiliates. All rights reserved.Amazon's trademarks and trade dress may not be used in connection with any product or service that is notAmazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages ordiscredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who mayor may not be affiliated with, connected to, or sponsored by Amazon.

Amazon Lex Developer GuideTable of ContentsWhat Is Amazon Lex? . 1Are You a First-time User of Amazon Lex? . 2How It Works . 3Supported Languages . 5Supported Languages and Locales . 5Languages and Locales Supported by Amazon Lex Features . 5Programming Model . 5Model Building API Operations . 6Runtime API Operations . 7Lambda Functions As Code Hooks . 7Managing Messages . 10Types of Messages . 10Contexts for Configuring Messages . 11Supported Message Formats . 15Message Groups . 15Response Cards . 16Managing Conversation Context . 20Setting Intent Context . 20Using Default Slot Values . 22Setting Session Attributes . 23Setting Request Attributes . 24Setting the Session Timeout . 26Sharing Information Between Intents . 26Setting Complex Attributes . 27Using Confidence Scores . 28Session Management . 29Conversation Logs . 30IAM Policies for Conversation Logs . 30Configuring Conversation Logs . 33Encrypting Conversation Logs . 35Viewing Text Logs in Amazon CloudWatch Logs . 36Accessing Audio Logs in Amazon S3 . 38Monitoring Conversation Log Status with CloudWatch Metrics . 39Managing Sessions . 39Switching Intents . 40Resuming a Prior Intent . 41Starting a New Session . 41Validating Slot Values . 42Deployment Options . 42Built-in Intents and Slot Types . 42Built-in Intents . 42Built-in Slot Types . 54Custom Slot Types . 62Slot Obfuscation . 63Sentiment Analysis . 63Tagging Resources . 64Tagging Your Resources . 65Tag Restrictions . 65Tagging Resources (Console) . 65Tagging Resources (AWS CLI) . 67Getting Started . 69Step 1: Set Up an Account . 69Sign Up for AWS . 69Create an IAM User . 70iii

Amazon Lex Developer GuideNext Step . 70Step 2: Set Up the AWS CLI . 70. 71Step 3: Getting Started (Console) . 71Exercise 1: Create a Bot Using a Blueprint . 71Exercise 2: Create a Custom Bot . 98Exercise 3: Publish a Version and Create an Alias . 109Step 4: Getting Started (AWS CLI) . 110Exercise 1: Create a Bot . 110Exercise 2: Add a New Utterance . 122Exercise 3: Add a Lambda Function . 126Exercise 4: Publish a Version . 129Exercise 5: Create an Alias . 133Exercise 6: Clean Up . 134Versioning and Aliases . 135Versioning . 135The LATEST Version . 135Publishing an Amazon Lex Resource Version . 136Updating an Amazon Lex Resource . 136Deleting an Amazon Lex Resource or Version . 136Aliases . 137Using Lambda Functions . 139Lambda Function Input Event and Response Format . 139Input Event Format . 139Response Format . 144Amazon Lex and AWS Lambda Blueprints . 149Updating a Blueprint for a Specific Locale . 149Deploying Bots . 150Deploying an Amazon Lex Bot on a Messaging Platform . 150Integrating with Facebook . 152Integrating with Kik . 154Integrating with Slack . 157Integrating with Twilio SMS . 162Deploying an Amazon Lex Bot in Mobile Applications . 164Importing and Exporting . 165Exporting and Importing in Amazon Lex Format . 165Exporting in Amazon Lex Format . 165Importing in Amazon Lex Format . 166JSON Format for Importing and Exporting . 167Exporting to an Alexa Skill . 170Bot Examples . 171Schedule Appointment . 171Overview of the Bot Blueprint (ScheduleAppointment) . 173Overview of the Lambda Function Blueprint (lex-make-appointment-python) . 174Step 1: Create an Amazon Lex Bot . 174Step 2: Create a Lambda Function . 176Step 3: Update the Intent: Configure a Code Hook . 177Step 4: Deploy the Bot on the Facebook Messenger Platform . 178Details of Information Flow . 178Book Trip . 189Step 1: Blueprint Review . 191Step 2: Create an Amazon Lex Bot . 192Step 3: Create a Lambda function . 195Step 4: Add the Lambda Function as a Code Hook . 195Details of the Information Flow . 198Example: Using a Response Card . 211Updating Utterances . 214iv

Amazon Lex Developer GuideIntegrating with a Web site . 215Call Center Agent Assistant . 215Step 1: Create an Amazon Kendra Index . 217Step 2: Create an Amazon Lex Bot . 217Step 3: Add a Custom and Built-in Intent . 217Step 4: Set up Amazon Cognito . 218Step 5: Deploy Your Bot as a Web Application . 219Step 6: Use the Bot . 220Migrating a bot . 222Migrating a bot (Console) . 222Migrating a Lambda function . 223Migration messages . 223Built-in intent . 223Built-in slot type . 223Conversation logs . 224Message groups . 224Prompts and phrases . 224Other Amazon Lex V1 features . 224Migrating a Lambda function . 225List of updated fields . 226Security . 231Data Protection . 231Encryption at Rest . 232Encryption in Transit . 233Key Management . 233Identity and Access Management . 233Audience . 233Authenticating with Identities . 234Managing Access Using Policies . 235Learn More . 236How Amazon Lex Works with IAM . 236Identity-Based Policy Examples . 241AWS managed policies . 245Troubleshooting . 251Using Service-Linked Roles . 253Service-Linked Roles Permissions for Amazon Lex . 253Creating a Service-Linked Role for Amazon Lex . 253Editing a Service-Linked Role for Amazon Lex . 253Deleting a Service-Linked Role for Amazon Lex . 253Supported Regions for Amazon Lex Service-Linked Roles . 254Monitoring . 254Monitoring Amazon Lex with CloudWatch . 254Logging Amazon Lex API Calls with AWS CloudTrail . 262Compliance Validation . 265Resilience . 266Infrastructure Security . 266Guidelines and Quotas . 267Supported Regions . 267General Guidelines . 267Quotas . 269Runtime Service Quotas . 270Model Building Quotas . 271API Reference . 275Actions . 275Amazon Lex Model Building Service . 276Amazon Lex Runtime Service . 426Data Types . 457v

Amazon Lex Developer GuideAmazon Lex Model Building Service .Amazon Lex Runtime Service .Document History .AWS glossary .vi458504518523

Amazon Lex Developer GuideWhat Is Amazon Lex?Amazon Lex is an AWS service for building conversational interfaces for applications using voice andtext. With Amazon Lex, the same conversational engine that powers Amazon Alexa is now availableto any developer, enabling you to build sophisticated, natural language chatbots into your new andexisting applications. Amazon Lex provides the deep functionality and flexibility of natural languageunderstanding (NLU) and automatic speech recognition (ASR) so you can build highly engaging userexperiences with lifelike, conversational interactions, and create new categories of products.Amazon Lex enables any developer to build conversational chatbots quickly. With Amazon Lex, no deeplearning expertise is necessary—to create a bot, you just specify the basic conversation flow in theAmazon Lex console. Amazon Lex manages the dialogue and dynamically adjusts the responses in theconversation. Using the console, you can build, test, and publish your text or voice chatbot. You can thenadd the conversational interfaces to bots on mobile devices, web applications, and chat platforms (forexample, Facebook Messenger).Amazon Lex provides pre-built integration with AWS Lambda, and you can easily integrate with manyother services on the AWS platform, including Amazon Cognito, AWS Mobile Hub, Amazon CloudWatch,and Amazon DynamoDB. Integration with Lambda provides bots access to pre-built serverless enterpriseconnectors to link to data in SaaS applications, such as Salesforce, HubSpot, or Marketo.Some of the benefits of using Amazon Lex include: Simplicity – Amazon Lex guides you through using the console to create your own chatbot in minutes.You supply just a few example phrases, and Amazon Lex builds a complete natural language modelthrough which the bot can interact using voice and text to ask questions, get answers, and completesophisticated tasks. Democratized deep learning technologies – Powered by the same technology as Alexa, AmazonLex provides ASR and NLU technologies to create a Speech Language Understanding (SLU) system.Through SLU, Amazon Lex takes natural language speech and text input, understands the intentbehind the input, and fulfills the user intent by invoking the appropriate business function.Speech recognition and natural language understanding are some of the most challenging problemsto solve in computer science, requiring sophisticated deep learning algorithms to be trained onmassive amounts of data and infrastructure. Amazon Lex puts deep learning technologies within reachof all developers, powered by the same technology as Alexa. Amazon Lex chatbots convert incomingspeech to text and understand the user intent to generate an intelligent response, so you can focus onbuilding your bots with differentiated value-add for your customers, to define entirely new categoriesof products made possible through conversational interfaces. Seamless deployment and scaling – With Amazon Lex, you can build, test, and deploy your chatbotsdirectly from the Amazon Lex console. Amazon Lex enables you to easily publish your voice or textchatbots for use on mobile devices, web apps, and chat services (for example, Facebook Messenger).Amazon Lex scales automatically so you don’t need to worry about provisioning hardware andmanaging infrastructure to power your bot experience. Built-in integration with the AWS platform – Amazon Lex has native interoperability with other AWSservices, such as Amazon Cognito, AWS Lambda, Amazon CloudWatch, and AWS Mobile Hub. You1

Amazon Lex Developer GuideAre You a First-time User of Amazon Lex?can take advantage of the power of the AWS platform for security, monitoring, user authentication,business logic, storage, and mobile app development. Cost-effectiveness – With Amazon Lex, there are no upfront costs or minimum fees. You are chargedonly for the text or speech requests that are made. The pay-as-you-go pricing and the low cost perrequest make the service a cost-effective way to build conversational interfaces. With the Amazon Lexfree tier, you can easily try Amazon Lex without any initial investment.Are You a First-time User of Amazon Lex?If you are a first-time user of Amazon Lex, we recommend that you read the following sections in order:1. Getting Started with Amazon Lex (p. 69) – In this section, you set up your account and testAmazon Lex.2. API Reference (p. 275) – This section provides additional examples that you can use to exploreAmazon Lex.2

Amazon Lex Developer GuideAmazon Lex: How It WorksAmazon Lex enables you to build applications using a speech or text interface powered by the sametechnology that powers Amazon Alexa. Following are the typical steps you perform when working withAmazon Lex:1. Create a bot and configure it with one or more intents that you want to support. Configure the bot soit understands the user's goal (intent), engages in conversation with the user to elicit information, andfulfills the user's intent.2. Test the bot. You can use the test window client provided by the Amazon Lex console.3. Publish a version and create an alias.4. Deploy the bot. You can deploy the bot on platforms such as mobile applications or messagingplatforms such as Facebook Messenger.Before you get started, familiarize yourself with the following Amazon Lex core concepts andterminology: Bot – A bot performs automated tasks such as ordering a pizza, booking a hotel, ordering flowers, andso on. An Amazon Lex bot is powered by Automatic Speech Recognition (ASR) and Natural LanguageUnderstanding (NLU) capabilities. Each bot must have a unique name within your account.Amazon Lex bots can understand user input provided with text or speech and converse in naturallanguage. You can create Lambda functions and add them as code hooks in your intent configurationto perform user data validation and fulfillment tasks. Intent – An intent represents an action that the user wants to perform. You create a bot to supportone or more related intents. For example, you might create a bot that orders pizza and drinks. For eachintent, you provide the following required information: Intent name– A descriptive name for the intent. For example, OrderPizza. Intent names must beunique within your account. Sample utterances – How a user might convey the intent. For example, a user might say "Can I ordera pizza please" or "I want to order a pizza". How to fulfill the intent – How you want to fulfill the intent after the user provides the necessaryinformation (for example, place order with a local pizza shop). We recommend that you create aLambda function to fulfill the intent.You can optionally configure the intent so Amazon Lex simply returns the information back to theclient application to do the necessary fulfillment.In addition to custom intents such as ordering a pizza, Amazon Lex also provides built-in intents toquickly set up your bot. For more information, see Built-in Intents and Slot Types (p. 42).3

Amazon Lex Developer Guide Slot – An intent can require zero or more slots or parameters. You add slots as part of the intentconfiguration. At runtime, Amazon Lex prompts the user for specific slot values. The user must providevalues for all required slots before Amazon Lex can fulfill the intent.For example, the Ord

Amazon Lex scales automatically so you don't need to worry about provisioning hardware and managing infrastructure to power your bot experience. Built-in integration with the AWS platform - Amazon Lex has native interoperability with other AWS services, such as Amazon Cognito, AWS Lambda, Amazon CloudWatch, and AWS Mobile Hub. You 1