Skip to content

A simple book recommendation bot built using Amazon Lex and Lambda, deployed both on a web UI using kommunicate & on WhatsApp using Twilio, offering personalized book suggestions.

Notifications You must be signed in to change notification settings

aakanksha-k/Book-Recommendation-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Book-Recommendation-Bot

Description

This is a simple book recommendation bot built using Amazon Lex, integrated with a Lambda function, to return personalized book suggestions to the users.

This bot has been deployed on two services, kommunicate & Twilio

  1. With kommunicate, the chatbot was embedded into an HTML website & the delivery of the chatbot's responses to users was managed, through the web interface.
  2. Whereas on Twilio, the delivery of the bot's responses to users via the chosen communication channel, here, WhatsApp, was managed.

Architecture

Proj 1_cloud

Services used 🛠

Amazon Lex AWS Lambda AWS IAM

Deployment

Step 1: Set Up Amazon Lex

  1. Sign in to AWS Management Console

  2. Create a Lex Bot

  • Click on "Create bot."
  • Choose "Custom bot" and provide the following details:
  • Bot name: BookRecommendationBot
  • Language: English (or your preferred language)
  • Output voice: None (since it's a text bot)
  • Session timeout: 5 minutes (default)
  • COPPA: No
  • IAM role: Create a new role with basic permissions
  • Sentiment analysis: No
  1. Add Intents:
  • Click on "Create intent."
  • Intent name: WelcomeIntent
  • Sample utterances: Add various ways users might ask for a recommendation, e.g., "Can you recommend a book?", "book recommendations", "Suggest a book", , “Hello”
  1. Define Slots:
  • Slot name: Genre
  • Slot type: AMAZON.BookGenre (Since, this SlotType isn’t provided by AWS, create a new type)
  • Prompt: "What genre of books do you like?"
  1. Save the Intent and Build the Bot

Step 2: Create Lambda Function for Recommendations

  1. Navigate to Lambda Console

  2. Create a Function:

  • Click "Create function."
  • Choose "Author from scratch."
  • Provide the following details:
    • Function name: BookRecommendationFunction
    • Runtime: Python 3.8 (or your preferred runtime
    • Permissions: Choose an existing role or create a new one with basic Lambda permissions.
  1. Add Code:
  1. Deploy the Function

  2. Add Lambda Trigger in Lex:

  • Go back to your Lex bot.
  • In the Intent, scroll to Fulfillment and enable it.
  • Click "Save intent" and "Build."
  1. Deployment:
  • Under Deployment, go to Aliases.
  • Choose the Alias associated with the Bot & select Bot's language.
  • Choose the Source & latest Lambda function and Save the settings.

Step 3: Ensuring User Permissions with IAM

  1. Navigate to IAM Dashboard

  2. Visit Roles > Your-Bot

  3. Under Permission Policies

  • Create an inline policy, namely, LexInvokeLambdaPolicy & add the code from iam_permissions.json
  • Save changes

Step 4: Building & Testing

  1. Go back to your Lex bot & build

  2. Test the bot in Lex Console Screenshot (946)

Step 5: Deployment

5.1 Integrating Amazon Lex with kommunicate

  1. Obtain AWS Credentials:
  • Sign in to AWS console as Root/IAM user.
  • Open IAM panel > "Access management -> Users".
  • Create a user (e.g., “Lex-bot”).
  • Attach policies: AmazonLexReadOnly and AmazonLexRunBotsOnly.
  • Create Access Key: Select "Third-Party Service" and generate keys.
  1. Gather Lex Bot Details:

    • Bot Name: Name of your Lex bot.
    • Bot Alias: Alias created when publishing the bot.
    • AWS Region: Region where Lex service is running.
  2. Integrate Lex Bot with Kommunicate:

  • Log in to kommunicate > Bot section.
  • Click "Integrate Bot" in Amazon Lex card.
  • Fill in Access Key ID, Secret Access Key, Bot Name, Bot Alias, AWS Region.
    • Click "Next".
  1. Configure Bot in Kommunicate:
  • Name your bot (visible to users).
  • Enable/Disable "autoHandoff".
  • Select "Let this bot handle all new conversations".
  1. Set Welcome Message in Lex:
    • Add kmConversationStarted as sample utterance to WelcomeIntent.

Once integrated, the HTML website embedded with Lex-bot would look like: Screenshot (951)

5.2 Integrating Amazon Lex with Twilio

  1. Set Up Twilio Account
  • Sign up at Twilio
  • Obtain your Account SID and Auth Token.
  • Verify your phone number in the Twilio console under "Verified Caller IDs".
  1. Create Bot Version and Alias in Lex:
  • Go to your Lex bot and create a new version.
  • Create an alias for the bot and link it with the new version.
  1. Configure Twilio Messaging Service:
  • Access the Twilio console and navigate to "Messaging."
  • Set up a messaging service and take note of the assigned phone number.
  • Verify your WhatsApp number following Twilio's sandbox setup.
  1. Integrate Lex with Twilio
  • Navigate to "Channels" in the Lex console and add a Twilio channel.
  • Enter your Twilio Account SID and Auth Token
  • Copy the callback URL provided by Lex.
  • In Twilio, set the webhook URL (callback URL from Lex) in the messaging service.
  1. Test the Integration
  • Send a message from your verified WhatsApp number to the Twilio number.
  • Confirm reception of responses from the Lex bot to validate the integration.

After deployement, the conversation over the chosen communication channel, could look like: Screenshot (952)

About

A simple book recommendation bot built using Amazon Lex and Lambda, deployed both on a web UI using kommunicate & on WhatsApp using Twilio, offering personalized book suggestions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published