From tg-alerts
Use when adding Telegram error notifications to any project. Guides through bot creation with @BotFather, chat/channel/forum-topic ID discovery, alert service implementation with deduplication and graceful failure, and framework-specific integration for Python (async/sync) and Node.js.
How this skill is triggered — by the user, by Claude, or both
Slash command
/tg-alerts:tg-alertsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Adds operational error alerts to any project via a dedicated Telegram bot. Alerts go to a private channel, group, or forum topic — not to end users. Battle-tested pattern with deduplication, HTML formatting, and crash-proof error handling.
Adds operational error alerts to any project via a dedicated Telegram bot. Alerts go to a private channel, group, or forum topic — not to end users. Battle-tested pattern with deduplication, HTML formatting, and crash-proof error handling.
This skill is interactive. Each phase involves asking the user questions or guiding them through Telegram actions.
digraph flow {
rankdir=LR;
"Assess\nProject" -> "Create\nBot" -> "Get\nChat ID" -> "Generate\nCode" -> "Integrate" -> "Test";
}
Detect from codebase or ASK:
Guide the user through these Telegram steps:
- Open Telegram, find @BotFather
- Send
/newbot- Name: something like "MyApp Alerts"
- Username: something like
myapp_alerts_bot- BotFather replies with a token — copy it
- Save as
ALERT_BOT_TOKENin.env
ASK the user to confirm they have the token before proceeding.
ASK: "Where should alerts go?"
| Target | Best for | Complexity |
|---|---|---|
| Private chat | Solo dev | Easiest |
| Group | Small team | Easy |
| Channel | Read-only broadcast | Medium |
| Forum topic | Organized by category | Medium |
Guide based on their choice:
- Open Telegram, find your new alert bot
- Send it any message (e.g., "hello")
- Run in terminal:
curl -s "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates" | python3 -m json.tool
- Find
"chat": {"id": 123456789}— that positive number is yourALERT_CHAT_ID
- Create a Telegram group (or use existing)
- Add the alert bot to the group
- Send any message in the group
- Run the
getUpdatescurl above- Find
chat.id— negative number like-1001234567890
- Create a channel (or use existing)
- Add the alert bot as administrator (needs "Post Messages" permission)
- Post any message in the channel
- Run
getUpdates- Find
"channel_post"->"chat"->"id"— negative, starts with-100
- Create a group -> Settings -> enable Topics
- Add the bot to the group
- Create a topic (e.g., "Errors")
- Send a message inside that topic
- Run
getUpdates- Find TWO values:
chat.id->ALERT_CHAT_IDmessage_thread_id->ALERT_THREAD_ID
Always test before writing code:
curl -s -X POST "https://api.telegram.org/bot<TOKEN>/sendMessage" \
-d chat_id=<CHAT_ID> -d "text=Test alert" -d parse_mode=HTML
For forum topics, add -d message_thread_id=<THREAD_ID>.
If the message appears in Telegram, proceed to Phase 4.
Troubleshooting empty getUpdates:
/setprivacy to @BotFather -> set to DisabledUse the appropriate reference implementation from this skill's directory:
| Stack | Reference File |
|---|---|
| Python async (FastAPI, aiohttp) | references/alert_service_async.py |
| Python sync (Django, Flask) | references/alert_service_sync.py |
| Node.js / TypeScript | references/alert_service_node.ts |
Read the reference file and adapt to the project:
Wire alert service into the project's error handling. The pattern:
logger.error() / console.error())| Framework | Unhandled Exception Hook | Startup Hook |
|---|---|---|
| FastAPI | @app.exception_handler(Exception) | lifespan context manager |
| Django | Custom middleware + 500 handler | AppConfig.ready() |
| Flask | @app.errorhandler(Exception) | App factory / before_first_request |
| Express | app.use((err, req, res, next) => ...) | After app.listen() |
| NestJS | @Catch() exception filter | onModuleInit() |
Add to .env and .env.example:
# Telegram operational alerts (optional)
# ALERT_BOT_TOKEN=123456:ABC-DEF...
# ALERT_CHAT_ID=-1001234567890
# ALERT_THREAD_ID=42
Ensure the config treats these as optional — alerting gracefully disables when not configured:
alerting_enabled = bool(ALERT_BOT_TOKEN and ALERT_CHAT_ID)
Consistent across all stacks — use Telegram HTML parse mode:
🔴 <b>Error</b>
<pre>Env: production
Error: ValueError
Context: [module.name] error message
Traceback (most recent call last):
...</pre>
🟡 <b>Warning</b>
<pre>Env: production
Some warning message</pre>
🟢
<pre>Application started
Env: production</pre>
Non-negotiable for every implementation:
{ExcType}:{lineno}@{filename}. One alert per crash site<>& breaking Telegram HTMLcreate_task(), sync: daemon thread. Never block requests| Mistake | Consequence | Fix |
|---|---|---|
| Same bot for app + alerts | Alerts fail when app bot is down | Separate bot token |
| No dedup | Hundreds of identical alerts | Dedup by exc type + location |
await send_alert() in request path | Slow requests if Telegram lags | Fire-and-forget |
| Log send failure at ERROR | Infinite alert loop | Log at DEBUG |
| No truncation | Telegram silently drops message | Truncate to 3500 chars |
| Raw HTML in traceback | Broken formatting | html.escape() all content |
| Alert required for startup | App won't start without Telegram | Optional via alerting_enabled |
getUpdates returns empty | Can't find chat ID | Send message first, curl immediately |
npx claudepluginhub dmitriyyukhanov/claude-plugins --plugin tg-alertsImplements Telegram bots with full Bot API support: BotFather setup, messages, webhooks, inline keyboards, groups, channels. Node.js and Python boilerplates.
Diagnoses, debugs, deploys, and monitors Telegram bots with structured health checks, webhook/polling diagnostics, environment validation, and safe restart checklists.
Enables communication with users via Telegram for clarifications, options, blockers, task completion notifications, and long-running task updates instead of terminal.