aws-lex-chatbot
Service icon

AWS Lex Chatbot

Stable version 1.1.1 (Compatible with OutSystems 11)
Uploaded
 on 01 October 2021
 by 
0.0
 (0 ratings)
aws-lex-chatbot

AWS Lex Chatbot

Documentation
1.1.1

Quick guides

Showcase AWS Lex Chatbot:


Useful information:


Creating the sample chatbot on AWS Console

Open Amazon Lex in the AWS Console

On the top-right corner of the console, confirm which region you are using. This needs to match the one you specify in the component.

Then, click the Create button (the blue one, top left corner) to create a new bot.


Upon clicking the button, the AWS console will prompt you with several sample bots or allow you to create a new one from scratch. For the purpose of this tutorial, we’ll use the BookTrip sample and we’ll call it MyBookingAssistant.


Before proceeding, we’ll need to specify the Language of our bot – English (US) for this tutorial. This is the language our bot will use to communicate and expects the user to use as well (either written or spoken).

There are a few more options that we need to account for:

  •          Sentiment Analysis: Amazon Lex uses Amazon Comprehend for performing sentiment analysis on text or speech inputs to your bot. For now you can leave this as “No” (default value).
  •          IAM Role: an infrastructure role needed to interact with your bot. Amazon will create this for you.
  •          COPPA: A setting to specify if the bot is subject to the Children's Online Privacy Protection Act (COPPA). Learn more about this.
  •          Advanced Options: for certain languages, you have the option to enable certain additional features to improve the service. You can learn more about it here. For the purpose of this tutorial, we’ll leave the default value as Yes.
  •          Confidence Score Threshold: the default value is 0.4 (40%). We can leave it as it is.


But what is the confidence score? (rewrite this, it’s copy pasta)

Every time your clients types a message, the bot analyses its accuracy and pairs it with the most matching available interaction. The accuracy is shown as a number: the higher the number, the better the match. This result is called matching score. Usually, If there are three available interactions, the bot will choose the one with the highest result.

Confidence Score is a threshold that determines what the lowest matching score acceptable to trigger an interaction is. If the matching score falls below the confidence score, the bot will trigger fallback interaction, an interaction that asks the user to repeat the query.

By setting the confidence score correctly, you can provide effortless and smooth chatting experience, right for your business.


Finally, click on the create button (bottom right corner) to create the bot. Et voilà, we have our bot created!



Since our bot is based on a sample bot provided by AWS, we already have some configurations in place in terms of functionality to jumpstart our integration.



Starting with the top left corner, we have:

  • MyBookingAssistant, or the name you gave to the bot.
  • Right next to it, we have Latest, which is the bot version that we are currently viewing. It has a small down arrow to change it.
  • Now, the tabs:
    • Editor is where you edit your bot behavior.
    • Settings is where you edit, well, your bot settings. These settings are a more extended version of the questions you were asked when creating it.
    • Channels, if you pretend to distribute it in different platforms (not applicable to OutSystems)
    • And, finally, Monitoring where you, well, monitor your bot behavior and interactions.
  • Intents, which are the actions that you want your bot to be able to fulfill to your users – in our sample we do already have BookCar and BookHotel.
  • Slot types, which is a set of possible (and predefined) values for a variable – in the image above, for the type of rooms when booking a hotel.
  • And, finally, Error Handling, where you define clarification prompts (whenever the bot cannot process the message) or the hang-up phrases (after the bot hit the retry threshold).


Let us now investigate the center part of the screen. This is where we define our intent, the information we need to gather and how our bot interacts with the user.

On the top part we have our intent name (BookHotel) and right next to it we have Latest, which is the intent version we are viewing. Just like the bot itself, our intents (and slots) also have versions. Below it there are the sample utterances. These utterances are the written (or spoken) sentences that will trigger this intent. In the example above, the user could use any of the three to start this intent.

You see the first utterance, with the {Nights} and the {Location}? These are placeholders for the slots. Slots are nothing else than just a variable that we need to gather from the user so we can correctly fulfill the intent.

Note: we are skipping “lambda initialization and validation” and “context” for now since they are not relevant for the scenario at hand. We’ll address this later.

Speaking of slots, our intent has four slots defined: Location, CheckInDate, Nights and RoomType. The Nights and the Location slots can be filled in two ways: by using the utterance – Book a 2 night stay in New York – or by answering the question when prompted. Each slot has a data type, that can be either a built-in type (Date, Number, City) or it can be a custom type, defined in the slot types.

Let us take a deeper look into the slot table:

  • The first column is the priority, which is the order that the question will be asked to the user. You have buttons on the right side of it to switch the order.
  • Second column is if this slot is required to be filled. If required, the intent will not be fulfilled until this slot has the required data.
  • Then you have the name and the data type. If you are using a built-in data type you cannot change the version, but if you are using a custom slot type, you can specify which version should be used.
  • In the prompt column you specify the question your bot will ask the user to retrieve the value.
  • And, finally, you have a settings option for the slot and the ability to remove it.

The settings option allows you to specify additional options for the slot – as seen in the picture – but for the purpose of this tutorial, we don’t need to change anything.

Now to the last three sections of the page – Confirmation Prompt, Fulfillment and Response.

The confirmation prompt is a summary of the current state of the intent (and the respective slot values) before considering the intent fulfilled. The user needs to specify if it is correct or not. In the case the user says no, the “Cancel” message will be shown and the intent discarded.

The fulfillment is the definition of what is executed when the intent is, well, fulfilled. We have two options: invoke a Lambda function or returning the parameters to the client. Since we want to process the response in the OutSystems platform, we’ll return the parameters to the client.

Finally, the Response. The response is what happens after the intent is fulfilled. You have several options here:

  • The first one is to enable custom messages (i.e. Your reservation was successfully registered!) when the intent is fulfilled.
  • The second one (response card) is to enable buttons for some integrations (not relevant for our scenario)
  • The last one is to close the interaction if the user says “no” to the custom message of the first bullet.


Example:

Intent is fulfilled. Bot says: “Thank you for your reservation! Is there anything else I can help you with?”

User says: “No.”

Bot closes the interaction: “Thank you and have a nice day!”


Custom Slot Types

As you have seen previously, we have the ability to configure custom slot types to be used in conjunction with our slots. In this example, our RoomType slot is a custom type and is comprised of the following values – and we have an empty one, too!

So, the first thing here is the slot type name (RoomTypeValues). Right next to it is the version we are viewing – as we said previously, everything has versions! Then we have the slot resolution (more on that later) and, finally, the values. Once you add the slot to the intent, the name will be unchangeable.

The slot resolution has two options: expand values and restrict to slot values and synonyms. There is a slight difference, although the functionality is similar.

When you restrict to slot values and synonyms, you specify the value along with some synonyms that the user can type that will lead to the value. When you select the expand values option, you will just specify the value and, if the user doesn’t type a match, AWS will infer the value from the typed value using synonyms.

The final “step” in configuring our bot behavior is specifying what happens when there’s an error. The error is considered when the bot can’t parse (understand) the input from the user and has two steps:

  • Clarification prompts, where the bot requests the user to “repeat” (or any other custom message) the command that was previously sent, since it could not be parsed by the bot itself.
  • If the clarification fails (or is disabled), the message that will be presented when hanging-up the interaction.

You also have the option to specify the number of retries for clarification before closing up the interaction.


Okay, our bot is now configured! We’re ready to roll! On the top right corner you’ll have two options: build and publish.


If you build, you can test your bot on the right side of the screen. When you’re testing, you’re able to communicate with your bot and see the current state of the dialog (and which intent is being handled). Also, during interaction, you can see how the slots are being populated based on inputs.

Pro tip: When an interaction from the user occurs, a JSON response will be sent back to the integrator (your OutSystems app). That JSON response can be seen by clicking the “Detail” radio button in the Inspect Response section and will allow you to see what’s going on and what changes when the interaction occurs.


Now that we have tested our bot, it’s time to publish it. In order to publish it, just click on the blue “Publish” button and specify an alias that will represent this version:


Creating a User on IAM

Go to the AWS console and search for IAM (or Identity and Access Management). It should show the IAM service.

Click on the Add user button (the blue one) and specify the following:

  • A username: in our case, it can be lexbot.
  • Access type: programmatic access.

Then, on the next screen (step 2), you are prompted for the permissions. Select “Attach existing policies directly” and search for Lex. You should have a result very similar – if not identical to – AmazonLexRunBotsOnly. Select this policy and keep clicking “Next” until the process finishes. You will be then shown the Access Key Id and the Secret Access Key that you need to use in the site properties.


Go to Service Center and find the AWSChatbotConnector module. Then go to the site properties of this module and define the following:


  • ServiceName: leave it as “lex”.
  • RegionName: go to the AWS Lex console and click on the region on the top right corner. You should see something like the image below. Type the region that you have currently selected (in orange, likely).
    • Note: the greyed ones are regions where Lex is not available.
  • AccessKey and SecretKey: Retreived when the IAM user for the chatbot was created.