Customer Service is a core service for a lot of businesses around the world and it is getting disrupted at the moment by Natural Language Processing-powered applications. This is an implementation of a serverless, microservice-driven web application. Specifically, a Dining Concierge chatbot that sends you restaurant suggestions given a set of preferences that you provide the chatbot with through conversation.
Link to chatbot: http://coms6998hw1.com.s3-website-us-east-1.amazonaws.com
Demo video of the chatbot: https://youtu.be/7vMOjHx9xTM
Directory Details
- /frontend: Frontend Code with updated SDK generated via API Gateway
- /lambda_functions/lambda_function_0.py: Lambda-0 python file
- /lambda_functions/lambda_function_1.py: Lambda-1 python file
- /lambda_functions/lambda_function_2.py : Lambda-2 python file
- /yelp_web_scrapper: Scrapper code to receive restaurant information using Yelp Fusion API
- /ddb_to_opensearch lambda function: Dynamodb to Opean Search Lambda Function
- /api_gateway/api_gateway.yaml: YAML file downloaded from swagger.io with required Bot APIs
- /lex_chatbot: Lex BOT Codebase exported from AWS Lex
This assignment has the following developments:
- Built and deployed the frontend of the application
- Frontend hosted in an AWS S3 bucket
- Built the API for the application using API Gateway to setup API with CORS enabled on your API methods
- Created a Lambda function that performs the chat operation
- Amazon Lex. Created a new bot using the Amazon Lex service.
The following three intents:
- GreetingIntent
- ThankYouIntent
- DiningSuggestionsIntent
The implementation of an intent entails its setup in Amazon Lex as well as handling its response in the Lambda function code hook.
For the GreetingIntent
- Created the intent in Lex,
- Trained and tested the intent in the Lex console,
- Implemented the handler for the GreetingIntent in the Lambda code hook, such that when a request for the GreetingIntent is received, a response is composed such as “Hi there, how can I help?”
For the DiningSuggestionsIntent, Collected the following pieces of information from the user, through conversation:
- Location
- Cuisine
- Dining Time
- Number of people
- Phone number
Based on the parameters collected from the user, push the information collected from the user (location, cuisine, etc.) to an SQS queue. And notified them over SMS once with the list of restaurant suggestions.
Integrated the Lex chatbot into your chat API using the AWS SDK to call Lex chatbot from the API Lambda. When an API request is receives:
- extract the text message from the API request,
- send it to your Lex chatbot,
- wait for the response,
- send back the response from Lex as the API response.
Used the Yelp API to collect 5,000+ random restaurants from Manhattan. Using the following tools:
- Yelp API
- Get restaurants by cuisine types
- Each cuisine type should have 1,000 restaurants or so.
- Made sure that restaurants don’t duplicate.
- DynamoDB: a noSQL database
- Created a DynamoDB table and named “yelp-restaurants”
- Stored the restaurants in DynamoDB because some restaurants might have more or less fields than others, which makes DynamoDB ideal for storing this data
- With each item stored, attached a key to the object named “insertedAtTimestamp” with the value of the time and date of whe the particular record is inserted
- Stored those that are necessary for your recommendation
- Business ID,
- Name
- Address
- Coordinates
- Number of Reviews
- Rating
- Zip Code
- Created an ElasticSearch instance using the AWS ElasticSearch Service.
- Created an ElasticSearch index called “restaurants”
- Created an ElasticSearch type under the index “restaurants” called “Restaurant”
- Stored partial information for each restaurant scraped in ElasticSearch under the “restaurants” index, where each entry has a “Restaurant” data type. 5 Stored RestaurantID and Cuisine for each restaurant
- Create a new Lambda function (LF2) that acts as a queue worker. Whenever it is invoked it
- pulls a message from the SQS queue (Q1),
- gets a random restaurant recommendation for the cuisine collected through conversation from ElasticSearch and DynamoDB,
- formats them and
- sends them over text message to the phone number included in the SQS message, using SNS.
- UseD the DynamoDB table “yelp-restaurants” 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.
- Modified the rest of the LF2 function if necessary to send the user text/email.
- 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, your LEX chatbot will identify the customer’s preferred ‘cuisine’ by searching through ElasticSearch to get random suggestions of restaurant IDs with this cuisine. At this point, the DynamoDB table is queried with these restaurant IDs to find more information about the suggested restaurants to your customers like name and address of the restaurant.
Implementation of concierge application, such that it remembers user's last search for both location and category. When a user returns to the chat, they automatically receive a recommendation based on their previous search.
Example Interaction
User: Hello Bot: Hi there, how can I help?
User: I need some restaurant suggestions.
Bot: Great. I can help you with that. What city or city area are you looking to dine in?
User: Manhattan
Bot: Got it, Manhattan. What cuisine would you like to try?
User: Japanese
Bot: Ok, how many people are in your party?
User: Two
Bot: A few more to go. What date?
User: Today
Bot: What time?
User: 7 pm, please
Bot: Great. Lastly, I need your phone number so I can send you my findings.
User: 123-456-7890
Bot: You’re all set. Expect my suggestions shortly! Have a good day.
User: Thank you!
Bot: You’re welcome.
(a few minutes later) User gets the following text message: “Hello! Here are my Japanese restaurant suggestions for 2 people, for today at 7 pm: 1. Sushi Nakazawa, located at 23 Commerce St, 2. Jin Ramen, located at 3183 Broadway, 3. Nikko, located at 1280 Amsterdam Ave. Enjoy your meal!”