telegram-polling
БесплатноЗапускает вложенные скриптыНе проверенPoll Telegram Bot API for new messages and route commands to agents. Implements 10-command bot with fail-closed allowlist, owner-only tier, two-step approve…
от oimiragieo★ 48 звёзд на GitHubОб этом скилле
Telegram Polling Skill
Overview
Polls the Telegram Bot API every 2 minutes via CronCreate and routes each incoming message to a command handler. Implements a 10-command bot with layered security: a fail-closed allowlist, an owner-only tier for privileged commands, audit logging, and replay-prevention offset tracking.
Key constraints:
- Telegram requires push-based responses — only send FINAL replies, never partial/streaming output.
- ALL commands are silently dropped for unauthorized senders (fail-closed, no "bot is active" leakage).
- Offset is written BEFORE processing commands to prevent replay attacks.
Prerequisites
- Create a Telegram bot via @BotFather → get token
- Find your Telegram user ID via @userinfobot
- Set required env vars in
.env:
TELEGRAM_BOT_TOKEN=your-bot-token-here
TELEGRAM_ALLOWED_USERS=123456789,987654321 # Comma-separated allowed user IDs
TELEGRAM_OWNER_ID=123456789 # Single owner user ID for privileged commands
Verify:
node -e "require('dotenv').config(); \
console.log('TOKEN:', process.env.TELEGRAM_BOT_TOKEN ? 'SET' : 'NOT_SET'); \
console.log('ALLOWED_USERS:', process.env.TELEGRAM_ALLOWED_USERS || 'EMPTY (ALL BLOCKED)'); \
console.log('OWNER_ID:', process.env.TELEGRAM_OWNER_ID || 'NOT_SET');"
Environment Variables
| Variable | Required | Purpose |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Yes | Bot API token from @BotFather |
TELEGRAM_ALLOWED_USERS |
Yes (fail-closed if empty) | Comma-separated Telegram user IDs. If empty or missing, ALL commands are blocked. |
TELEGRAM_OWNER_ID |
Yes (for privileged commands) | Single user ID with access to /ask, /spawn, /approve, /deny |
Authorization Model (REQ-01, REQ-02)
Two-tier authorization is applied to EVERY incoming update before any command is processed:
Tier 1: Allowlist Check (REQ-01 — Fail-Closed)
TELEGRAM_ALLOWED_USERS must contain the sender's user_id.toString()
- If
TELEGRAM_ALLOWED_USERSis empty, missing, or does not contain the sender: silent drop (no response, no indication bot is active). - Parse:
process.env.TELEGRAM_ALLOWED_USERS.split(',').map(s => s.trim()).filter(Boolean) - Empty string after split/filter = fail-closed (no allowed users = nobody passes).
Tier 2: Owner Check (REQ-02)
TELEGRAM_OWNER_ID must equal sender's user_id.toString()
- Only
TELEGRAM_OWNER_IDuser may use:/ask,/spawn,/approve(+/confirm),/deny - Owner-only unauthorized attempt: reply "Unauthorized" (only after passing Tier 1).
Authorization pseudocode
const allowedUsers = (process.env.TELEGRAM_ALLOWED_USERS || '')
.split(',')
.map(s => s.trim())
.filter(Boolean);
const ownerId = (process.env.TELEGRAM_OWNER_ID || '').trim();
const senderId = String(msg.from.id);
// REQ-01: Fail-closed allowlist
if (allowedUsers.length === 0 || !allowedUsers.includes(senderId)) {
// Silent drop — do NOT reply
return;
}
// REQ-02: Owner tier check (only for privileged commands)
const isOwner = senderId === ownerId;
const ownerOnlyCommands = ['/ask', '/spawn', '/approve', '/confirm', '/deny'];
if (ownerOnlyCommands.some(cmd => command.startsWith(cmd)) && !isOwner) {
await sendMessage(chatId, 'Unauthorized');
return;
}
State File: .claude/context/tmp/telegram-offset.json
{
"offset": 0,
"last_processed_update_id": 0,
"last_processed_at": "2026-03-08T10:00:00.000Z",
"pending_confirmations": {
"42": {
"action": "approve",
"requested_at": "2026-03-08T10:00:00.000Z",
"expires_at": "2026-03-08T10:01:00.000Z"
}
}
}
offset: next update_id to fetch (= last_processed_update_id + 1)last_processed_update_id: highest update_id seenpending_confirmations: keyed by TASK_ID (string), value has action + timestamps- Confirmations expire after 60 seconds (REQ-04)
Offset Security (REQ-07)
ALWAYS write the new offset BEFORE processing commands. This prevents replay attacks if the bot crashes mid-processing.
// Step 1: Read current offset
const state = safeReadJSON(offsetFile) || {
offset: 0,
last_processed_update_id: 0,
pending_confirmations: {},
};
const currentOffset = state.offset || 0;
// Step 2: Fetch updates
const updates = await fetchUpdates(token, currentOffset);
// Step 3: Filter to updates with update_id > last_processed_update_id (replay prevention)
const newUpdates = updates.filter(u => u.update_id > (state.la
Установить telegram-polling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteBashTaskCreateTaskUpdateTaskListTaskGetSkillВложенные файлы
FAQ
Что делает скилл telegram-polling?
Poll Telegram Bot API for new messages and route commands to agents. Implements 10-command bot with fail-closed allowlist, owner-only tier, two-step approve, audit logging, and replay-prevention offset tracking.
Как установить скилл telegram-polling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл telegram-polling запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic