微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🤖

原生 HTTPS 构建专业级 Bot

Telegram · v1.0.1
developer-tools 安全 S 级 榜单 #27 作者 codedao12 公开目录收录
17.3k 下载 22 安装 66.3k 收藏 33 浏览

简介

通过原生 HTTPS 构建生产级 Telegram 机器人,支持命令驱动对话与 Webhook/轮询双模式,无需 SDK。

原始描述

OpenClaw skill for designing Telegram Bot API workflows and command-driven conversations using direct HTTPS requests (no SDKs).

通过你的 Agent 添加

安装目录:telegram/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/telegram/
Codex CLI~/.codex/skills/telegram/
DeepSeek Harness~/.agents/skills/telegram/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Telegram Bot Skill 是一套面向生产环境的 Telegram Bot API 工作流设计指南,核心定位是无 SDK 的轻量实现方案。Skill 要求用户提供 Bot Token、更新策略(Webhook 或长轮询)、命令列表及对话风格,输出包含命令设计规范、更新流程规划和运维检查清单。

关键设计原则包括:

  • 严格命令路由:强制使用 /start, /help, /settings, /status 标准命令
  • 更新规范化:提供统一的 update 标准化与路由规则
  • 安全优先:Token 永不落地日志、Webhook 支持 secret token 头部验证
  • 故障容错:429 指数退避、消息突发抑制

显著优点

  1. 零依赖架构:纯 HTTPS 直连,无 SDK/框架锁定,适合对供应链安全敏感的场景
  2. 生产级规范:涵盖命令 UX、消息风格、更新路由的完整方法论
  3. 资源轻量化:202 行纯 Markdown,无可执行代码,无运行时负担
  4. 官方对齐:严格引用 Telegram 官方 API(api.telegram.org)与文档(core.telegram.org)
  5. 安全基线高:扫描评分 95/100,S 级安全评级,符合 GDPR 数据最小化

潜在缺点与局限性

  • 无开箱即用代码:需用户自行实现 HTTP 客户端与状态管理
  • 媒体上传受限:明确声明不支持复杂媒体流处理
  • T3 来源可信度:社区维护项目,内容准确性需用户交叉验证
  • 无许可证声明:当前未包含 LICENSE 文件,存在合规隐患

适合人群

  • 追求极简架构的后端开发者
  • 需要审计 Bot 全链路的合规敏感团队
  • 已有 HTTP 基础设施、希望快速对接 Telegram 的技术团队
  • 学习 Bot API 原生机制的教学场景

常规风险

  1. Token 泄露风险:HTTP 直连模式要求用户自行保管 bot<token>,Skill 虽建议不落地日志但无法强制执行
  2. Webhook 配置复杂度:自签名证书、反向代理、secret token 配置需额外 DevOps 投入
  3. Rate Limit 处理:Telegram 全局 30 msg/sec 限制需用户自行实现令牌桶或退避逻辑
  4. 更新类型演进:Bot API 持续新增 update 类型(如 Reaction、ChatJoinRequest),文档可能滞后

技能正文


name: telegram triggers: "send telegram, telegram message, telegram listener, start daemon, stop daemon, telegram notification, push notification, telegram bot, @YourBot, telegram alert" description: "Control the always-listening Telegram daemon, send messages, manage the task/goal bot, and configure scheduled alerts."

Telegram Skill

Auto-activate for Telegram message sending, daemon control, or bot configuration.

Setup Instructions (For CLI Agents)

When helping the user set up the Telegram bot, follow these steps:

Step 1: Install Dependencies

pip install -r requirements.txt

Step 2: Create Environment File

Copy the template and help the user fill in credentials:

cp .env.example .env

Required credentials (user must obtain):

Credential How to Get
TELEGRAM_BOT_TOKEN Message @BotFather on Telegram, use /newbot
TELEGRAM_BOT_USER_ID Message @userinfobot on Telegram
TELEGRAM_API_ID Go to https://my.telegram.org → API Development Tools
TELEGRAM_API_HASH Go to https://my.telegram.org → API Development Tools

Step 3: Create Logs Directory

mkdir -p logs

Step 4: Start the Bot

python telegram_listener.py --daemon

Step 5: Verify Setup

python telegram_listener.py --status

Daemon Control

What Command
Start listener /telegram start
Stop listener /telegram stop
Status + PID /telegram status
Sleep (alerts only) /telegram sleep
Wake (full response) /telegram wake
View logs /telegram logs

Send Messages

Command 'telegram' (see below for command content) send "Your message here"
Command 'telegram' (see below for command content) brief          # Send morning briefing now
Command 'telegram' (see below for command content) alert "msg"    # System alert notification

Architecture

Two-tier — daemon is standalone Python, cannot call Claude MCP directly:

Tier Mechanism Commands
Direct Pure Python + API calls tasks, goals, weather, status
Queue Write to /tmp/telegram_agent_queue.json complex queries

Key Files

  • Script: telegram_listener.py + telegram_helpers.py
  • PID: /tmp/telegram_listener.pid
  • State: /tmp/telegram_listener_state.json
  • Logs: logs/telegram_listener.log
  • Queue: /tmp/telegram_agent_queue.json
  • Template: templates/helper_template.py

Config (user_profile.json → telegram)

{ "chat_id": null, "notifications_enabled": true, "morning_brief": true,
  "task_reminders": true, "goal_checkin_time": "20:00", "always_listening": true }

Building New Integrations

Use the telegram-builder skill for detailed guidance on adding new commands and services.

Quick Pattern

  1. Add helper function in telegram_helpers.py:

    def get_my_service(query=None):
        """Fetch data from your API."""
        # Your implementation
        return "**My Service**\nResult here"
    
  2. Import in telegram_listener.py:

    from telegram_helpers import get_my_service
    
  3. Add command handler in route_command():

    if lower.startswith("/myservice"):
        query = text.split(maxsplit=1)[1] if len(text.split()) > 1 else None
        return get_my_service(query)
    

Template Reference

See templates/helper_template.py for a complete integration example.


Built-in Bot Commands

The user can send these commands directly to their bot:

Tasks & Goals

Command Action
/tasks Today's tasks
add task: ... Add a task
done: ... / done 1 Complete a task
/goals Active goals
add goal: ... Add a goal
/progress Today's stats + streak

System

Command Action
/help Full command menu
/status Listener + system health
/weather Current weather
sleep / goodnight Enter sleep mode
wake / good morning Exit sleep mode

Scheduled Alerts

Configured in user_profile.json → telegram:

Time Alert Config Key
8:00 AM Morning brief (weather, tasks, goals) morning_brief: true
8:00 PM (default) Evening check-in (completed, pending, streak) goal_checkin_time: "20:00"

正文来自原始仓库, 版权归作者所有,许可:Apache-2.0。 权利人认为有不妥,可申请下架。

原始仓库

作者的项目地址:https://github.com/shane9coy/Telegram-Bot-Easy

标签

telegrambot-apiwebhookhttpsmessagingautomationserverless-friendlysdk-free

同类 Skill