ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

telegram-bot-messaging - SKILL

2026/10/3 2:26:23 拓冰建站 浏览量
telegram-bot-messaging - SKILL name: telegram-bot-messagingdescription: “Send Telegram messages, files, and alerts via bot API; ask questions with inline buttons and wait for the answer. Supports multiple bots, named chat targets, and CI/cron/hook notifications.”category: productivityrisk: criticalsource: https://github.com/sanjay3290/ai-skills/tree/main/skills/telegramsource_repo: sanjay3290/ai-skillssource_type: communitydate_added: “2026-07-09”author: sanjay3290tags: [telegram, notifications, bots, approvals]tools: [claude, cursor, gemini]license: “Apache-2.0”license_source: “https://github.com/sanjay3290/ai-skills/blob/main/LICENSE”Telegram何时使用当需要从工作流、钩子、cron 任务或 CI 流水线发送 Telegram 消息、文件或提醒时使用当长时间运行的任务应在手机上通知你或请求你批准时使用内联按钮提问并等待回答当把完成后通知我或继续前先问我的行为接入自动化会话时使用向 Telegram 发送更新、提醒和文件读取回复运行提问并等待的审批流程。纯 bash curl jq —— 除了机器人令牌外无需安装。首次运行:bash scripts/telegram.sh setup引导式 BotFather 演练。安全闸门在设置、发送消息或文件、读取回复或启用钩子之前请先获得用户对目标聊天、机器人账号以及确切内容或文件的明确批准。切勿自动发送工作区、客户、凭据或机密数据。将令牌视为机密不要回显它、不要提交它、也不要让它出现在 shell 历史中。命令bashscripts/telegram.sh sendDeploy finished ✅# basic alertbashscripts/telegram.sh sendlow priority--silent# no notification soundbashscripts/telegram.sh send*bold* alert--formatmd# MarkdownV2 (falls back to plain)bashscripts/telegram.sh sendhi--toalerts--botwork# named target named botbashscripts/telegram.shfilereport.pdfQ3 report# document (photos auto-detected)bashscripts/telegram.shread# new incoming messages since last readANSWER$(bashscripts/telegram.sh askDeploy to prod?--optionsYes,No--timeout300)# exit 0 answered (stdout answer), 2 timeout配置环境变量优先其次为~/.config/telegram/config权限 600TELEGRAM_BOT_TOKEN123:ABC... # default bot TELEGRAM_CHAT_ID987654321 # default target BOT_ALERTS_TOKEN456:DEF... # --bot alerts (add via: setup --bot alerts) TARGET_FAMILY-100987... # --to family (any chat/group/channel id) TELEGRAM_APPROVER_IDS123456789 # default group approver user IDs (comma-separated) APPROVERS_FAMILY123456789,987654321 # approvers for --to family (overrides default)回复和回答仅接受来自已配置聊天 ID 的消息。私聊保持直接聊天行为发送者用户 ID 必须等于聊天 ID。由于群聊 ID 被每个成员共享除非TELEGRAM_APPROVER_IDS或目标特定的APPROVERS_NAME明确列出了允许回答的 Telegram 用户 ID否则群聊中的ask会以失败关闭。Claude Code 钩子settings.json当 Claude 需要输入以及完成时通知你的手机{hooks:{Notification:[{hooks:[{type:command,command:bash ~/.claude/skills/telegram/scripts/telegram.sh send \ Claude needs input in $(basename \\\$PWD\\\)\}]}],Stop:[{hooks:[{type:command,command:bash ~/.claude/skills/telegram/scripts/telegram.sh send \✅ Claude finished in $(basename \\\$PWD\\\)\ --silent}]}]}}任何脚本/自动化中的审批闸门if[$(bashscripts/telegram.sh askDeploy to prod?--optionsYes,No)Yes];then./deploy.shfi局限性Telegram 是第三方服务消息和文件内容会离开本地机器并且可能根据 Telegram 的政策被保留。此技能无法验证聊天 ID 是否属于预期的接收者在每次新的目的地或自动化之前确认目标。机器人令牌赋予对机器人的完全控制权。仅将它们存储在受保护的本地机密存储或权限 600 的配置文件中。脚本通过stdin 而非进程参数将包含令牌的 API URL 提供给 curl如果怀疑令牌泄露请轮换它。未经用户明确、当前的授权不要使用示例创建无人值守的通知或审批流程。