View on GitHub

AWS-Dining-Concierge-Chatbot

The Dining Concierge chatbot is a microservice-driven web application where the chatbot sends restaurant suggestions given a set of preferences that you provide to the chatbot through conversation.

AWS Services Used

S3, AWS Lambda, API Gateway, Lex, SQS, SNS, Elastic Search, DynamoDB

Architecture Diagram

architecture

Implementation

  1. Build and deployed the frontend of the application on AWS S3 bucket
  2. Build the API for the application
    • Used API Gateway to setup the API using Swagger
    • Created a Lambda function (LF0) that performs the chat operation
  3. Build a Dining Concierge chatbot using Amazon Lex.
    • Created a bot using the Amazon Lex service.
    • Created a Lambda function (LF1) as a code hook for Lex, which essentially entails the invocation of the Lambda before Lex responds to any of your requests. This helps to manipulate and validate parameters as well as format the bot’s responses.
    • The bot use three intents:
      • GreetingIntent : response such as “Hi there, how can I help?”
      • ThankYouIntent : "Thank you"
      • DiningSuggestionsIntent
    • For the DiningSuggestionsIntent, the chat bot collect at least one of the following pieces of information from the user, through conversation:
      • Location
      • Cuisine
      • Dining Time
      • Number of people
      • Phone number
  4. Based on the parameters collected from the user, the information is then pushed to an SQS queue (Q1).
  5. Send a confirmation to the user that the user will receive the suggestions over SMS.
  6. Integrated the Lex chatbot into your chat API
    • Used the AWS SDK to call your Lex chatbot from the API Lambda (LF0).
    • API receives a request:
      • extract the text message from the API request,
      • send it to your Lex chatbot,
      • wait for the response,
      • response back from Lex as the API response.
  7. Used the Yelp API to collect 5,000+ random restaurants from Manhattan.
  8. DynamoDB (a noSQL database)
    • Create a DynamoDB table and named “yelp-restaurants”
    • Store the restaurants you scrape, in DynamoDB because some restaurants might have more or less fields than others, which makes DynamoDB ideal for storing this data
    • Only Stored the information that are necessary for your recommendation like Business ID, Name, Address, Coordinates, Number of Reviews, Rating, Zip Code
  9. Created an ElasticSearch instance using the AWS ElasticSearch Service.
    • Created an ElasticSearch index called “restaurants”
    • Create an ElasticSearch type under the index “restaurants” called “Restaurant”
    • Stored the RestaurantID and Cuisine for each restaurant scraped in ElasticSearch under the “restaurants” index, where each entry has a “Restaurant” data type.
  10. Build a suggestions module, that is decoupled from the Lex chatbot.
    • Create a new Lambda function (LF2) that acts as a queue worker.
    • Whenever it is invoked it
      1. pulls a message from the SQS queue (Q1),
      2. gets a random restaurant recommendation for the cuisine collected through conversation from ElasticSearch and DynamoDB,
      3. formats them
      4. sends them over text message to the phone number included in the SQS message, using SNS
  11. Use the DynamoDB table “yelp-restaurants” (which was created from Step 1) to fetch more information about the restaurants (restaurant name, address, etc.), since the restaurants stored in ElasticSearch will have only a small subset of fields from each restaurant.
  12. Set up a CloudWatch event trigger that runs every minute and invokes the Lambda function as a result. This automates the queue worker Lambda to poll and process suggestion requests on its own.

In summary, based on a conversation with the customer,the LEX chatbot will identify the customer’s preferred ‘cuisine and will search using ElasticSearch to receive random suggestions of restaurant IDs with cuisine. At this point, we need to query the DynamoDB table with these restaurant IDs to find more information about the restaurants and suggest to customers like name and address of the restaurant.