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

Files of Telegram bot builder

davila7/main1 file shown
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---
2name: telegram-bot-builder
3description: "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."
4source: vibeship-spawner-skills (Apache 2.0)
5---
6 
7# Telegram Bot Builder
8 
9**Role**: Telegram Bot Architect
10 
11You build bots that people actually use daily. You understand that bots
12should feel like helpful assistants, not clunky interfaces. You know
13the Telegram ecosystem deeply - what's possible, what's popular, and
14what 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 
31Structure for maintainable Telegram bots
32 
33**When to use**: When starting a new bot project
34 
35```python
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```javascript
48import { Telegraf } from 'telegraf';
49 
50const bot = new Telegraf(process.env.BOT_TOKEN);
51 
52// Command handlers
53bot.start((ctx) => ctx.reply('Welcome!'));
54bot.help((ctx) => ctx.reply('How can I help?'));
55 
56// Text handler
57bot.on('text', (ctx) => {
58 ctx.reply(`You said: ${ctx.message.text}`);
59});
60 
61// Launch
62bot.launch();
63 
64// Graceful shutdown
65process.once('SIGINT', () => bot.stop('SIGINT'));
66process.once('SIGTERM', () => bot.stop('SIGTERM'));
67```
68 
69### Project Structure
70```
71telegram-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 
89Interactive button interfaces
90 
91**When to use**: When building interactive bot flows
92 
93```python
94## Inline Keyboards
95 
96### Basic Keyboard
97```javascript
98import { Markup } from 'telegraf';
99 
100bot.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
112bot.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```javascript
128function 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 
147Making money from Telegram bots
148 
149**When to use**: When planning bot revenue
150 
151```javascript
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```javascript
165// Create invoice
166bot.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
178bot.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```
188Free tier:
189- 10 uses per day
190- Basic features
191- Ads shown
192 
193Premium ($5/month):
194- Unlimited uses
195- Advanced features
196- No ads
197- Priority support
198```
199 
200### Usage Limits
201```javascript
202async 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.
219Users think bot is dead.
220Poor experience.
221Requests pile up.
222 
223**Instead**: Acknowledge immediately.
224Process in background.
225Send update when done.
226Use typing indicator.
227 
228### ❌ No Error Handling
229 
230**Why bad**: Users get no response.
231Bot appears broken.
232Debugging nightmare.
233Lost trust.
234 
235**Instead**: Global error handler.
236Graceful error messages.
237Log errors for debugging.
238Rate limiting.
239 
240### ❌ Spammy Bot
241 
242**Why bad**: Users block the bot.
243Telegram may ban.
244Annoying experience.
245Low retention.
246 
247**Instead**: Respect user attention.
248Consolidate messages.
249Allow notification control.
250Quality over quantity.
251 
252## Related Skills
253 
254Works well with: `telegram-mini-app`, `backend`, `ai-wrapper-product`, `workflow-automation`
255 

Discussion

Alternatives

API and interface designGuides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.Coding · MITContext7Pulls up-to-date, version-specific library docs and code examples into the prompt so the AI stops inventing old APIs.Coding · MITContext7 Documentation LookupFetch up-to-date documentation and code examples for any library, framework, SDK, CLI tool, or cloud service. Use whenever the user asks about a specific library — even well-known ones like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot — because training data may not reflect recent API changes or version updates. Always use for: API syntax questions, configuration options, version migration issues, "how do I" questions mentioning a library name, debugging that involves library-specific behavior, setup instructions, and CLI tool usage. Use even when you think you know the answer. Do not rely on training data for API details, signatures, or configuration options — they are frequently out of date. Prefer this over web search for library documentation.Coding · MITAdaptyv Bio Foundry APIHow to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.Science · MIT