Gift Card Amazon Lex Bot with Whatsapp Integration

Nidhi Gajjar
4 min readNov 20, 2021

The project is based on creating a chatbot using Amazon Lex with whatsapp integration. In the project we create a Gift Card chatbot which allows the users to buy giftcard from the available giftcards and send the giftcard to the person they want through email/sms. The chatbot is created using the Amazon Lex chatbot service and user can use this chatbot through whatsapp interface. To integrate this chatbot service with Whatsapp, Twilio service is being used.

Amazon Services used in Project

There are various AWS services that are used in developing this project along with Amazon Lex. In this project we have used the AWS services like AWS Lambda, AWS SNS, AWS SES, Amazon Dynamo DB along with AWS Lex.

Implementation of the Project

Creation of Lex Bot

In this a Lex Bot is created which consists of three different intents. This intents are used for interaction with the users and implementing task of sending gift cards. The intents used are as below:

  1. UserInfoIntent

With this intent we get the user details like the name of the user, email id and mobile number of the user who is going to order the gift card using the chatbot. When the user starts using the chatbot the first intent executed is UserInfoIntent.

Once all the slot values are fulfilled these values are send to GetUserDetails lambda function which generates an unique user id and stores these values received in the DynamoDB User table to maintain the user details. information.

Data Stored in User Table

2. OrderDetailsIntent

Next once the user details are registered we move forward to the OrderDetails Intent. In this intent we get the information related to the ProductName the user wants to purchase and the Quantity they want to buy. Again on intent fulfillment the data is stored as session attributes using the lambda function GetOrderDetails. The lambda function here also retrieves the available products and the product details like name, brand, price, how to redeem from the database and sends it to the intent which are displayed to user.

3. ReceiverDetailsIntent

After the user confirms that he/she wants to order a particular order next we ask about the information regarding whom they want to send the giftcard. For this we use ReceiverDetailsIntent, which asks for the name, email, phonenumber, customised message they want to send to the person along with giftcard and the delivery mode (either sms or email or both). Once these details are received the lambda function named getReceiverDetails stores this details along with unique giftcard id in the Order Table in DynamoDB.

Sending Gift Card information

After the order is confirmed the order details are stored in the OrderTable in DynamoDB and this entry in the ordert table triggers a lambda function whose task is to send the order details information along with payment information to the person who has ordered the giftcard. this information is sent to the registered email using the Amazon SES service. Also the gift card details like giftcard id, customised message, gift card details are send to the person for whom gift card is purchased on the basis of delivery mode selected. For sending sms Amazon SNS is used and for sending email Amazon SES is used.

Integrating Lex chatbot with Whatsapp

Once the entire chatbot is ready we publish the chatbot and then integrate it with whatsapp using Twilio platform. For this we need a twilio account from where we get our account sid and account sid token values. To integrate with twilio we go into the Channel section of Lex Bot in AWS Console and choose option of Twilio SMS and make appropriate configuration as shown in below image. After this an endpoint url is generated which is to be submitted in the twilio account settings to start using lex chatbot through whatsapp.

Chat Output

So that’s all about the project. The lambda function code can be found in the github repository https://github.com/nidhi2802/GiftCardLambdaFunction.

--

--

Nidhi Gajjar

Site Reliability Engineer, 2X AWS Certified, AWS Cloud Enthusiastic