Book Trip Chatbot Using AWS Lex

Rutvi Pan
4 min readNov 15, 2021


What is Chatbot?

A chatbot is merely a computer program that fundamentally simulates human conversations. It allows a form of interaction between a human and a machine the communication, which happens via messages or voice command. A chatbot is programmed to work independently from a human operator.

Why Chatbot is important?

Chatbot applications streamline interactions between people and services, enhancing customer experience. At the same time, they offer companies new opportunities to improve the customers engagement process and operational efficiency by reducing the typical cost of customer service.

What is AWS Lex?

Amazon Lex is an AWS service for building conversational interfaces for applications using voice and text. Amazon Lex enables any developer to build conversational chatbots quickly. With Amazon Lex, no deep learning expertise is necessary — to create a bot, you just specify the basic conversation flow in the Amazon Lex console. Amazon Lex manages the dialogue and dynamically adjusts the responses in the conversation. Using the console, you can build, test, and publish your text or voice chatbot.

let’s familiarize with few concepts of Lex.

Intent: An intent represents an action that the user wants to perform. A bot will have one or more related intents. For example, an ecommerce bot will have intents to place an order and check order status. Each intent will have descriptive name like PlaceOrder, CheckOrderStatus etc.

Utterances: Utterances are sample phrases user typically uses to convey the intent. For example, user might say ‘Check my order status’ or ‘What is the status of my order’ etc. An intent can have one or more utterances associated with it. The more number of utterances associated with intent the better it is.

Slot: Slot is a parameter associated with an intent which is required to fulfil user’s request. An intent can have zero or more slots. In CheckOrderStatus intent, orderId will be one of the slots. At runtime Lex prompts the user for specific slot values. Slot can be configured as required or optional. User must provide values for all required slots before fulfilling an intent. Utterances are also configured with slot which are the phrases users use to provide slot values.

Slot Type: Each slot has a type. There are built in slot types which can be used or create a custom slot type if required. AMAZON.NUMBER built in slot type can be used for orderId slot. While creating custom slot type, list of values for slot has to be enumerated.

Prompt: Prompt is the phrase used by Lex at runtime to get slot values for an intent. Each slot can have one or more prompts associated with it. Lex randomly picks up one of them. like following image

Lambda Initialization, Validation, Fulfillment: While NLU and conversation flow is taken care by Lex, we need Lambda functions for business logic. Lex provides pre-built integration with Lambda. Lambda function can be used for Initialization, Validation and Fulfillment. Same function can be used for both functionalities or can have different functions depending on complexity.

Here I have made this chatbot for book a trip so by using that user can book a hotel and car for their trips. At last Build chatbot by clicking Build button at top right corner. Once build is successful, it will be ready to test. Bot can be tested from console by clicking ‘Test bot’ section in right pane.

Here when i say book a hotel for today it says that reservation must be scheduled at least one day in advanced so here lambda function is used for validation.

Above screenshot shows how conversation flow happens between user and our bot.

This above screenshot is of WhatsApp message screen. I have used Twilio SMS channel for providing WhatsApp UI to my chatbot.