A cloud-based conversational AI chatbot built with AWS Lex, featuring a modern web interface and optional multi-channel messaging through Twilio integration.
This project demonstrates a production-ready IT Help Desk chatbot that can handle common support requests such as password resets, network troubleshooting, and software installations. The chatbot uses AWS Lex's generative AI capabilities combined with custom business logic through Lambda functions.
- Conversational AI: Powered by AWS Lex with generative AI for natural language understanding
- Multi-Intent Support: Handles password resets, network issues, software installations, and general queries
- User Authentication: Secure access control using Amazon Cognito
- Modern Web Interface: Clean, responsive UI built with Lex Web UI
- Multi-Channel Support: Optional integration with Twilio for SMS and WhatsApp messaging
- Custom Validation: Lambda-based slot validation and fulfillment logic
- Customizable Styling: Fully customizable CSS for brand consistency
The system consists of four main components that work together seamlessly:
- Amazon Lex: Processes user inputs and manages conversation flow
- AWS Lambda: Validates user inputs and executes business logic
- Amazon Cognito: Handles user authentication and authorization
- Lex Web UI: Provides the web-based chat interface
- Twilio (Optional): Enables SMS and WhatsApp messaging channels
Before starting, ensure you have:
- AWS Account
- Node.js version 18 or higher
- npm or yarn package manager
- Twilio Account (optional, for SMS/WhatsApp integration)
- Navigate to the AWS Lex Console
- Click "Create bot"
- Configure the bot with these settings:
- Creation method: Start with generative AI
- Bot name:
ITHelpDeskBot - Description: IT Help Desk support chatbot
- IAM role: Check the option : Create a role with basic Amazon Lex permissions
- Language: English (US)
- Session timeout: 5 minutes
Create Many intents to handle different user requests:
Example Intent 1: PasswordReset
- Go to the AWS Lambda Console
- Click "Create function"
- Configure:
- Function name:
ITHelpDeskBotHandler - Runtime: Python 3.12
- Architecture: x86_64
- Permissions: Create a new role with basic Lambda permissions
- Function name:
Replace the default code with the following:
import json
def validate_slots(slots, intent_name):
"""
Validates required slots for each intent.
Returns validation status and prompts for missing information.
"""
if intent_name == 'PasswordReset':
if not slots.get('username'):
return {
'isValid': False,
'violatedSlot': 'username',
'message': "Can you tell me your username?"
}
if not slots.get('Email'):
return {
'isValid': False,
'violatedSlot': 'Email',
'message': "What email address is associated with this account?"
}
elif intent_name == 'NetworkIssue':
if not slots.get('ConnectionType'):
return {
'isValid': False,
'violatedSlot': 'ConnectionType',
'message': "Are you trying to connect via WiFi, Ethernet, VPN, or Cellular?"
}
return {'isValid': True}
def lambda_handler(event, context):
"""
Main handler for Lex bot events.
Handles both dialog validation and fulfillment.
"""
slots = event['sessionState']['intent'].get('slots', {})
intent_name = event['sessionState']['intent']['name']
source = event['invocationSource']
# Dialog validation phase
if source == 'DialogCodeHook':
validation_result = validate_slots(slots, intent_name)
if not validation_result['isValid']:
# Request missing information
return {
"sessionState": {
"dialogAction": {
"type": "ElicitSlot",
"slotToElicit": validation_result['violatedSlot']
},
"intent": {
"name": intent_name,
"slots": slots
}
},
"messages": [
{
"contentType": "PlainText",
"content": validation_result['message']
}
]
}
else:
# All slots valid - delegate to Lex
return {
"sessionState": {
"dialogAction": {"type": "Delegate"},
"intent": {
"name": intent_name,
"slots": slots
}
}
}
# Fulfillment phase
if source == 'FulfillmentCodeHook':
responses = {
'PasswordReset': "I've initiated a password reset for your account. Check your email for instructions within 5 minutes.",
'NetworkIssue': "For {ConnectionType} issues, please restart your device. If it doesn't work, go to Settings > Network and reconnect. Still failing? Contact IT at ext. 5555.".format(
ConnectionType=slots.get('ConnectionType', {}).get('value', {}).get('interpretedValue', 'your connection')
),
'SoftwareInstallation': "Your software installation request has been logged. IT will assist you shortly.",
'GeneralQuery': "Thank you for your question. We will provide an answer as soon as possible.",
'SmallTalk': "Hello! How can I help you today?",
'FallbackIntent': "I'm sorry, I didn't understand that. Can you rephrase?"
}
return {
"sessionState": {
"dialogAction": {"type": "Close"},
"intent": {
"name": intent_name,
"slots": slots,
"state": "Fulfilled"
}
},
"messages": [
{
"contentType": "PlainText",
"content": responses.get(intent_name, "Thanks! Your request is processed.")
}
]
}-
Go back to your Lex bot
-
Build the bot
-
Create an Alias for that version
-
In the alias settings:
- In Cognito, go to "Identity pools"
- Click "Create identity pool"
This section enables SMS and WhatsApp messaging capabilities.
- Sign up at Twilio Console

- Get a Twilio phone number with SMS capabilities

- Note your Account SID and Auth Token
- In your Lex bot, go to "Channel integrations"
- Click "Add channel"

- Select "Twilio SMS"

- Enter your Twilio credentials:
- Copy the Callback URL provided by AWS
- In Twilio Console, select your phone number
- Under Messaging Configuration:
- Save the configuration
- In Twilio, navigate to "Messaging" > "Try it out" > "Send a WhatsApp message"
- Follow the setup wizard to connect WhatsApp

- Configure the WhatsApp webhook URL (same as SMS callback URL)
- Send the join code to your WhatsApp Sandbox

Send a test message to your Twilio number or WhatsApp:
git clone https://github.com/yourusername/cloud-based-lex-aws-chatbot.git
cd cloud-based-lex-aws-chatbot/lex-web-uinpm installEdit the configuration file at:
aws-lex-web-ui-master/lex-web-ui/src/config/config.dev.json
{
"cognito": {
"userPoolId": "us-east-1_XXXXXXXXX",
"userPoolClientId": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"identityPoolId": "us-east-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"region": "us-east-1"
},
"lex": {
"botId": "XXXXXXXXXX",
"botAliasId": "XXXXXXXXXX",
"localeId": "en_US",
"region": "us-east-1"
},
"ui": {
"toolbarTitle": "IT Help Desk Bot",
"toolbarLogo": "",
"pageTitle": "IT Help Desk Support"
}
}Replace the placeholder values with your actual AWS resource IDs.
Run the application locally for testing:
npm run serveThe application will be available at http://localhost:8080
- Build the production bundle:
npm run build- Create an S3 bucket:
aws s3 mb s3://ithelpdesk-chatbot-ui-
Enable static website hosting
-
Upload the build files:
aws s3 sync ./dist s3://ithelpdesk-chatbot-ui- Configure CloudFront for HTTPS access























