From cdc404f66f0ab909719da7c74cd845c4b8b74784 Mon Sep 17 00:00:00 2001 From: tukuaiai Date: Wed, 17 Dec 2025 20:26:50 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=92=8C=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - i18n/en/skills/telegram-dev/SKILL.md | 615 +++++++++---------- i18n/en/skills/telegram-dev/scripts/.gitkeep | 0 3 files changed, 307 insertions(+), 309 deletions(-) create mode 100644 i18n/en/skills/telegram-dev/scripts/.gitkeep diff --git a/README.md b/README.md index 298e551..e0b6774 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@

构建状态 - 最新版本 许可证 主要语言 代码量 diff --git a/i18n/en/skills/telegram-dev/SKILL.md b/i18n/en/skills/telegram-dev/SKILL.md index 2faa07f..d0a1123 100644 --- a/i18n/en/skills/telegram-dev/SKILL.md +++ b/i18n/en/skills/telegram-dev/SKILL.md @@ -1,79 +1,78 @@ -TRANSLATED CONTENT: --- name: telegram-dev -description: Telegram 生态开发全栈指南 - 涵盖 Bot API、Mini Apps (Web Apps)、MTProto 客户端开发。包括消息处理、支付、内联模式、Webhook、认证、存储、传感器 API 等完整开发资源。 +description: A full-stack guide to Telegram ecosystem development - covering Bot API, Mini Apps (Web Apps), and MTProto client development. Includes complete development resources for message handling, payments, inline mode, webhooks, authentication, storage, sensor APIs, and more. --- -# Telegram 生态开发技能 +# Telegram Ecosystem Development Skill -全面的 Telegram 开发指南,涵盖 Bot 开发、Mini Apps (Web Apps)、客户端开发的完整技术栈。 +A comprehensive guide to Telegram development, covering the full technology stack for Bot development, Mini Apps (Web Apps), and client development. -## 何时使用此技能 +## When to Use This Skill -当需要以下帮助时使用此技能: -- 开发 Telegram Bot(消息机器人) -- 创建 Telegram Mini Apps(小程序) -- 构建自定义 Telegram 客户端 -- 集成 Telegram 支付和业务功能 -- 实现 Webhook 和长轮询 -- 使用 Telegram 认证和存储 -- 处理消息、媒体和文件 -- 实现内联模式和键盘 +Use this skill when you need help with the following: +- Developing a Telegram Bot (message bot) +- Creating Telegram Mini Apps +- Building a custom Telegram client +- Integrating Telegram payments and business features +- Implementing webhooks and long polling +- Using Telegram authentication and storage +- Handling messages, media, and files +- Implementing inline mode and keyboards -## Telegram 开发生态概览 +## Overview of the Telegram Development Ecosystem -### 三大核心 API +### Three Core APIs -1. **Bot API** - 创建机器人程序 - - HTTP 接口,简单易用 - - 自动处理加密和通信 - - 适合:聊天机器人、自动化工具 +1. **Bot API** - For creating bot programs + - Simple to use HTTP interface + - Automatically handles encryption and communication + - Suitable for: chatbots, automation tools -2. **Mini Apps API** (Web Apps) - 创建 Web 应用 - - JavaScript 接口 - - 在 Telegram 内运行 - - 适合:小程序、游戏、电商 +2. **Mini Apps API** (Web Apps) - For creating web applications + - JavaScript interface + - Runs inside Telegram + - Suitable for: mini-apps, games, e-commerce -3. **Telegram API & TDLib** - 创建客户端 - - 完整的 Telegram 协议实现 - - 支持所有平台 - - 适合:自定义客户端、企业应用 +3. **Telegram API & TDLib** - For creating clients + - Full implementation of the Telegram protocol + - Supports all platforms + - Suitable for: custom clients, enterprise applications -## Bot API 开发 +## Bot API Development -### 快速开始 +### Quick Start -**API 端点:** +**API Endpoint:** ``` https://api.telegram.org/bot/METHOD_NAME ``` -**获取 Bot Token:** -1. 与 @BotFather 对话 -2. 发送 `/newbot` -3. 按提示设置名称 -4. 获取 token +**Get a Bot Token:** +1. Talk to @BotFather +2. Send `/newbot` +3. Follow the prompts to set a name +4. Get the token -**第一个 Bot (Python):** +**First Bot (Python):** ```python import requests BOT_TOKEN = "your_bot_token_here" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" -# 发送消息 +# Send a message def send_message(chat_id, text): url = f"{API_URL}/sendMessage" data = {"chat_id": chat_id, "text": text} return requests.post(url, json=data) -# 获取更新(长轮询) +# Get updates (long polling) def get_updates(offset=None): url = f"{API_URL}/getUpdates" params = {"offset": offset, "timeout": 30} return requests.get(url, params=params).json() -# 主循环 +# Main loop offset = None while True: updates = get_updates(offset) @@ -81,48 +80,48 @@ while True: chat_id = update["message"]["chat"]["id"] text = update["message"]["text"] - # 回复消息 - send_message(chat_id, f"你说了:{text}") + # Reply to the message + send_message(chat_id, f"You said: {text}") offset = update["update_id"] + 1 ``` -### 核心 API 方法 +### Core API Methods -**更新管理:** -- `getUpdates` - 长轮询获取更新 -- `setWebhook` - 设置 Webhook -- `deleteWebhook` - 删除 Webhook -- `getWebhookInfo` - 查询 Webhook 状态 +**Update Management:** +- `getUpdates` - Get updates via long polling +- `setWebhook` - Set a webhook +- `deleteWebhook` - Delete a webhook +- `getWebhookInfo` - Query webhook status -**消息操作:** -- `sendMessage` - 发送文本消息 -- `sendPhoto` / `sendVideo` / `sendDocument` - 发送媒体 -- `sendAudio` / `sendVoice` - 发送音频 -- `sendLocation` / `sendVenue` - 发送位置 -- `editMessageText` - 编辑消息 -- `deleteMessage` - 删除消息 -- `forwardMessage` / `copyMessage` - 转发/复制消息 +**Message Operations:** +- `sendMessage` - Send a text message +- `sendPhoto` / `sendVideo` / `sendDocument` - Send media +- `sendAudio` / `sendVoice` - Send audio +- `sendLocation` / `sendVenue` - Send a location +- `editMessageText` - Edit a message +- `deleteMessage` - Delete a message +- `forwardMessage` / `copyMessage` - Forward/copy a message -**交互元素:** -- `sendPoll` - 发送投票(最多 12 个选项) -- 内联键盘 (InlineKeyboardMarkup) -- 回复键盘 (ReplyKeyboardMarkup) -- `answerCallbackQuery` - 响应回调查询 +**Interactive Elements:** +- `sendPoll` - Send a poll (up to 12 options) +- Inline Keyboard (InlineKeyboardMarkup) +- Reply Keyboard (ReplyKeyboardMarkup) +- `answerCallbackQuery` - Respond to a callback query -**文件操作:** -- `getFile` - 获取文件信息 -- `downloadFile` - 下载文件 -- 支持最大 2GB 文件(本地 Bot API 模式) +**File Operations:** +- `getFile` - Get file information +- `downloadFile` - Download a file +- Supports files up to 2GB (in local Bot API mode) -**支付功能:** -- `sendInvoice` - 发送发票 -- `answerPreCheckoutQuery` - 处理支付 -- Telegram Stars 支付(最高 10,000 Stars) +**Payment Features:** +- `sendInvoice` - Send an invoice +- `answerPreCheckoutQuery` - Process a payment +- Telegram Stars payment (up to 10,000 Stars) -### Webhook 配置 +### Webhook Configuration -**设置 Webhook:** +**Set a Webhook:** ```python import requests @@ -135,7 +134,7 @@ requests.post( ) ``` -**Flask Webhook 示例:** +**Flask Webhook Example:** ```python from flask import Flask, request import requests @@ -150,10 +149,10 @@ def webhook(): chat_id = update["message"]["chat"]["id"] text = update["message"]["text"] - # 发送回复 + # Send a reply requests.post( f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage", - json={"chat_id": chat_id, "text": f"收到: {text}"} + json={"chat_id": chat_id, "text": f"Received: {text}"} ) return "OK" @@ -162,25 +161,25 @@ if __name__ == '__main__': app.run(port=5000) ``` -**Webhook 要求:** -- 必须使用 HTTPS -- 支持 TLS 1.2+ -- 端口:443, 80, 88, 8443 -- 公共可访问的 URL +**Webhook Requirements:** +- Must use HTTPS +- Supports TLS 1.2+ +- Ports: 443, 80, 88, 8443 +- Publicly accessible URL -### 内联键盘 +### Inline Keyboard -**创建内联键盘:** +**Create an Inline Keyboard:** ```python def send_inline_keyboard(chat_id): keyboard = { "inline_keyboard": [ [ - {"text": "按钮 1", "callback_data": "btn1"}, - {"text": "按钮 2", "callback_data": "btn2"} + {"text": "Button 1", "callback_data": "btn1"}, + {"text": "Button 2", "callback_data": "btn2"} ], [ - {"text": "打开链接", "url": "https://example.com"} + {"text": "Open Link", "url": "https://example.com"} ] ] } @@ -189,55 +188,55 @@ def send_inline_keyboard(chat_id): f"{API_URL}/sendMessage", json={ "chat_id": chat_id, - "text": "选择一个选项:", + "text": "Choose an option:", "reply_markup": keyboard } ) ``` -**处理回调:** +**Handle Callbacks:** ```python def handle_callback_query(callback_query): query_id = callback_query["id"] data = callback_query["data"] chat_id = callback_query["message"]["chat"]["id"] - # 响应回调 + # Respond to the callback requests.post( f"{API_URL}/answerCallbackQuery", - json={"callback_query_id": query_id, "text": f"你点击了 {data}"} + json={"callback_query_id": query_id, "text": f"You clicked {data}"} ) - # 更新消息 + # Update the message requests.post( f"{API_URL}/editMessageText", json={ "chat_id": chat_id, "message_id": callback_query["message"]["message_id"], - "text": f"你选择了:{data}" + "text": f"You chose: {data}" } ) ``` -### 内联模式 +### Inline Mode -**配置内联模式:** -与 @BotFather 对话,发送 `/setinline` +**Configure Inline Mode:** +Talk to @BotFather and send `/setinline` -**处理内联查询:** +**Handle Inline Queries:** ```python def handle_inline_query(inline_query): query_id = inline_query["id"] query_text = inline_query["query"] - # 创建结果 + # Create results results = [ { "type": "article", "id": "1", - "title": "结果 1", + "title": "Result 1", "input_message_content": { - "message_text": f"你搜索了:{query_text}" + "message_text": f"You searched for: {query_text}" } } ] @@ -248,11 +247,11 @@ def handle_inline_query(inline_query): ) ``` -## Mini Apps (Web Apps) 开发 +## Mini Apps (Web Apps) Development -### 初始化 Mini App +### Initialize a Mini App -**HTML 模板:** +**HTML Template:** ```html @@ -264,34 +263,34 @@ def handle_inline_query(inline_query):

Telegram Mini App

- +