telegram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTelegram Bot API Skill
Telegram Bot API 技能
You have full access to the Telegram Bot API. Use CLI commands for common operations, and direct API calls for everything else.
您拥有Telegram Bot API的完整访问权限。常用操作可使用CLI命令,其他操作可直接调用API。
Getting the Bot Token
获取Bot Token
bash
BOT_TOKEN=$(curl -s http://localhost:23001/api/settings | jq -r '.telegram.botToken')bash
BOT_TOKEN=$(curl -s http://localhost:23001/api/settings | jq -r '.telegram.botToken')API Call Pattern
API调用模式
bash
undefinedbash
undefinedJSON body (most methods)
JSON请求体(大多数方法)
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/<METHOD>"
-H "Content-Type: application/json"
-d '{ ... }'
-H "Content-Type: application/json"
-d '{ ... }'
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/<METHOD>"
-H "Content-Type: application/json"
-d '{ ... }'
-H "Content-Type: application/json"
-d '{ ... }'
Multipart form (file uploads)
多部分表单(文件上传)
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/<METHOD>"
-F "chat_id=<CHAT_ID>"
-F "photo=@/path/to/file.jpg"
-F "caption=optional caption"
-F "chat_id=<CHAT_ID>"
-F "photo=@/path/to/file.jpg"
-F "caption=optional caption"
Full API docs: https://core.telegram.org/bots/api
---curl -s "https://api.telegram.org/bot${BOT_TOKEN}/<METHOD>"
-F "chat_id=<CHAT_ID>"
-F "photo=@/path/to/file.jpg"
-F "caption=optional caption"
-F "chat_id=<CHAT_ID>"
-F "photo=@/path/to/file.jpg"
-F "caption=optional caption"
完整API文档:https://core.telegram.org/bots/api
---CLI Quick Commands
CLI快速命令
bash
undefinedbash
undefinedCurrent chat (ALMA_CHAT_ID auto-set)
当前聊天(ALMA_CHAT_ID会自动设置)
alma send photo /path/to/img.jpg "caption"
alma send file /path/to/doc.pdf "caption"
alma send audio /path/to/song.mp3
alma send video /path/to/vid.mp4
alma send photo /path/to/img.jpg "caption"
alma send file /path/to/doc.pdf "caption"
alma send audio /path/to/song.mp3
alma send video /path/to/vid.mp4
Group operations
群组操作
alma group list
alma group send <chatId> "text"
alma group send-photo <chatId> /path "caption"
alma group send-document <chatId> /path "caption"
alma group send-video <chatId> /path "caption"
alma group history <chatId> [limit]
alma group search <chatId> "query"
alma group context <chatId>
alma group pin <chatId> <msgId>
alma group unpin <chatId> [msgId]
alma group leave <chatId>
alma group patrol
alma group list
alma group send <chatId> "text"
alma group send-photo <chatId> /path "caption"
alma group send-document <chatId> /path "caption"
alma group send-video <chatId> /path "caption"
alma group history <chatId> [limit]
alma group search <chatId> "query"
alma group context <chatId>
alma group pin <chatId> <msgId>
alma group unpin <chatId> [msgId]
alma group leave <chatId>
alma group patrol
Direct message & message mgmt
私信与消息管理
alma dm <userId> "message"
alma msg delete <chatId> <msgId>
alma msg react <chatId> <msgId> <emoji> # Add reaction to a message (e.g. ❤️ 😂 👍)
alma msg sticker <chatId> <sticker_file_id> # Send a sticker (use file_id from received stickers)
alma msg sticker-search [set_name] # List sticker sets (no args) or index a specific set
alma msg sticker-find <emoji> # Find stickers by emoji across all indexed sets
---alma dm <userId> "message"
alma msg delete <chatId> <msgId>
alma msg react <chatId> <msgId> <emoji> # 给消息添加反应(例如 ❤️ 😂 👍)
alma msg sticker <chatId> <sticker_file_id> # 发送贴纸(使用收到贴纸的file_id)
alma msg sticker-search [set_name] # 列出贴纸套装(无参数)或索引特定套装
alma msg sticker-find <emoji> # 在所有已索引的套装中按表情查找贴纸
---All Telegram Bot API Methods
所有Telegram Bot API方法
Sending Messages
发送消息
| Method | Description |
|---|---|
| Send text message. Params: |
| Send photo. |
| Send file. |
| Send video. |
| Send GIF. |
| Send audio. |
| Send voice message. |
| Send round video. |
| Send sticker. |
| Send location. |
| Send venue. |
| Send contact. |
| Send poll. |
| Send dice/slot. |
| Send album (2-10 items). |
| Show typing/uploading status. |
| Stream partial message. |
| 方法 | 描述 |
|---|---|
| 发送文本消息。参数: |
| 发送照片。参数: |
| 发送文件。参数: |
| 发送视频。参数: |
| 发送GIF。参数: |
| 发送音频。参数: |
| 发送语音消息。参数: |
| 发送圆形视频。参数: |
| 发送贴纸。参数: |
| 发送位置。参数: |
| 发送地点信息。参数: |
| 发送联系人。参数: |
| 发送投票。参数: |
| 发送骰子/老虎机。参数: |
| 发送相册(2-10个项目)。参数: |
| 显示输入/上传状态。参数: |
| 发送消息草稿。参数: |
Forwarding & Copying
转发与复制
| Method | Description |
|---|---|
| Forward message. |
| Forward multiple. |
| Copy without "Forwarded" header. |
| Copy multiple. |
| 方法 | 描述 |
|---|---|
| 转发消息。参数: |
| 转发多条消息。参数: |
| 复制消息(无"转发"标识)。参数: |
| 复制多条消息。参数: |
Editing Messages
编辑消息
| Method | Description |
|---|---|
| Edit text. |
| Edit caption. |
| Edit media. |
| Edit inline keyboard. |
| Update live location. |
| Stop live location. |
| Delete message. |
| Delete multiple. |
| 方法 | 描述 |
|---|---|
| 编辑文本。参数: |
| 编辑说明文字。参数: |
| 编辑媒体内容。参数: |
| 编辑内联键盘。参数: |
| 更新实时位置。参数: |
| 停止实时位置更新。参数: |
| 删除消息。参数: |
| 删除多条消息。参数: |
Reactions
消息反应
| Method | Description |
|---|---|
| React to message. |
| 方法 | 描述 |
|---|---|
| 给消息添加反应。参数: |
Chat Management
聊天管理
| Method | Description |
|---|---|
| Get chat info. |
| Member count. |
| Get one member's info. |
| List admins. |
| Set title. |
| Set description. |
| Set photo. |
| Delete photo. |
| Set default permissions. |
| Set sticker set. |
| Remove sticker set. |
| Leave chat. |
| Pin message. |
| Unpin message. |
| Unpin all. |
| 方法 | 描述 |
|---|---|
| 获取聊天信息。参数: |
| 获取成员数量。参数: |
| 获取单个成员信息。参数: |
| 列出管理员。参数: |
| 设置标题。参数: |
| 设置描述。参数: |
| 设置头像。参数: |
| 删除头像。参数: |
| 设置默认权限。参数: |
| 设置贴纸套装。参数: |
| 移除贴纸套装。参数: |
| 离开聊天。参数: |
| 置顶消息。参数: |
| 取消置顶消息。参数: |
| 取消所有置顶消息。参数: |
Member Management
成员管理
| Method | Description |
|---|---|
| Ban user. |
| Unban user. |
| Restrict user. |
| Promote to admin. |
| Set admin title. |
| Approve join request. |
| Decline join request. |
| 方法 | 描述 |
|---|---|
| 封禁用户。参数: |
| 解封用户。参数: |
| 限制用户权限。参数: |
| 提升为管理员。参数: |
| 设置管理员自定义头衔。参数: |
| 批准加入请求。参数: |
| 拒绝加入请求。参数: |
Invite Links
邀请链接
| Method | Description |
|---|---|
| Create new primary link. |
| Create invite link. |
| Edit invite link. |
| Revoke link. |
| Paid subscription link. |
| 方法 | 描述 |
|---|---|
| 创建新的主邀请链接。参数: |
| 创建邀请链接。参数: |
| 编辑邀请链接。参数: |
| 撤销邀请链接。参数: |
| 创建付费订阅链接。参数: |
Forum Topics
论坛话题
| Method | Description |
|---|---|
| Create topic. |
| Edit topic. |
| Close topic. |
| Reopen topic. |
| Delete topic. |
| Unpin all in topic. |
| Get available topic icons |
| Edit General topic. |
| Close General. |
| Reopen General. |
| Hide General. |
| Unhide General. |
| 方法 | 描述 |
|---|---|
| 创建话题。参数: |
| 编辑话题。参数: |
| 关闭话题。参数: |
| 重新打开话题。参数: |
| 删除话题。参数: |
| 取消话题内所有置顶消息。参数: |
| 获取可用的话题图标贴纸 |
| 编辑通用话题。参数: |
| 关闭通用话题。参数: |
| 重新打开通用话题。参数: |
| 隐藏通用话题。参数: |
| 显示通用话题。参数: |
Bot Profile
Bot资料
| Method | Description |
|---|---|
| Get bot info |
| Set bot name. |
| Get bot name |
| Set bot description. |
| Get bot description |
| Set short description. |
| Get short description |
| Set bot profile photo. |
| Remove bot profile photo |
| Set command list. |
| Get commands |
| Delete commands |
| Set menu button. |
| Get menu button |
| Set default admin rights. |
| Get default admin rights |
| 方法 | 描述 |
|---|---|
| 获取Bot信息 |
| 设置Bot名称。参数: |
| 获取Bot名称 |
| 设置Bot描述。参数: |
| 获取Bot描述 |
| 设置Bot简短描述。参数: |
| 获取Bot简短描述 |
| 设置Bot头像。参数: |
| 移除Bot头像 |
| 设置命令列表。参数: |
| 获取命令列表 |
| 删除命令列表 |
| 设置菜单按钮。参数: |
| 获取菜单按钮 |
| 设置默认管理员权限。参数: |
| 获取默认管理员权限 |
User Info
用户信息
| Method | Description |
|---|---|
| Get profile photos. |
| Get profile audios. |
| 方法 | 描述 |
|---|---|
| 获取用户头像。参数: |
| 获取用户个人音频。参数: |
Files
文件
| Method | Description |
|---|---|
| Get file download info. |
| 方法 | 描述 |
|---|---|
| 获取文件下载信息。参数: |
Inline Keyboards & Callbacks
内联键盘与回调
json
// reply_markup for inline buttons
{
"inline_keyboard": [
[{"text": "Button 1", "callback_data": "btn1"}, {"text": "URL", "url": "https://example.com"}],
[{"text": "Row 2", "callback_data": "btn2"}]
]
}| Method | Description |
|---|---|
| Answer callback from inline button. |
json
// 内联按钮的reply_markup
{
"inline_keyboard": [
[{"text": "Button 1", "callback_data": "btn1"}, {"text": "URL", "url": "https://example.com"}],
[{"text": "Row 2", "callback_data": "btn2"}]
]
}| 方法 | 描述 |
|---|---|
| 响应内联按钮的回调。参数: |
Stickers
贴纸
| Method | Description |
|---|---|
| Send sticker. |
| Get sticker set. |
| Get custom emoji. |
| Create sticker set. |
| Add sticker. |
| Reorder. |
| Delete sticker. |
| Set title. |
| Set thumbnail. |
| 方法 | 描述 |
|---|---|
| 发送贴纸。参数: |
| 获取贴纸套装。参数: |
| 获取自定义表情。参数: |
| 创建新贴纸套装。参数: |
| 向套装添加贴纸。参数: |
| 调整贴纸顺序。参数: |
| 从套装删除贴纸。参数: |
| 设置套装标题。参数: |
| 设置套装缩略图。参数: |
Payments
支付
| Method | Description |
|---|---|
| Send invoice. |
| Create payment link |
| Answer shipping. |
| Answer checkout. |
| Refund stars. |
| 方法 | 描述 |
|---|---|
| 发送发票。参数: |
| 创建支付链接 |
| 响应配送查询。参数: |
| 响应预结账查询。参数: |
| 退款Stars支付。参数: |
Games
游戏
| Method | Description |
|---|---|
| Send game. |
| Set score. |
| Get scores. |
| 方法 | 描述 |
|---|---|
| 发送游戏。参数: |
| 设置游戏分数。参数: |
| 获取游戏最高分。参数: |
Common Examples
常见示例
Post to a channel
发布到频道
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "@channel_username", "text": "Hello!"}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "@channel_username", "text": "Hello!"}'Send photo with inline keyboard
发送带内联键盘的照片
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendPhoto" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "'$ALMA_CHAT_ID'",
"photo": "https://example.com/image.jpg",
"caption": "Check this out!",
"reply_markup": {"inline_keyboard": [[{"text":"👍 Like","callback_data":"like"},{"text":"👎","callback_data":"dislike"}]]}
}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendPhoto" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "'$ALMA_CHAT_ID'",
"photo": "https://example.com/image.jpg",
"caption": "Check this out!",
"reply_markup": {"inline_keyboard": [[{"text":"👍 Like","callback_data":"like"},{"text":"👎","callback_data":"dislike"}]]}
}'Forward message between chats
在聊天之间转发消息
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/forwardMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<TARGET>", "from_chat_id": "<SOURCE>", "message_id": 123}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/forwardMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<TARGET>", "from_chat_id": "<SOURCE>", "message_id": 123}'Create a poll
创建投票
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendPoll" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "question": "Best language?", "options": [{"text":"Rust"},{"text":"TypeScript"},{"text":"Python"}], "is_anonymous": false}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendPoll" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "question": "Best language?", "options": [{"text":"Rust"},{"text":"TypeScript"},{"text":"Python"}], "is_anonymous": false}'Reply to a specific message
回复特定消息
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "text": "Replying!", "reply_parameters": {"message_id": 5678}}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "text": "Replying!", "reply_parameters": {"message_id": 5678}}'Promote user to admin
提升用户为管理员
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/promoteChatMember" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<GROUP>", "user_id": 12345, "can_pin_messages": true, "can_invite_users": true}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/promoteChatMember" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<GROUP>", "user_id": 12345, "can_pin_messages": true, "can_invite_users": true}'Upload and send a local file
上传并发送本地文件
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument" \
-F "chat_id=$ALMA_CHAT_ID" \
-F "document=@/path/to/file.pdf" \
-F "caption=Here's the document"bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument" \
-F "chat_id=$ALMA_CHAT_ID" \
-F "document=@/path/to/file.pdf" \
-F "caption=Here's the document"Send album (media group)
发送相册(媒体组)
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "media": [
{"type":"photo","media":"https://example.com/1.jpg","caption":"First"},
{"type":"photo","media":"https://example.com/2.jpg"}
]}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup" \
-H "Content-Type: application/json" \
-d '{"chat_id": "'$ALMA_CHAT_ID'", "media": [
{"type":"photo","media":"https://example.com/1.jpg","caption":"First"},
{"type":"photo","media":"https://example.com/2.jpg"}
]}'Create invite link
创建邀请链接
bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/createChatInviteLink" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<GROUP>", "name": "My Link", "member_limit": 100}'bash
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/createChatInviteLink" \
-H "Content-Type: application/json" \
-d '{"chat_id": "<GROUP>", "name": "My Link", "member_limit": 100}'Tips
提示
- Channel posts: Use or numeric chat_id (starts with
@channel_username)-100 - Bot must be admin to: post to channels, pin, delete others' messages, ban, manage topics
- ALMA_CHAT_ID is auto-set in Bash tool env — use it for current chat
- File uploads: Use multipart form, not
-FJSON-d - parse_mode: Use for
"HTML"<b>bold</b> <i>italic</i> <code>code</code> <a href="url">link</a> - Group IDs are negative; user IDs are positive
- Message IDs are visible as in chat
[msg:xxx] - For methods not listed here, check https://core.telegram.org/bots/api
- 频道发帖:使用或数字聊天ID(以
@channel_username开头)-100 - Bot必须是管理员才能:在频道发帖、置顶消息、删除他人消息、封禁用户、管理话题
- ALMA_CHAT_ID会在Bash工具环境中自动设置 — 可用于当前聊天
- 文件上传:使用多部分表单,而非
-FJSON-d - parse_mode:使用来实现
"HTML"格式<b>粗体</b> <i>斜体</i> <code>代码</code> <a href="url">链接</a> - 群组ID为负数;用户ID为正数
- 消息ID在聊天中显示为
[msg:xxx] - 未在此列出的方法,请查看https://core.telegram.org/bots/api