Skip to content

Latest commit

 

History

History
135 lines (89 loc) · 3.99 KB

File metadata and controls

135 lines (89 loc) · 3.99 KB

Creating The Bot Using AWS Lex with Custom Instances


🧠 Lex Chatbot Project Log: PersonalBanker

🔍 Objective

Build a chatbot using Amazon Lex that helps users check their bank balance. It should prompt them for an account type (Saving or Current) and a 4-digit PIN. If all goes well, it responds with their mock balance. Otherwise, it loops or errors appropriately.


🛠️ INTENT: GetBalanceCheck

  • Created a new intent called GetBalanceCheck.

  • This intent covers queries related to checking account balance.

  • Added these utterances (as examples of what users might type):

    check my bank balance  
    how much money is in my account  
    how much money do i have
    

⚠️ I avoided punctuation at the end of sample utterances. Lex is picky here—it can throw build errors if they’re formatted like normal sentences.


📥 SLOTS

1. AccountType (Custom Slot)

  • Created a new custom slot type called AccountType.

  • Values:

    • Saving
    • Current
  • Marked it as required, and added this prompt:

    What type of account do you want to check (Current or Savings)?
    
  • Connected this to the GetBalanceCheck intent.

2. PinNumber (Built-in Slot)

  • Added another slot to the same intent.

  • Used AMAZON.FOUR_DIGIT_NUMBER as the slot type.

  • Gave it this prompt:

    What is your pin number for your {AccountType} account?
    
  • Also marked as required.

🧠 Lex collects these slot values before it sends the data to any backend logic.


🎨 Response Cards (Optional UX Boost)

  • For a more user-friendly experience (especially in chat UIs), I added response cards to the AccountType prompt.
  • Gave users clickable buttons instead of making them type:
    • Saving AccountSaving
    • Current AccountCurrent

This helped guide inputs and avoid typos.


🔧 Back-End Logic – Lambda

Function Name: myPersonalBanker
Runtime: Node.js 14.x
Permissions: Gave it basic execution role with Lex permissions.

Code File: I used the script myPersonalBanker_v1.js from the project repo. Here’s what it does:

  • Checks the intent name (GetBalanceCheck)
  • Validates the PIN (must be 1234)
  • If valid, replies with a hardcoded mock balance (like $4,362.50)
  • If invalid, gives an error message

🧪 The code includes a basic fallback that says “try again” if PINs don’t match—good for feedback loops.


🔗 Connecting Lex to Lambda

To actually make the bot do something, I linked the intent to the Lambda:

  • Went into the GetBalanceCheck intent → scrolled to Fulfillment
  • Selected AWS Lambda function and picked myPersonalBanker
  • Hit OK on the permission prompt and saved the intent
  • Then rebuilt the bot

Now, when users fill out the slots, Lex sends that data to the Lambda, which returns a response.


🧪 Testing the Flow

Sample test:

User: What is my balance
Bot: What type of account do you want to check (Current or Savings)?
User: Saving
Bot: What is your pin number for your Saving account?
User: 1234
Bot: Your balance for the Saving account is $4,362.50

User enters the wrong PIN?
Bot responds with an error and asks again.

I updated the code by commenting/uncommenting different return statements depending on whether I wanted to return a success, an error, or just a placeholder.

// return simpleResponse(intentRequest, callback);
// return balanceIntentError(intentRequest, callback);
return balanceIntent(intentRequest, callback);

🧾 Summary & Key Learnings

  • Defined intents and slots cleanly to guide user input
  • Added response cards for a more polished chat experience
  • Used Lambda to simulate basic security logic (PIN check)
  • Learned how Lex and Lambda pass data between them
  • Understood slot order, validation, and response flow

Next step: I might extend this to query a database or plug into an AWS service like RDS or DynamoDB instead of returning static values.