skills/telegram-bot-builder/SKILL.md
Use when building Telegram bots, designing bot conversation flows, choosing bot libraries, configuring webhooks or polling, implementing Telegram Payments or Stars, handling Telegram API rate limits or file size constraints, or scaling a bot beyond hobby usage. NEVER for voice-based bot experiences (use voice-agents), no-code bot automation via n8n (use n8n-workflow-patterns), full web applications that happen to include a Telegram bot (use app-builder), Discord/Slack/WhatsApp bots (platform-specific skills).
npx skillsauth add sharkitect-solutions/sharkitect-claude-toolkit telegram-bot-builderInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Request | This Skill | Defer To | |---------|-----------|----------| | Build a Telegram bot from scratch | YES | -- | | Voice bot with speech recognition | NO | voice-agents | | Connect Telegram to n8n workflows | NO | n8n-workflow-patterns | | Full SaaS product with Telegram integration | NO | app-builder | | Bot payment integration (Stars, Stripe) | YES | -- | | Deploy bot to cloud infrastructure | Webhook/polling config only | docker-expert for containers | | Bot database schema design | NO | senior-architect | | Telegram Mini App (TWA) | NO | app-builder |
| File | Purpose | When to Load | |---|---|---| | SKILL.md | Bot architecture decisions, library selection, API gotchas, scaling | Always (auto-loaded) | | conversation-patterns.md | Scene/wizard lifecycle, FSM transition tables, deep linking, group chat patterns, inline mode, command routing | When designing multi-step conversation flows or complex bot interactions | | api-limits-reference.md | Rate limit tables, file size limits by type, MarkdownV2 escaping, callback data constraints, media group rules | When troubleshooting API errors, formatting issues, or rate limit problems | | deployment-guide.md | Webhook SSL setup, reverse proxy configs, health monitoring, graceful shutdown, self-hosted Bot API, backup/recovery | When deploying to production or troubleshooting production issues |
Follow this sequence for every Telegram bot request. Do not jump to code.
Key mindset: Most bot projects fail not from bad code but from wrong scope. A bot that handles one use case end-to-end (including error states, edge cases, and graceful failures) ships faster and retains users better than a bot that half-handles five use cases.
Choose based on the FIRST matching signal:
| Signal | Choose | Reason | |--------|--------|--------| | Team knows TypeScript, wants type safety | grammy | Best TS support, transformer middleware | | Rapid prototype, Python team | python-telegram-bot | Lowest time-to-hello-world | | High-concurrency Python (>500 req/s) | aiogram | Async-native, no sync bottlenecks | | Node.js team, large plugin ecosystem needed | Telegraf | Most middleware/plugins available | | Need raw API control, any language | Direct HTTP | Libraries add overhead you may not want | | Long-running background tasks in Python | aiogram | Telegraf and grammY lack native job queues |
Override rule: If the user has already chosen a library, use it. Do not suggest switching unless they report a specific problem the library cannot solve.
Warning: Do NOT mix libraries. Pick one per bot. Migration between them is painful due to middleware/context API differences.
| Factor | Long Polling | Webhook | |--------|-------------|---------| | Development/local testing | USE THIS | Requires tunnel (ngrok) | | Production deployment | Only if no public URL | USE THIS | | Serverless (Lambda, CF Workers) | Impossible | USE THIS | | VPS/dedicated server | Works but wasteful | USE THIS | | Multiple bot instances | Race conditions | Load-balanced safely | | Latency | 1-2s delay typical | Near-instant | | Firewall-restricted environments | USE THIS (outbound only) | Needs inbound HTTPS on 443/80/88/8443 |
Decision: Use polling for development. Use webhooks for production. The only production exception is firewall-restricted environments where inbound HTTPS is blocked. If the user has a working polling setup they want to keep, do not force webhook migration unless they hit scaling limits.
X-Telegram-Bot-Api-Secret-Token) -- always set this, validate on every requestsetWebhook silently succeeds even if your URL is unreachable -- test with getWebhookInfo| Flow Complexity | Pattern | Example | |----------------|---------|---------| | Single question-answer | Stateless handler | /weather command | | 2-3 step linear form | Scene/wizard | Collect name + email | | Branching dialog (>3 paths) | Finite state machine with named states | Support ticket triage | | Free-form + structured mix | Hybrid: FSM for structure, NLP for free-form steps | AI chatbot with settings menu |
| Need | Use | Avoid | |------|-----|-------| | Choose from <4 options | Inline keyboard | Reply keyboard (takes screen space) | | Choose from 4-8 options | Inline keyboard with columns | Single-column (too tall) | | Choose from >8 options | Paginated inline keyboard or text search | Massive button grid | | Free text input (names, descriptions) | ForceReply or plain text handler | Inline keyboard | | Persistent quick actions | Reply keyboard with resize | Inline keyboard (disappears) | | Binary yes/no | Inline keyboard on same message | Separate message |
Never exceed 3 levels of nested menus. At depth 4+, users lose context of where they are. If you need more depth, redesign as search or category filters.
| Gotcha | Detail | Mitigation |
|--------|--------|------------|
| Message edit timeout | Cannot edit messages older than 48 hours | Store message timestamps, fall back to new message |
| Callback query answer | MUST call answerCallbackQuery within 30 seconds or user sees loading spinner forever | Always answer, even on error |
| File size upload limit | 50 MB via bot API, 20 MB for photos | For larger files, upload to external storage, send URL |
| File size download limit | 20 MB via getFile | Use Telegram CDN URL directly for larger files |
| Rate limit (per chat) | ~30 messages/second to same chat | Queue messages, batch with delays |
| Rate limit (global) | ~30 messages/second across all chats (may vary) | Implement global send queue with backoff |
| Flood control (bulk send) | Sending to many users triggers 429 errors | Max ~25-30 messages/second, spread across 1-second windows |
| Group vs private behavior | Bot cannot see messages in groups unless BotFather /setprivacy is disabled or bot is admin | Document this for users; check chat.type |
| Inline mode rate limit | Results cached by Telegram for cache_time seconds | Set cache_time to 0 during development, 300+ in production |
| HTML parse mode quirks | Only supports a subset of HTML -- no <div>, no <br>, use \n for newlines | Stick to <b>, <i>, <code>, <pre>, <a> |
| Message length limit | 4096 characters for text, 1024 for captions | Split long messages, paginate |
| Silent message failures | sendMessage to a user who blocked the bot returns 403 -- no event, no notification | Catch 403, mark user inactive |
| Scenario | Method | Why | |----------|--------|-----| | Digital goods (stickers, premium features) | Telegram Stars | No payment provider needed, native UX, Apple/Google compliant | | Physical goods or services | Telegram Payments (Stripe/etc.) | Stars not allowed for physical goods | | Subscription model | External payment + webhook | Telegram Payments lacks recurring billing natively | | One-time digital purchase | Stars (preferred) or Telegram Payments | Stars has lowest friction | | Users in restricted countries | External payment link | Telegram Payments provider coverage varies |
| User Count | Session Storage | Update Delivery | Key Concern | |------------|----------------|-----------------|-------------| | <1K | In-memory (Map/dict) | Polling OK | Simplicity | | 1K-10K | Redis | Webhook required | Session persistence across restarts | | 10K-100K | Redis cluster + DB for permanent data | Webhook + queue (Bull/Celery) | Message send rate limits | | >100K | Sharded Redis + DB + dedicated send workers | Webhook + message queue + worker pool | Flood control, graceful degradation |
getUpdates offset tracking carefully -- missed offsets mean duplicate processing| Anti-Pattern | Symptom | Fix | |-------------|---------|-----| | Menu Hell | 5+ levels of nested inline keyboards, users get lost. 40%+ drop-off per menu level beyond 3. | Flatten to max 3 levels, add "Back to Main" at every level | | Spam Bot | Unsolicited messages, daily "tips", broadcast abuse. Telegram bans bots with >0.1% spam report rate. | Only message on user action or explicit opt-in notification | | Silent Failure | Bot receives message, does nothing (no reply, no error). Users retry 2-3 times then abandon permanently. | Always reply -- even "I didn't understand" is better than silence | | Keyboard Overload | 20+ buttons in one message | Paginate at 8, use categories, or switch to text search | | No Onboarding | /start sends "Welcome!" and nothing else | Guide first action: show main menu, explain what bot does in 1-2 lines | | State Amnesia | Bot forgets mid-conversation context after restart | Persist conversation state to Redis/DB, not memory | | Wall of Text | Bot sends 2000-character messages | Break into multiple short messages with 200ms delay between | | Confirmation Trap | Every single action requires "Are you sure?" | Only confirm destructive/irreversible actions |
Verify before deploying any bot to production:
| Check | Why | Fail = |
|-------|-----|--------|
| Bot token in env var, not in code | Token in repo = compromised bot | Security breach |
| /start handler implemented | First thing every user triggers | Broken first impression |
| answerCallbackQuery on every inline button | Missing = permanent loading spinner | Users think bot is broken |
| Error handler registered | Unhandled error = crash = offline bot | Silent downtime |
| Webhook secret token set and validated | Without it, anyone can POST fake updates | Spoofed messages |
| Session storage is persistent (Redis/DB) | In-memory = data loss on restart | State amnesia |
| Rate limit queue for sends | Tight loops trigger 429 bans | Extended API ban |
| 403 handling for blocked users | Blocked users return 403 silently | Wasted send attempts, potential ban |
| The agent might think... | But actually... | |--------------------------|-----------------| | "I should include the full Telegraf/grammY setup code" | Claude knows these libraries. Link to docs or describe the pattern. | | "The bot needs a database, let me design the schema" | Database design is senior-architect territory. This skill covers bot-specific session storage only. | | "I'll add webhook + polling + both options in the code" | Pick one based on the deployment context. Shipping both creates dead code. | | "Let me build a web dashboard for bot admin" | That is a full web app (app-builder). Bot admin should be a separate admin bot or BotFather settings. | | "I should handle voice messages with speech-to-text" | Voice processing is voice-agents scope. This skill can receive voice files but not process audio. | | "The user wants a chatbot, so I need an AI/LLM integration" | Not all Telegram bots need AI. Clarify if they want command-driven, menu-driven, or conversational AI. |
answerCallbackQuery after inline button press -- causes permanent loading spinnersetPrivacy disabled in groups without informing users -- privacy concern/start command handler -- required by Telegram, first thing users trigger429 Too Many Requests responses -- implement exponential backoff or face extended bansdevelopment
When the user wants help with paid advertising campaigns on Google Ads, Meta (Facebook/Instagram), LinkedIn, Twitter/X, or other ad platforms. Also use when the user mentions 'PPC,' 'paid media,' 'ad copy,' 'ad creative,' 'ROAS,' 'CPA,' 'ad campaign,' 'retargeting,' or 'audience targeting.' This skill covers campaign strategy, ad creation, audience targeting, and optimization.
testing
--- name: using-sharkitect-methodology description: Use when starting any conversation in a Sharkitect workspace OR before any task involving NEW pricing, positioning, proposal, strategy, plan-execution, or schema-design work — mandates invocation of Sharkitect-specific methodology skills (pricing-strategy, marketing-strategy-pmm, smb-cfo, hq-revenue-ops, executing-plans, brainstorming) under the same anti-rationalization discipline as using-superpowers. Documentation has failed 4 times across H
testing
Use when user says 'end session', 'wrap up', 'stop for the day', 'done for today', 'close out', 'save session', 'wrapping up', or invokes /end-session. Runs the full 9-step end-of-session protocol: resource audit, MEMORY.md update, lessons capture, plan status, pending items, workspace checklist, .tmp/ audit, git commit+push, Supabase brain sync, session brief, summary. Final step schedules a detached self-kill of the current session ONLY (3s delay) so the window closes cleanly. Other claude.exe processes (active workspaces) are NOT touched -- orphan cleanup is handled separately by Claude-Orphan-Cleanup-Hourly with proper age safeguards. Do NOT use for: mid-session quick saves (use session-checkpoint), skill syncing (use sync-skills.py), brain memory queries (use supabase-sync.py pull), document freshness reviews (use document-lifecycle), resource gap detection (use resource-auditor).
testing
Remove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, passive voice, negative parallelisms, and filler phrases.