Browse by Domains

TravoBOT – “Move freely in pandemic” (AWS Serverless Chatbot)

Team Members:
1. Deepmala Agarwal
2. Arun Mohan
3. Ghanshyam Kumar Singh
4. Hitaish Raina

Of all the things that this pandemic has taught us, one of the primary concern that many people are still facing is the uncertainty in planning their travel – either in case of emergency or for leisure. And this resulted in TravoBOT – A chatbot that helps the user by collating information from different data sources and provide user with a travel recommendation to a particular destination.

This article gives an overview to the serverless chatbot architecture using various AWS services.

The four sections details the technical build & configuration:

  • Purpose: By understanding the intent of our solution, you can enhance the impact of your work. This section explains the use case that our product has been designed to achieve.
  • Data Layers: In this section, we will discuss about the conceptual stages of data layers in a data lake in AWS.
  • Implementation Flow & Technology Stack: In this section, we will discuss about how to implement python chatbot from ingestion to presentation using various AWS services like Lambda, S3, Glue, Athena, etc.
  • Presentation: This section details about the integration of facebook with AWS Chatbot service (Amazon LEX)

Purpose

TravoBOT takes in one’s current location, travel origin and travel destination and based on
these inputs, it provides the following:

  1. Current pandemic situation in the destination that includes counts of active cases,
    deaths and recovery
  2. Travel Advisory & Travel recommendation based on past 14 days trend

Data Layers

We have categorized the data layers as below:

  • Data Ingestion Layer – Data from various sources gets loaded appropriate S3 buckets and the AWS Lambda functions reads the API data and loads the same onto S3 buckets.
  • Data Transformation Layer – In this layer, Lambda function reads the data from ingestion layer S3 buckets and loads the same onto transformation layer S3 buckets. As part of transformation, Lambda performs the following actions to ensure accuracy-

    Calculation of moving average of active cases
    • Calculates daily growth rate – Daily active cases increase on a given day/Total # of active cases previous day
    • Calculates average daily growth rate for past 14 days

      Travel Recommendation
    • Predict Risk Zone: Using scatter plot & linear regression, we predict the trend (declining or inclining)
    • If the value calculated above is > 0, it determines the location to be in “RED” zone (inclining) and if it is less than 0, it is in “GREEN” zone (declining)
  • Data Consumption Layer – In this layer, user logins to Facebook account and adds the bot as their contact. To be able to do this, a Facebook account along with callback URL to AWS was leveraged.

Implementation Flow & Technology Stack

Consumption Layer

  • User initiates the conversation with BOT through Facebook
  • API Gateway has been configured so that this BOT can be leveraged in other channels (if
    required)
  • Amazon LEX has been configured with Intents, Slots, validation & fulfilment to interact
    with user per the business rules defined in Consumption Lambda
  • Consumption Lambda performs the following tasks:
    a. Validate the user inputs (as appropriate)
    b. Retrieve data from transformation S3 buckets and provide to LEX in line with the
    user response based on the defined business rules
    c. Logging into Cloud Watch

Transformation Layer

  • Transformation S3 bucket – Output of Transformation Lambda is stored in this bucket
  • Transformation Lambda – Lambda function reads the data from ingestion layer S3
    buckets and transforms the same onto transformation layer S3 buckets

Data Ingestion Layer

  • Ingestion S3 buckets – Stores raw data ingested through APIs into Cloud
  • Ingestion Lambda – Initiates the API call to retrieve data on a daily basis
  • All the deployment was done using AWS SAM CLI

Presentation

This bot was implemented using Amazon LEX service provided by AWS for building chatbot. It
also integrates with Facebook (only for development purpose) using callback URL.

Below are the steps to configure Amazon LEX:

  • Bot: Amazon Lex bots can understand user input provided with text or speech and converse in natural language. It consists of all the components related to a conversation, which includes:
    • Intent: An intent represents an action that the user wants to perform.
    • Utterances: An utterance is a text phrase that invokes intent
    • Slots: Slots can be defined as a parameter of intent.
    • Prompt: A prompt is a question that Lex uses to ask the end user to provide data for a slot that is needed to fulfill an intent
    • Fulfillment: Fulfillment provides the business logic that is executed after getting all required slot values. Like AWS Lambda functions for fulfillment of business logic and user input validations.

Creating & Architecting Bot Conversations:

  1. Bot Name: TravoBot
  2. Output: Text
  3. Set Session Timeout: 5 min

Create Slots: We are creating slots as shown below

Slots: Map slots with their types and provide prompt questions that need to be asked to get valid value for the slot. Note the sequence, Lex-bot will ask the questions according to priority.

Confirmation: This is optional. If required you can provide a confirmation message e.g. Are you sure you want to travel?

Fulfillment: Now we have all necessary data gathered from the chatbot, it can just be passed over in lambda function.

Lambda initialization and validation: Lambda function provided here i.e. TravoBot will be invoked on each user input whose intent is understood by Amazon Lex. It will validate the Source and destination with predefined list of cities.

Error Handling: We can customize the error message for bot users. Click on error handling and replace default values with the required ones.

Bot is Now Ready to Chat: Build and publish the chatbot and integrate with required channel as shown below.

Potential Enhancements:

  • TravoBOT can be further enhanced to include questions related to the following:
    • Mobility Stats – that includes retail & recreational places, grocery stores, parks, workplace, transit stations & residential places
    • Open Businesses
    • Nearest hospitals
  • As part of data ingestion, AWS Batch can be used if the data load time is more than 15 minutes due to the limitation of AWS Lambda.

Summary

Key takeaways are:

  • Serverless architecture offers effective storage of big data volume & variety using S3 Serverless architecture has “pay as you use” model making it cost efficient
  • This architecture provides a way to remove infrastructure responsibilities from your workload including provisioning, scaling & maintenance
  • Amazon LEX provides easy integration with Facebook
  • Boto3 does not support Pandas library – hence we need to use AWS SAM CLI for importing codes from developer machine to cloud

Avatar photo
Great Learning Team
Great Learning's Blog covers the latest developments and innovations in technology that can be leveraged to build rewarding careers. You'll find career guides, tech tutorials and industry news to keep yourself updated with the fast-changing world of tech and business.

Leave a Comment

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

Scroll to Top