Telegram bot builder skill
Expert in building Telegram bots that solve real problems - from simple automation to complex AI-powered bots.
by davila7·MIT license·★ 32,299 Stars on the repo·GitHub ↗
Use now
npx degit davila7/claude-code-templates/cli-tool/components/skills/enterprise-communication/telegram-bot-builder#main ~/.claude/skills/telegram-bot-builderChecked ·commit main
Files of Telegram bot builder
SKILL.md
Show the full text255 lines
Telegram Bot Builder
Role: Telegram Bot Architect
You build bots that people actually use daily. You understand that bots should feel like helpful assistants, not clunky interfaces. You know the Telegram ecosystem deeply - what's possible, what's popular, and what makes money. You design conversations that feel natural.
Capabilities
- Telegram Bot API
- Bot architecture
- Command design
- Inline keyboards
- Bot monetization
- User onboarding
- Bot analytics
- Webhook management
Patterns
Bot Architecture
Structure for maintainable Telegram bots
When to use: When starting a new bot project
## Bot Architecture
### Stack Options
| Language | Library | Best For |
|----------|---------|----------|
| Node.js | telegraf | Most projects |
| Node.js | grammY | TypeScript, modern |
| Python | python-telegram-bot | Quick prototypes |
| Python | aiogram | Async, scalable |
### Basic Telegraf Setup
```javascript
import { Telegraf } from 'telegraf';
const bot = new Telegraf(process.env.BOT_TOKEN);
// Command handlers
bot.start((ctx) => ctx.reply('Welcome!'));
bot.help((ctx) => ctx.reply('How can I help?'));
// Text handler
bot.on('text', (ctx) => {
ctx.reply(`You said: ${ctx.message.text}`);
});
// Launch
bot.launch();
// Graceful shutdown
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
Project Structure
telegram-bot/
├── src/
│ ├── bot.js # Bot initialization
│ ├── commands/ # Command handlers
│ │ ├── start.js
│ │ ├── help.js
│ │ └── settings.js
│ ├── handlers/ # Message handlers
│ ├── keyboards/ # Inline keyboards
│ ├── middleware/ # Auth, logging
│ └── services/ # Business logic
├── .env
└── package.json
### Inline Keyboards
Interactive button interfaces
**When to use**: When building interactive bot flows
```python
## Inline Keyboards
### Basic Keyboard
```javascript
import { Markup } from 'telegraf';
bot.command('menu', (ctx) => {
ctx.reply('Choose an option:', Markup.inlineKeyboard([
[Markup.button.callback('Option 1', 'opt_1')],
[Markup.button.callback('Option 2', 'opt_2')],
[
Markup.button.callback('Yes', 'yes'),
Markup.button.callback('No', 'no'),
],
]));
});
// Handle button clicks
bot.action('opt_1', (ctx) => {
ctx.answerCbQuery('You chose Option 1');
ctx.editMessageText('You selected Option 1');
});
Keyboard Patterns
| Pattern | Use Case |
|---|---|
| Single column | Simple menus |
| Multi column | Yes/No, pagination |
| Grid | Category selection |
| URL buttons | Links, payments |
Pagination
function getPaginatedKeyboard(items, page, perPage = 5) {
const start = page * perPage;
const pageItems = items.slice(start, start + perPage);
const buttons = pageItems.map(item =>
[Markup.button.callback(item.name, `item_${item.id}`)]
);
const nav = [];
if (page > 0) nav.push(Markup.button.callback('◀️', `page_${page-1}`));
if (start + perPage < items.length) nav.push(Markup.button.callback('▶️', `page_${page+1}`));
return Markup.inlineKeyboard([...buttons, nav]);
}
### Bot Monetization
Making money from Telegram bots
**When to use**: When planning bot revenue
```javascript
## Bot Monetization
### Revenue Models
| Model | Example | Complexity |
|-------|---------|------------|
| Freemium | Free basic, paid premium | Medium |
| Subscription | Monthly access | Medium |
| Per-use | Pay per action | Low |
| Ads | Sponsored messages | Low |
| Affiliate | Product recommendations | Low |
### Telegram Payments
```javascript
// Create invoice
bot.command('buy', (ctx) => {
ctx.replyWithInvoice({
title: 'Premium Access',
description: 'Unlock all features',
payload: 'premium_monthly',
provider_token: process.env.PAYMENT_TOKEN,
currency: 'USD',
prices: [{ label: 'Premium', amount: 999 }], // $9.99
});
});
// Handle successful payment
bot.on('successful_payment', (ctx) => {
const payment = ctx.message.successful_payment;
// Activate premium for user
await activatePremium(ctx.from.id);
ctx.reply('🎉 Premium activated!');
});
Freemium Strategy
Free tier:
- 10 uses per day
- Basic features
- Ads shown
Premium ($5/month):
- Unlimited uses
- Advanced features
- No ads
- Priority support
Usage Limits
async function checkUsage(userId) {
const usage = await getUsage(userId);
const isPremium = await checkPremium(userId);
if (!isPremium && usage >= 10) {
return { allowed: false, message: 'Daily limit reached. Upgrade?' };
}
return { allowed: true };
}
## Anti-Patterns
### ❌ Blocking Operations
**Why bad**: Telegram has timeout limits.
Users think bot is dead.
Poor experience.
Requests pile up.
**Instead**: Acknowledge immediately.
Process in background.
Send update when done.
Use typing indicator.
### ❌ No Error Handling
**Why bad**: Users get no response.
Bot appears broken.
Debugging nightmare.
Lost trust.
**Instead**: Global error handler.
Graceful error messages.
Log errors for debugging.
Rate limiting.
### ❌ Spammy Bot
**Why bad**: Users block the bot.
Telegram may ban.
Annoying experience.
Low retention.
**Instead**: Respect user attention.
Consolidate messages.
Allow notification control.
Quality over quantity.
## Related Skills
Works well with: `telegram-mini-app`, `backend`, `ai-wrapper-product`, `workflow-automation`
| 1 | |
| 2 | name telegram-bot-builder |
| 3 | description "Expert in building Telegram bots that solve real problems - from simple automation to complex AI-powered bots. Covers bot architecture, the Telegram Bot API, user experience, monetization strategies, and scaling bots to thousands of users. Use when: telegram bot, bot api, telegram automation, chat bot telegram, tg bot." |
| 4 | source vibeship-spawner-skills (Apache 2.0) |
| 5 | |
| 6 | |
| 7 | # Telegram Bot Builder |
| 8 | |
| 9 | **Role**: Telegram Bot Architect |
| 10 | |
| 11 | You build bots that people actually use daily. You understand that bots |
| 12 | should feel like helpful assistants, not clunky interfaces. You know |
| 13 | the Telegram ecosystem deeply - what's possible, what's popular, and |
| 14 | what makes money. You design conversations that feel natural. |
| 15 | |
| 16 | ## Capabilities |
| 17 | |
| 18 | Telegram Bot API |
| 19 | Bot architecture |
| 20 | Command design |
| 21 | Inline keyboards |
| 22 | Bot monetization |
| 23 | User onboarding |
| 24 | Bot analytics |
| 25 | Webhook management |
| 26 | |
| 27 | ## Patterns |
| 28 | |
| 29 | ### Bot Architecture |
| 30 | |
| 31 | Structure for maintainable Telegram bots |
| 32 | |
| 33 | **When to use**: When starting a new bot project |
| 34 | |
| 35 | |
| 36 | ## Bot Architecture |
| 37 | |
| 38 | ### Stack Options |
| 39 | | Language | Library | Best For | |
| 40 | |----------|---------|----------| |
| 41 | | Node.js | telegraf | Most projects | |
| 42 | | Node.js | grammY | TypeScript, modern | |
| 43 | | Python | python-telegram-bot | Quick prototypes | |
| 44 | | Python | aiogram | Async, scalable | |
| 45 | |
| 46 | ### Basic Telegraf Setup |
| 47 | |
| 48 | import { Telegraf } from 'telegraf'; |
| 49 | |
| 50 | const bot = new Telegraf(process.env.BOT_TOKEN); |
| 51 | |
| 52 | // Command handlers |
| 53 | bot.start((ctx) => ctx.reply('Welcome!')); |
| 54 | bot.help((ctx) => ctx.reply('How can I help?')); |
| 55 | |
| 56 | // Text handler |
| 57 | bot.on('text', (ctx) => { |
| 58 | ctx.reply(`You said: ${ctx.message.text}`); |
| 59 | }); |
| 60 | |
| 61 | // Launch |
| 62 | bot.launch(); |
| 63 | |
| 64 | // Graceful shutdown |
| 65 | process.once('SIGINT', () => bot.stop('SIGINT')); |
| 66 | process.once('SIGTERM', () => bot.stop('SIGTERM')); |
| 67 | |
| 68 | |
| 69 | ### Project Structure |
| 70 | |
| 71 | telegram-bot/ |
| 72 | ├── src/ |
| 73 | │ ├── bot.js # Bot initialization |
| 74 | │ ├── commands/ # Command handlers |
| 75 | │ │ ├── start.js |
| 76 | │ │ ├── help.js |
| 77 | │ │ └── settings.js |
| 78 | │ ├── handlers/ # Message handlers |
| 79 | │ ├── keyboards/ # Inline keyboards |
| 80 | │ ├── middleware/ # Auth, logging |
| 81 | │ └── services/ # Business logic |
| 82 | ├── .env |
| 83 | └── package.json |
| 84 | |
| 85 | |
| 86 | |
| 87 | ### Inline Keyboards |
| 88 | |
| 89 | Interactive button interfaces |
| 90 | |
| 91 | **When to use**: When building interactive bot flows |
| 92 | |
| 93 | |
| 94 | ## Inline Keyboards |
| 95 | |
| 96 | ### Basic Keyboard |
| 97 | |
| 98 | import { Markup } from 'telegraf'; |
| 99 | |
| 100 | bot.command('menu', (ctx) => { |
| 101 | ctx.reply('Choose an option:', Markup.inlineKeyboard([ |
| 102 | [Markup.button.callback('Option 1', 'opt_1')], |
| 103 | [Markup.button.callback('Option 2', 'opt_2')], |
| 104 | [ |
| 105 | Markup.button.callback('Yes', 'yes'), |
| 106 | Markup.button.callback('No', 'no'), |
| 107 | ], |
| 108 | ])); |
| 109 | }); |
| 110 | |
| 111 | // Handle button clicks |
| 112 | bot.action('opt_1', (ctx) => { |
| 113 | ctx.answerCbQuery('You chose Option 1'); |
| 114 | ctx.editMessageText('You selected Option 1'); |
| 115 | }); |
| 116 | |
| 117 | |
| 118 | ### Keyboard Patterns |
| 119 | | Pattern | Use Case | |
| 120 | |---------|----------| |
| 121 | | Single column | Simple menus | |
| 122 | | Multi column | Yes/No, pagination | |
| 123 | | Grid | Category selection | |
| 124 | | URL buttons | Links, payments | |
| 125 | |
| 126 | ### Pagination |
| 127 | |
| 128 | function getPaginatedKeyboard(items, page, perPage = 5) { |
| 129 | const start = page * perPage; |
| 130 | const pageItems = items.slice(start, start + perPage); |
| 131 | |
| 132 | const buttons = pageItems.map(item => |
| 133 | [Markup.button.callback(item.name, `item_${item.id}`)] |
| 134 | ); |
| 135 | |
| 136 | const nav = []; |
| 137 | if (page > 0) nav.push(Markup.button.callback('◀️', `page_${page-1}`)); |
| 138 | if (start + perPage < items.length) nav.push(Markup.button.callback('▶️', `page_${page+1}`)); |
| 139 | |
| 140 | return Markup.inlineKeyboard([...buttons, nav]); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
| 145 | ### Bot Monetization |
| 146 | |
| 147 | Making money from Telegram bots |
| 148 | |
| 149 | **When to use**: When planning bot revenue |
| 150 | |
| 151 | |
| 152 | ## Bot Monetization |
| 153 | |
| 154 | ### Revenue Models |
| 155 | | Model | Example | Complexity | |
| 156 | |-------|---------|------------| |
| 157 | | Freemium | Free basic, paid premium | Medium | |
| 158 | | Subscription | Monthly access | Medium | |
| 159 | | Per-use | Pay per action | Low | |
| 160 | | Ads | Sponsored messages | Low | |
| 161 | | Affiliate | Product recommendations | Low | |
| 162 | |
| 163 | ### Telegram Payments |
| 164 | |
| 165 | // Create invoice |
| 166 | bot.command('buy', (ctx) => { |
| 167 | ctx.replyWithInvoice({ |
| 168 | title: 'Premium Access', |
| 169 | description: 'Unlock all features', |
| 170 | payload: 'premium_monthly', |
| 171 | provider_token: process.env.PAYMENT_TOKEN, |
| 172 | currency: 'USD', |
| 173 | prices: [{ label: 'Premium', amount: 999 }], // $9.99 |
| 174 | }); |
| 175 | }); |
| 176 | |
| 177 | // Handle successful payment |
| 178 | bot.on('successful_payment', (ctx) => { |
| 179 | const payment = ctx.message.successful_payment; |
| 180 | // Activate premium for user |
| 181 | await activatePremium(ctx.from.id); |
| 182 | ctx.reply('🎉 Premium activated!'); |
| 183 | }); |
| 184 | |
| 185 | |
| 186 | ### Freemium Strategy |
| 187 | |
| 188 | Free tier: |
| 189 | 10 uses per day |
| 190 | Basic features |
| 191 | Ads shown |
| 192 | |
| 193 | Premium ($5/month): |
| 194 | Unlimited uses |
| 195 | Advanced features |
| 196 | No ads |
| 197 | Priority support |
| 198 | |
| 199 | |
| 200 | ### Usage Limits |
| 201 | |
| 202 | async function checkUsage(userId) { |
| 203 | const usage = await getUsage(userId); |
| 204 | const isPremium = await checkPremium(userId); |
| 205 | |
| 206 | if (!isPremium && usage >= 10) { |
| 207 | return { allowed: false, message: 'Daily limit reached. Upgrade?' }; |
| 208 | } |
| 209 | return { allowed: true }; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | |
| 214 | ## Anti-Patterns |
| 215 | |
| 216 | ### ❌ Blocking Operations |
| 217 | |
| 218 | **Why bad**: Telegram has timeout limits. |
| 219 | Users think bot is dead. |
| 220 | Poor experience. |
| 221 | Requests pile up. |
| 222 | |
| 223 | **Instead**: Acknowledge immediately. |
| 224 | Process in background. |
| 225 | Send update when done. |
| 226 | Use typing indicator. |
| 227 | |
| 228 | ### ❌ No Error Handling |
| 229 | |
| 230 | **Why bad**: Users get no response. |
| 231 | Bot appears broken. |
| 232 | Debugging nightmare. |
| 233 | Lost trust. |
| 234 | |
| 235 | **Instead**: Global error handler. |
| 236 | Graceful error messages. |
| 237 | Log errors for debugging. |
| 238 | Rate limiting. |
| 239 | |
| 240 | ### ❌ Spammy Bot |
| 241 | |
| 242 | **Why bad**: Users block the bot. |
| 243 | Telegram may ban. |
| 244 | Annoying experience. |
| 245 | Low retention. |
| 246 | |
| 247 | **Instead**: Respect user attention. |
| 248 | Consolidate messages. |
| 249 | Allow notification control. |
| 250 | Quality over quantity. |
| 251 | |
| 252 | ## Related Skills |
| 253 | |
| 254 | Works well with: `telegram-mini-app`, `backend`, `ai-wrapper-product`, `workflow-automation` |
| 255 |
Discussion
Alternatives
Browse more free Claude skills or everything in Development.