Serverless Telegram bot built with:
- @effect-ak/tg-bot — Type-safe Telegram Bot API client with fluent builder, long polling, and webhook handler
- effortless-aws — Code-first AWS Lambda deployment framework
- 🎯 Type-safe Telegram Bot API interactions
- 🚀 Serverless deployment with AWS Lambda + API Gateway
- ⚡ Fast deployment with effortless-aws (~5-10s)
- 🔒 Bot token in AWS SSM Parameter Store
- 📊 User message stats in DynamoDB (single-table design)
- 🌐 Telegram Mini App page served via CloudFront + S3
The bot is already deployed on AWS Lambda:
Available commands:
/start— Welcome message with fire effect/help— GitHub repository link/typescript— Random TypeScript fact/echo— Echoes the message in JSON format/random— Sends a soccer ball dice
- Node.js 18+ and pnpm
- AWS account with configured credentials (
aws configure) - Telegram Bot Token (get one from @BotFather)
- Install dependencies:
pnpm install- Create a
.envfile:
BOT_TOKEN=your_telegram_bot_token- Run the bot locally (long polling):
pnpm devCreate a SecureString parameter:
- Dev:
/effect-tg-bot/dev/bot-token - Prod:
/effect-tg-bot/prod/bot-token - Region:
eu-west-1
# Dev stage
pnpm deploy
# Prod stage
pnpm deploy:prodDeployment provisions:
- Lambda for the webhook handler (POST /webhook)
- Lambda for the setup endpoint (GET /setup-webhook)
- DynamoDB table for user stats
- S3 + CloudFront for the Mini App static page
- IAM roles, SSM access, and API Gateway
Call the deployed setup endpoint — it registers the webhook URL and bot commands in one shot:
curl https://your-api-gateway-url.amazonaws.com/setup-webhookOr use the helper scripts:
WEBHOOK_URL=https://your-api-gateway-url.amazonaws.com/webhook pnpm webhook:set
pnpm webhook:infopnpm logspnpm destroysrc/
├── bot.ts # Bot commands and handlers (defineBot)
├── polling.ts # Long polling for local dev (runBot)
├── webhook.ts # Lambda webhook handler (defineApi builder)
├── setup-webhook.ts # Lambda endpoint that registers webhook + commands
├── db.ts # DynamoDB user-stats table (defineTable)
├── webapp.ts # Mini App static site (defineStaticSite)
└── webapp/app.html # Mini App page
effortless.config.ts # Deployment configuration
Uses long polling via runBot from @effect-ak/tg-bot.
Telegram sends updates directly to the Lambda via API Gateway webhook. The webhook handler is built with the defineApi builder from effortless-aws, with typed deps, SSM secrets, and a single-table DynamoDB design for user stats.
Edit effortless.config.ts to customize:
- AWS region
- Lambda memory and timeout
- Stage names
- Handler discovery paths
MIT