telegram-ai-bot
v1.0.1
Published
AI-powered Telegram bot template — customizable for any niche. Claude API, Stripe payments, multi-language, Cloudflare Workers ready.
Maintainers
Readme
AI Bot Starter Kit for Telegram
A production-ready Telegram bot template powered by Claude AI, with Stripe payments, multi-language support, and one-click deployment to Cloudflare Workers.
Customize it for any niche: fitness coach, language tutor, business assistant, or anything else.
Features
- Claude AI responses with conversation memory (last 10 messages)
- Free/Premium tiers with rate limiting (20 msgs/day free, unlimited premium)
- Stripe integration for $9.99/month premium subscriptions
- Multi-language support (English & French, easily extensible)
- Serverless deployment on Cloudflare Workers (free tier eligible)
- Commands: /start, /help, /reset, /lang, /premium, /stats
- Analytics endpoint for tracking users and messages
- Niche templates: general, fitness, language, business (just change one env var)
Quick Start
Prerequisites
- Node.js 18+
- Wrangler CLI (
npm i -g wrangler) - A Telegram Bot Token
- An Anthropic API Key
- A Stripe Account (for payments)
1. Install
npm install2. Configure Secrets
# Copy the example env file for local dev
cp .dev.vars.example .dev.vars
# Edit .dev.vars with your keys
# For production, set secrets via Wrangler:
wrangler secret put TELEGRAM_BOT_TOKEN
wrangler secret put TELEGRAM_WEBHOOK_SECRET
wrangler secret put ANTHROPIC_API_KEY
wrangler secret put STRIPE_SECRET_KEY
wrangler secret put STRIPE_WEBHOOK_SECRET3. Customize Your Bot
Edit wrangler.toml:
[vars]
BOT_NAME = "FitCoach AI" # Your bot's display name
BOT_NICHE = "fitness" # general | fitness | language | business
DEFAULT_LANGUAGE = "en" # en | fr
FREE_DAILY_LIMIT = "20" # Free tier message limit
STRIPE_PAYMENT_LINK = "https://buy.stripe.com/your-link"4. Deploy
# Local development
npm run dev
# Deploy to Cloudflare Workers
npm run deploy5. Set Up Webhook
After deploying, register your webhook with Telegram:
https://your-worker.your-subdomain.workers.dev/setup?url=https://your-worker.your-subdomain.workers.dev6. Set Up Stripe (Premium)
- Create a Product in Stripe Dashboard ($9.99/month recurring)
- Create a Payment Link for that product
- Add
?client_reference_id={CHECKOUT_SESSION_ID}to the link - Set up a Stripe Webhook pointing to
https://your-worker.dev/stripe - Subscribe to
checkout.session.completedandcustomer.subscription.deleted - Add metadata field
telegram_user_idto your checkout session
API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
| / | GET | Health check |
| /webhook?secret=... | POST | Telegram webhook receiver |
| /stripe | POST | Stripe webhook receiver |
| /setup?url=... | GET | Register Telegram webhook |
| /analytics | GET | User and message statistics |
Customization
Add a New Niche
Edit src/types.ts and add your niche to NICHE_PROMPTS:
export const NICHE_PROMPTS = {
// ...existing niches...
cooking: "You are a professional chef and cooking instructor on Telegram...",
};Then set BOT_NICHE = "cooking" in wrangler.toml.
Add a New Language
Edit src/i18n.ts and add translations for each string key:
welcome: {
en: "Welcome...",
fr: "Bienvenue...",
es: "Bienvenido...", // Add Spanish
},Use Persistent Storage
Replace InMemoryStore in src/bot.ts with your own implementation of the UserStore interface. Works with:
- Cloudflare KV (key-value, eventually consistent)
- Cloudflare D1 (SQLite, transactional)
- Redis (via Upstash for serverless)
Architecture
Telegram --> Cloudflare Worker --> Claude API
|
+--> Stripe (payments)
+--> In-memory store (users, conversations)Cost Estimate
| Component | Free Tier | Paid | |---|---|---| | Cloudflare Workers | 100k req/day | $5/month unlimited | | Claude API (Sonnet) | - | ~$0.003/message | | Stripe | - | 2.9% + $0.30 per transaction | | Telegram | Free | Free |
Break-even: ~4 premium subscribers cover the API costs for ~1000 messages/day.
License
MIT License. See LICENSE for details.
