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.
-
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.
-
Created a new custom slot type called
AccountType. -
Values:
SavingCurrent
-
Marked it as required, and added this prompt:
What type of account do you want to check (Current or Savings)? -
Connected this to the
GetBalanceCheckintent.
-
Added another slot to the same intent.
-
Used
AMAZON.FOUR_DIGIT_NUMBERas 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.
- For a more user-friendly experience (especially in chat UIs), I added response cards to the
AccountTypeprompt. - Gave users clickable buttons instead of making them type:
- Saving Account →
Saving - Current Account →
Current
- Saving Account →
This helped guide inputs and avoid typos.
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.
To actually make the bot do something, I linked the intent to the Lambda:
- Went into the
GetBalanceCheckintent → 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.
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
returnstatements 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);- 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.