Create ChatBot in 5 minutes with Amazon Lex

Hey learners,

This week, I'm back with another helpful AWS service called Amazon Lex, which enables businesses to design chatbots that can also be voice-controlled and are extremely versatile in their development.

Introduction:

Conversational interfaces have become increasingly popular as a way to interact with consumers and deliver seamless experiences in the modern digital era. Amazon Lex, a powerful service by Amazon Web Services (AWS), has emerged as a game-changer in the realm of conversational interfaces. The creation of chatbots and voice-based applications is made easier with Amazon Lex's superior natural language understanding (NLU) features and seamless platform connectivity.

Now, let's talk about the components we need to set up while building a chatbot in Amazon Lex.

Components:

  1. Intent: An intent is a particular task or action that a user wants to carry out as a result of their communication with the chatbot. It symbolizes the underlying intent or significance of the user's input.

    In simple terms, an "Intent" is a 'goal that the user wants to achieve'.

    e.g. - Order a Pizza, Book a hotel, etc.

  2. Utterance: An utterance in Amazon Lex is a particular word or input that a user gives to communicate with a conversational bot. It simulates the vocabulary and idioms that users might employ when interacting with the bot.

    In simple terms, an "utterance" is 'Anything a user says".

    e.g. - I want to book a flight from New York to London, etc.

  1. Slots: Slots are used to capture particular data from users during a discussion, including names, dates, or numbers. They specify the data's structure and give the bot the tools it needs to accurately interpret and respond to user requests.

    In Simple terms, Slots are "Values provided by users, to fulfill an intent".

    e.g. - Chocolate(flavour), India (county), 5 (number).

  2. Fulfillment: Fulfilment is the process of acting or responding to the user's purpose and the gathered slot values. It entails carrying out the required logic to satisfy the user's request.

    In simple terms, it kind of response to user input.

    e.g - Suppose one user says cancel the order, the chatbot will respond with, suppose, "cancelling an order". That's a fulfillment of the intent.

Also, there is a term associated with fulfillment, which is Confirmation.

Before proceeding with fulfillment, confirming a user about the current status is called "Confirmation".

e.g. - "We are now ready to place an order"

Mostly Chatbot runs through the Lambda function.

Image taken from internet and used for educational purpose.

In this blog, we are going to create a Chatbot first and then will test it.

Step 1:

Let's now move to the Amazon Lex console.

Now, let's make our Pizza bot πŸ₯³. Click on Create bot.

  • Name the bot as your wish

  • Choose Create a Role option, which will create a new IAM role with the required permissions. You no need to worry.

  • Choose NO for COPPA as we are doing it for demo purposes.

  • Our session timeout section we are kept by default. You are free to modify it as needed.

  • Click on Next.

  • If you want to change something such as language or Text-to-Speech voices, you can do and click on Create.

Step 2 :

Now our main work is starting. Be creative as much as you want here 😁.

We will create our intent first.

I'll share the screenshot for the first intent with the logic behind it. For others, I'll discuss the logic only, so the blog will not be flooded with screenshots. For any help, I'm always just a DM away 😊.

Welcome Intent:

This intent will serve as the welcome prompt, and it will be followed whenever a user writes for the first time. We now need to educate the bot based on our best guesses of the sentences that people might say. Users might, for instance, begin their message with "Hello" or just write, "Help me with a pizza." We must provide as much as we can.

  • Give an intent name. For us it's WelcomeIntent. Remember space is not allowed.

Now simply come down a bit and under Sample utterances, Add your sentences which will trigger the bot to respond.

  • Now think as user interacted with the bot. Now bot needs to reply to user back right?

    Just below the utterance, there we can find initial response section, where we can set the bot response.

    You can create a simple response. Also, you can set something interesting 😎.

  • Expand the ***Advanced Options > Expand the "Response for acknowledging the user's request" > More response options > In the message group section, add a message > From Top right side 'drop down' > Choose card group > Give the Title (****For us it's "*Hello, Welcome! What would you like to do?") > Expand the "Buttons" > Add buttons in key-value format > Update response

  • Close the dialogue box and click on Save intent.

    Note: I'm only showing a way to make it. Explore and show the community your own creativityπŸ’–.

    Congratulation, πŸŽ‰πŸŽ‰ our working chatbot is ready on a basic level and I can't wait to interact🀩 Let's see how it's working.

    Step -3: Build and Test

    Simply click on build and then test to go for a demo.

    And here you go 😍. You can either type or use text-to-speech to speak and hear the responses.

Now, I'll make add slots also to make it more interactive. To add slots, we need to create a new intent. Let's make it!

Step 4 - Add Slots :

  • Back the page and click on "Add Intent" > Add Empty Intent

  • Give a name and add.

  • Provide Sentences, initial response and now come to slots.

Logic: Here we are creating an intent for taking orders. So sentences will be something as "Order a pizza" , etc. And Initial response we can say as "Sure!"

In Slots, Now we need to give some Slot types which will kind of work here as input variables.

Suppose, the slot type is AMAZON. Date. Anytime the user will provide a date as a response, this slot will take place there.

This is our slot for Name. Like ways, you can create many slots. If any particular slot (such as flavour), is not available, particularly to Amazon, you can use AMAZON.AlphaNumeric which will take any random response.

You can also give them the choice to select, from Advanced options.

Step 5- Confirmation :

After all the slots added, we will go for Confirmation section. Toggle the bar and make it active.

Now, we know what to say when the user will respond with "NO". But if the user says "YES" to the order, then?

Yes, you guessed it correctly! It will then move to the "fulfillment" section.

Step 6 - Fulfillment :

Now, give a closing statement also for a good closure. and Save Intent!

You can create a new intent for "Cancel Order" also. I'm not showing that here as the process is exact same and moreover I'm very excited to see you guys in a LinkedIn post with an updated chatbot!

Final Test :

Let's Build and Test our Final Product! 😎❀️πŸ”₯

It's Just perfectly working, even with voice notes. πŸ”₯πŸŽ‰.

Conclusion:

There are many advantages to using Amazon Lex for creating conversational bots and NLU capabilities. With its built-in language processing, intent recognition, and slot-filling features, developers can easily build chatbots that comprehend and effectively handle user input. It also has a seamless connection with other AWS services like Lambda and S3.

Additionally, Amazon Lex simplifies the development process, reducing the time and effort required to build conversational interfaces while providing advanced features like context management and session handling. Overall, leveraging Amazon Lex empowers developers to create powerful and intelligent conversational experiences with ease.

Thanks for being with me till the end. I hope that provided you with some useful knowledge. Don't forget to spread the word to your friends and community. Part -2 is coming very soon!

Feel free to ask any more questions or for help if you need it.πŸ‘

Follow Sitabja Chatterjee for more content! ✌️

5
Subscribe to my newsletter

Read articles from Sitabja Chatterjee directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sitabja Chatterjee
Sitabja Chatterjee

Hi there! I'm a passionate individual deeply fascinated by the world of cloud computing, DevOps practices, and AWS. My journey in this field is driven by an insatiable curiosity and an unyielding desire to explore and share knowledge with others. As a dedicated cloud enthusiast, I immerse myself in the ever-evolving landscape of cloud technologies, staying up-to-date with the latest trends and advancements. I find immense joy in leveraging the power of cloud platforms, especially AWS, to design scalable and robust solutions that meet modern-day business needs. DevOps has captured my heart with its holistic approach to software development and operations. I firmly believe in the power of collaboration, automation, and continuous improvement to streamline the software delivery process. With my strong foundation in DevOps principles, I strive to bridge the gap between development and operations teams, fostering a culture of efficiency and innovation. One of my greatest passions lies in sharing knowledge with the community. Through blogging and engaging with fellow tech enthusiasts, I aim to demystify complex concepts, provide practical insights, and inspire others to embark on their own cloud and DevOps journeys. I'm a firm believer in the philosophy that knowledge grows when shared, and together we can build a vibrant and supportive community. Join me on this exhilarating expedition as we unravel the intricacies of cloud technologies, dive deep into DevOps practices, and unleash the true potential of AWS. Together, let's explore, learn, and empower one another to thrive in this ever-evolving tech landscape.