November 16, 2023 No Comments

Chatbots have become an integral part of modern businesses, providing a convenient way to interact with customers, automate tasks, and enhance user experiences. Amazon Lex, a service offered by Amazon Web Services (AWS), allows you to build powerful and intelligent chatbots that can be integrated into various platforms and applications.

The Amazon Lex-powered chatbot engages with the user, understands their preferences, and provides personalized recommendations, ultimately improving the user’s shopping experience. 

In this blog, we’ll explain things simply and walk you through building chatbots with AWS Lex and other AWS services. 

So come along with me as we will explore the world of AWS services and Lex. We’ll look at how to create chatbots that lighten and enjoy human lives.

Login to Amazon Console

To get started with Amazon Web Services (AWS) and AWS Lex chatbots, you’ll need an AWS account. If you already have one, you can use those credentials to log in. If you don’t have an AWS account, you can easily create a new account to begin your journey into building intelligent chatbots and utilizing AWS services.

Go to the AWS Lex Service

Now, let’s navigate to Amazon Lex within the Amazon Web Services (AWS) console. Once you’ve logged in, follow these steps:

  • In the AWS Management Console, locate the “Services” menu at the top of the screen.
  • Type “Amazon Lex” in the search bar and select “Amazon Lex” from the results
  • You’ll be directed to the Amazon Lex dashboard, where you can start creating and managing your chatbots. It should look something like the screenshot below.

Create a new Bot

To create a new chatbot, look for the “Create Bot” button and click on it.

Fill Up the Form

After clicking on the “Create bot” button, select the “Create a blank Bot” option from the creation methods.

Provide a specific name for your bot in the “Name” field and add a description in the “Description” field. This will help you identify and describe your chatbot’s purpose and configuration.

Next, for IAM permissions, select the “Create a role with basic Amazon Lex permissions” option. This will set up the necessary permissions for your bot to interact with AWS services.

Under the “Children’s Online Privacy Protection Act (COPPA)” section, select “No” if your bot does not target users who are subject to COPPA regulations.

You can set an idle session timeout as desired. This determines how long the bot session will remain active without user interaction. Adjust this value according to your application’s requirements.

Once you’ve configured these settings, click the “Next” button to proceed with the creation of your chatbot.

After clicking “Next” and configuring the previous settings, you will reach a screen where you can select the language and voice interaction options.

In this case, since you mentioned that your application is text-based and doesn’t involve voice interactions, you can select “English (US)” as the language, and choose “None” for voice interaction.

After making these selections, click on the “Done” button to continue.

Intent

Intents are the basic building blocks of a chatbot in AWS Lex. Intents map user input to responses. AWS Lex provides two default intents, ‘NewIntent’ and ‘FallbackIntent’, for each bot you create.

FallbackIntent

When you create a new bot in AWS Lex, the Default Fallback Intent is automatically configured with default responses. This intent is triggered when a user’s input doesn’t match with any other defined intent in your chatbot.

You have the flexibility to customize the text responses in the Fallback Intent to provide more contextually relevant and informative replies to users when their input doesn’t align with a specific intent. By modifying these responses, you can improve the user experience and guide users in a more helpful way.

It’s important to note that, by default, if a user enters input that doesn’t match any intent, AWS Lex will randomly select one of the configured responses from the Fallback Intent to provide a reply. You can add, edit, or remove responses as needed to ensure the chatbot’s behavior aligns with your desired user experience.

NewIntent

NewIntent is automatically configured with various training phrases and responses. This intent will be triggered when the user starts interacting with our chatbot. Even when he hasn’t provided any input, this intent will be invoked.

Now click on “NewIntent”. You can see contexts, slots, sample utterances, confirmation, parameters, code hooks, and responses.

We can start building our bot by adding training phrases and responses.

Training phrases are used for matching with user inputs.

When the User’s input matches with any of these training phrases Default welcome intent triggers.

Response will be returned randomly from the below list of responses which set by you.

Slots

Slots are indeed a crucial component in Amazon Lex for gathering specific information required to fulfill an intent. Here are some important aspects of slots in Amazon Lex:

Slot Definition: A slot is a piece of information that Amazon Lex needs to successfully fulfill an intent. Slots represent data that the chatbot needs from the user to understand and complete a task.

Slot Types: Each slot is associated with a slot type, which defines the kind of data or values that can be provided for that slot. You can use built-in slot types provided by Amazon Lex or create your custom slot types for more specific use cases.

User Input Prompts: During a conversation, Amazon Lex prompts the user to provide values for specific slots. It guides the user to provide information for each slot associated with the intent.

Required Slots: For an intent to be fulfilled, the user must provide values for all the required slots associated with that intent. Required slots are essential for Amazon Lex to understand and complete the user’s request.

Advanced Options: Amazon Lex offers advanced options for configuring slots. You can define prompt variations to make the conversation more natural and engaging. Additionally, you can use rich messages, such as SSML (Speech Synthesis Markup Language), cards, and custom payloads to enhance the user experience and provide more context in responses.

Default Slot Values: You can configure default values for slots to provide initial values when a user doesn’t specify them. This can help streamline the conversation and reduce the effort required from the user.

Create New Intent

Save Current Intent (if editing): If you’re editing an existing intent and want to save your changes, make sure to save the current intent configuration.

Navigate Back to Intents List: Use the “Back to Intents List” option to return to the list of intents for your chatbot.

Add a New Intent: Click on the “Add Intent” button to create a new intent.

Choose “Add Empty Intent”: From the drop-down list, select “Add Empty Intent.” This will create a new intent without predefined training phrases or responses, allowing you to define it from scratch.

After selecting “Add Empty Intent”, you’ll be prompted to provide a name for your new intent.

In the “Intent Name” field, type “<Intent Name>” to give your intent this specific name.

Under the Sample utterances section, we can see the textbox. Enter your training phrases and click the save button.

You need to enter sample utterances as per the intent. You need to decide what type of user input will invoke this intent. For example, for this Introduction intent, I have added “tell me about yourself” and “introduce yourself”.

Now scroll down to the Initial Response section. Every intent must have at least one response. In the message Text box, type a response message and press Enter. We can add 2 more responses in variations. Intent use random responses from the list you have entered. Don’t forget to click on the save button otherwise your changes won’t take effect.

Advanced Responses

In AWS Lex there are multiple types of responses, not just simple Text Responses. You can use it for different purposes to show off your information in a better way. For example, at times you might need to display some image or list of items or external links, etc. In those cases, Advanced responses come in handy.

Click on “Advanced Options” to access additional settings for your response.

Confirmation Responses

AWS Lex, you can add a confirmation message for user interactions that require confirmation. This confirmation message helps ensure that the user’s intent or action is clear and provides a positive user experience. Here’s how you can set it up:

Confirmation Prompt: When defining a response for an intent, you can specify a “Confirmation Prompt.” This is a message that the chatbot will use to confirm the user’s intent or action. For example, it could be a message like, “Are you sure you want to proceed?”

Decline Response: Additionally, you can set a “Decline Response” for situations where the user declines the action or intent. This response is triggered when the user doesn’t confirm the action.

Fulfillment Response

AWS Lex, you can use fulfillment messages to provide users with information about the status of fulfilling their intent. Fulfillment messages are especially useful when your chatbot needs to interact with external services or perform actions in response to a user’s intent. Here’s how you can configure fulfillment messages:

Successful Fulfillment Message: You can define a message that is sent to the user when the intent is successfully fulfilled. This message informs the user that their request has been processed or their intent has been satisfied.

Unsuccessful Fulfillment Message: You can define a message that is sent when the intent cannot be fulfilled. This message can help manage user expectations and provide guidance in cases where the request can’t be completed as expected.

Fulfillment Function with Lambda: AWS Lex allows you to integrate a Lambda function to fulfill the intent. This function can be used to perform custom logic, interact with databases, or connect to other APIs to complete the user’s request.

Fulfillment Start Message: You can define a message to be sent at the beginning of the fulfillment process. This can serve as a confirmation to the user that their request is being processed.

Fulfillment Middle Message: You can define messages that are sent during the fulfillment process. These messages can be used to provide updates to the user while the fulfillment function is running.

Fulfillment End Message: Once the fulfillment process is complete, you can define a message to let the user know the outcome. This is particularly important if the fulfillment involves asynchronous tasks.

Variations of Messages: You can define up to five variations of a message for each response. Amazon Lex will choose one of these messages to send to the user when the response is generated. This adds a level of variability and personalization to the conversation.

Closing response

The closing response in AWS Lex is a critical component of the conversation with the user. It is sent to the user after their intent has been fulfilled. Here are some key points about the closing response:

Purpose: The closing response serves to bring closure to the conversation or to transition the user to the next appropriate action.

Conversation Closure: You can use the closing response to end the conversation with a polite and informative message.

Designing the Conversation Path: The closing response can also be used to set values, configure the next steps, and apply conditions for the conversation flow.

Explicit Next Steps: You can specify explicit next steps based on the user’s interaction and intent, allowing for a more guided and structured conversation.

Conversation Termination: In the absence of a condition or an explicit next step, AWS Lex will naturally end the conversation with your bot after the closing response is delivered.

Fallback: If you don’t provide a closing response or if none of the defined conditions are evaluated to be true, AWS Lex will automatically conclude the conversation with your bot. It’s important to have a closing response or clear conditions to ensure that the user isn’t left hanging without a clear conclusion.

Chatbot Build

When you have finished configuring your chatbot in Amazon Lex and are ready to make it operational, you can use the “Build” option to compile and deploy your chatbot. Here are the steps to build your chatbot:

After completing the setup and configuration of your chatbot, locate the “Build” option in the Amazon Lex console.

Click on the “Build” button. This action triggers the process of building your chatbot, which involves generating the necessary resources and configurations to make your chatbot operational.

Depending on the complexity of your chatbot and the resources required, you may need to wait while Amazon Lex builds your chatbot. The time required for this process can vary.

Once the build process is complete, your chatbot will be ready for use. You can then integrate it into your applications, websites, or other channels to interact with users.

Chatbot Testing

Testing your chatbot is an important step to ensure it’s functioning correctly and providing the desired responses. To test your chatbot in Amazon Lex, follow these steps:

After you’ve built your chatbot, locate the “Test” button in the Amazon Lex console.

Click on the “Test” button to initiate the testing process.

You will be presented with a chat interface where you can interact with your chatbot just as a user would.

Enter test messages and interact with your chatbot to see how it responds. This allows you to verify that the chatbot understands user inputs, triggers the right intents, and provides appropriate responses.

This tutorial has guided you through the process of creating a chatbot using Amazon Lex. You’ve learned how to design conversational flows, integrate natural language understanding, and empower your chatbot to interact with users in a human-like manner. By mastering Amazon Lex, you’re now equipped to build your own intelligent chatbots and explore the endless possibilities of conversational AI in applications, ranging from e-commerce to customer support and beyond.

Write a comment

Your email address will not be published. Required fields are marked *

Want to talk to an Expert Developer?

Our experts in Generative AI, Python Programming, and Chatbot Development can help you build innovative solutions and scale your business faster.