Skip to content

Telegram conversational GenAI bot, powered by Amazon Bedrock, using PTB, hosted on AWS Serverless.

Notifications You must be signed in to change notification settings

jojo786/aws-bedrock-telegram-genai-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Bedrock Telegram GenAI Chatbot

Telegram conversational GenAI bot, powered by Amazon Bedrock, using PTB, hosted on AWS Serverless

  • Uses the python-telegram-bot telegram bot framework, using this project to run PTB on AWS Serverless
  • GenAI conversational capabilities powered by Amazon Bedrock, using the Claude 3.5 Sonnet LLM

Architecture

Requests from Telegram come in via an Amazon API Gateway endpoint, which get routed to a Lambda function. The Lambda function gets the Telegram Token from SSM Parameter Store. Requests are sent to Amazon Bedrock. Chat history is maintained in DynamoDB. Logs are stored on CloudWatch. Telegram token stored securely in SSM using Lambda Powertools. All deployed using AWS SAM IaC. Lambda SnapStart is enabled to reduce cold starts and improve performance. Monitoring services like X-Ray, Lambda Insights and Application Signal are all enabled for comprehensive monitoring.

architecture

service map

How to run it

  • Create your bot using BotFather, and note the token, e.g. 12334342:ABCD124324234
  • Install AWS CLI, and configure it
  • Install AWS SAM CLI
  • Create an SSM Parameter to store the Telegram token. aws ssm put-parameter --region us-east-1 --name "/bedrock-telegram-genai-chatbot/telegram/prod/bot_token" --type "SecureString" --value "12334342:ABCD12432423" --overwrite
  • Run sam build && sam deploy --guided. Provide a stack-name, us-east-1 as the region.
  • Note the Outputs from the above sam deploy command, which will include the Value of the TelegramApi, which is the API GW / Lambda URL endpoint, e.g. https://1fgfgfd56.lambda-url.eu-west-1.on.aws/
  • Update your Telegram bot to change from polling to Webhook, by pasting this URL in your browser, or curl'ing it: https://api.telegram.org/bot12334342:ABCD124324234/setWebHook?url=https://1fgfgfd56.lambda-url.eu-west-1.on.aws/. Use your bot token and API GW / Lambda URL endpoint. You can check that it was set correctly by going to https://api.telegram.org/bot12334342:ABCD124324234/getWebhookInfo, which should include the url of your API GW / Lambda URL, as well as any errors Telegram is encountering calling your bot on that webhook.

About

Telegram conversational GenAI bot, powered by Amazon Bedrock, using PTB, hosted on AWS Serverless.

Topics

Resources

Stars

Watchers

Forks

Languages