简介
通过 Maton 网关安全调用 Telegram Bot API,支持消息发送、群组管理、Webhook 与交互式机器人开发,需配置 API 密钥与 Bot Token。
原始描述
Telegram Bot API integration with managed authentication. Send messages, manage chats, handle updates, and interact with users through your Telegram bot. Use this skill when users want to send messages, create polls, manage bot commands, or interact with Telegram chats. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
通过你的 Agent 添加
安装目录:telegram/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
Telegram Skill 是 Maton 平台提供的托管式 Telegram Bot API 网关,允许开发者无需直接暴露 Bot Token 即可调用完整的 Telegram Bot 接口。核心流程包括:
- 环境配置:设置
MATON_API_KEY环境变量,从 maton.ai 获取 API 密钥 - 连接管理:通过
ctrl.maton.ai创建 Telegram 连接,完成 Bot Token 授权 - API 调用:使用
gateway.maton.ai/telegram/:token/{method}格式调用任意 Telegram Bot API 方法,:token自动替换为托管的 Bot Token
主要功能覆盖:
- 消息发送(文本、图片、视频、文档、音频、位置、联系人)
- 交互组件(内联键盘、回复键盘、轮询投票、骰子动画)
- 消息管理(编辑、删除、转发、复制消息)
- 群组与频道(获取聊天信息、管理员列表、成员数量)
- 机器人配置(设置命令菜单、个人资料、描述信息)
- 实时更新(长轮询 getUpdates、Webhook 设置)
- 文件处理(获取文件信息、下载链接生成)
技术特点:
- 支持 Python、JavaScript 等多种语言的代码示例
- 连接级多 Bot 管理(通过
Maton-Connection头指定) - 自动 token 替换,避免敏感信息硬编码
- 完整的 Telegram Bot API 透传,无功能阉割
显著优点
- 安全托管:Bot Token 由 Maton 平台加密存储,调用时自动注入,降低泄露风险
- 简化认证:统一使用 Maton API Key,无需处理 Telegram 的多重认证机制
- 多 Bot 支持:单账户可管理多个 Telegram Bot,通过连接 ID 灵活切换
- 完整 API 覆盖:支持 Telegram Bot API 全部方法,包括最新的轮询、WebApp、表情回应等功能
- 开发友好:提供 Python urllib、requests、JavaScript fetch 等完整代码示例
- 企业就绪:支持连接状态查询、批量管理、Webhook 安全配置
潜在缺点与局限性
- 平台依赖:完全依赖 Maton 服务可用性,若网关故障则所有 Bot 受影响
- 网络延迟:请求需经过 Maton 网关转发,较直接调用 Telegram API 增加一跳延迟
- 文件上传限制:建议使用 URL 方式传文件,直接上传需处理 multipart/form-data 复杂度
- 速率限制透传:Telegram 原有限制(如每分钟 30 条消息)仍然生效,网关层额外限制未明确说明
- 调试复杂度:多层网关结构(Maton → Telegram)增加了问题定位难度
- 商业绑定:长期使用需维持 Maton 账户有效性,迁移成本较高
适合人群
- Bot 开发者:需要快速搭建 Telegram 机器人的独立开发者
- 运维团队:管理多 Bot、多环境的自动化消息推送需求
- 企业集成:已有 Maton 生态,需将 Telegram 纳入统一 API 管理体系
- 安全敏感场景:不希望 Bot Token 分散在多处代码或配置中的团队
常规风险
风险类型
说明
缓解建议
密钥泄露
MATON_API_KEY 若泄露,攻击者可操作全部连接
使用环境变量,避免提交到版本控制;定期轮换密钥
Token 权限滥用
Bot Token 可能具有群组管理、消息删除等高权限
遵循最小权限原则,定期审查 Bot 所在群组
Webhook 安全
若自行设置 Webhook,需验证 secret_token
始终配置 secret_token 并验证请求来源
消息内容风险
发送 HTML/Markdown 时可能触发 XSS 或钓鱼
过滤用户输入,使用 parse_mode 时谨慎拼接内容
速率封禁
高频调用可能导致 Telegram 封禁 Bot
实施指数退避重试,监控 429 错误响应
数据隐私
消息内容经过 Maton 网关,存在中间人风险
敏感场景考虑端到端加密或直连 Telegram API
- 平台依赖:完全依赖 Maton 服务可用性,若网关故障则所有 Bot 受影响
- 网络延迟:请求需经过 Maton 网关转发,较直接调用 Telegram API 增加一跳延迟
- 文件上传限制:建议使用 URL 方式传文件,直接上传需处理 multipart/form-data 复杂度
- 速率限制透传:Telegram 原有限制(如每分钟 30 条消息)仍然生效,网关层额外限制未明确说明
- 调试复杂度:多层网关结构(Maton → Telegram)增加了问题定位难度
- 商业绑定:长期使用需维持 Maton 账户有效性,迁移成本较高
适合人群
- Bot 开发者:需要快速搭建 Telegram 机器人的独立开发者
- 运维团队:管理多 Bot、多环境的自动化消息推送需求
- 企业集成:已有 Maton 生态,需将 Telegram 纳入统一 API 管理体系
- 安全敏感场景:不希望 Bot Token 分散在多处代码或配置中的团队
常规风险
风险类型
说明
缓解建议
密钥泄露
MATON_API_KEY 若泄露,攻击者可操作全部连接
使用环境变量,避免提交到版本控制;定期轮换密钥
Token 权限滥用
Bot Token 可能具有群组管理、消息删除等高权限
遵循最小权限原则,定期审查 Bot 所在群组
Webhook 安全
若自行设置 Webhook,需验证 secret_token
始终配置 secret_token 并验证请求来源
消息内容风险
发送 HTML/Markdown 时可能触发 XSS 或钓鱼
过滤用户输入,使用 parse_mode 时谨慎拼接内容
速率封禁
高频调用可能导致 Telegram 封禁 Bot
实施指数退避重试,监控 429 错误响应
数据隐私
消息内容经过 Maton 网关,存在中间人风险
敏感场景考虑端到端加密或直连 Telegram API
| 风险类型 | 说明 | 缓解建议 |
|---|---|---|
| 密钥泄露 | MATON_API_KEY 若泄露,攻击者可操作全部连接 |
使用环境变量,避免提交到版本控制;定期轮换密钥 |
| Token 权限滥用 | Bot Token 可能具有群组管理、消息删除等高权限 | 遵循最小权限原则,定期审查 Bot 所在群组 |
| Webhook 安全 | 若自行设置 Webhook,需验证 secret_token | 始终配置 secret_token 并验证请求来源 |
| 消息内容风险 | 发送 HTML/Markdown 时可能触发 XSS 或钓鱼 | 过滤用户输入,使用 parse_mode 时谨慎拼接内容 |
| 速率封禁 | 高频调用可能导致 Telegram 封禁 Bot | 实施指数退避重试,监控 429 错误响应 |
| 数据隐私 | 消息内容经过 Maton 网关,存在中间人风险 | 敏感场景考虑端到端加密或直连 Telegram API |
技能正文
name: telegram
description: |
Telegram Bot API integration with managed authentication. Send messages, manage chats, handle updates, and interact with users through your Telegram bot. Use this skill when users want to send messages, create polls, manage bot commands, or interact with Telegram chats. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
compatibility: Requires network access and valid Maton API key
metadata:
author: maton
version: "1.0"
clawdbot:
emoji: 🧠
requires:
env:
- MATON_API_KEY
Telegram Bot API
Access the Telegram Bot API with managed authentication. Send messages, photos, polls, locations, and more through your Telegram bot.
Quick Start
# Get bot info
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/telegram/:token/getMe')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Base URL
https://gateway.maton.ai/telegram/:token/{method}
# Get bot info
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/telegram/:token/getMe')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
https://gateway.maton.ai/telegram/:token/{method}
The :token placeholder is automatically replaced with your bot token from the connection configuration. Replace {method} with the Telegram Bot API method name (e.g., sendMessage, getUpdates).
Authentication
All requests require the Maton API key in the Authorization header:
Authorization: Bearer $MATON_API_KEY
Environment Variable: Set your API key as MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
Getting Your API Key
- Sign in or create an account at maton.ai
- Go to maton.ai/settings
- Copy your API key
Connection Management
Manage your Telegram bot connections at https://ctrl.maton.ai.
List Connections
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=telegram&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Create Connection
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'telegram'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Get Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=telegram&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'telegram'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Get Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Response:
{
"connection": {
"connection_id": "e8f5078d-e507-4139-aabe-1615181ea8fc",
"status": "ACTIVE",
"creation_time": "2026-02-07T10:37:21.053942Z",
"last_updated_time": "2026-02-07T10:37:59.881901Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "telegram",
"metadata": {}
}
}
Open the returned url in a browser to complete the bot token configuration.
Delete Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Specifying Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
If you have multiple Telegram connections (multiple bots), specify which one to use with the Maton-Connection header:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/telegram/:token/getMe')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', 'e8f5078d-e507-4139-aabe-1615181ea8fc')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
If omitted, the gateway uses the default (oldest) active connection.
API Reference
Bot Information
Get Bot Info
GET /telegram/:token/getMe
GET /telegram/:token/getMe
Returns information about the bot.
Response:
{
"ok": true,
"result": {
"id": 8523474253,
"is_bot": true,
"first_name": "Maton",
"username": "maton_bot",
"can_join_groups": true,
"can_read_all_group_messages": true,
"supports_inline_queries": true
}
}
Getting Updates
Get Updates (Long Polling)
POST /telegram/:token/getUpdates
Content-Type: application/json
{
"limit": 100,
"timeout": 30,
"offset": 625435210
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| offset | Integer | No | First update ID to return |
| limit | Integer | No | Number of updates (1-100, default 100) |
| timeout | Integer | No | Long polling timeout in seconds |
| allowed_updates | Array | No | Update types to receive |
Get Webhook Info
GET /telegram/:token/getWebhookInfo
Set Webhook
POST /telegram/:token/setWebhook
Content-Type: application/json
{
"url": "https://example.com/webhook",
"allowed_updates": ["message", "callback_query"],
"secret_token": "your_secret_token"
}
Delete Webhook
POST /telegram/:token/deleteWebhook
Content-Type: application/json
{
"drop_pending_updates": true
}
Sending Messages
Send Text Message
POST /telegram/:token/sendMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"text": "Hello, World!",
"parse_mode": "HTML"
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID or @username
text
String
Yes
Message text (1-4096 characters)
parse_mode
String
No
HTML, Markdown, or MarkdownV2
reply_markup
Object
No
Inline keyboard or reply keyboard
reply_parameters
Object
No
Reply to a specific message
GET /telegram/:token/getWebhookInfo
POST /telegram/:token/setWebhook
Content-Type: application/json
{
"url": "https://example.com/webhook",
"allowed_updates": ["message", "callback_query"],
"secret_token": "your_secret_token"
}
Delete Webhook
POST /telegram/:token/deleteWebhook
Content-Type: application/json
{
"drop_pending_updates": true
}
Sending Messages
Send Text Message
POST /telegram/:token/sendMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"text": "Hello, World!",
"parse_mode": "HTML"
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID or @username
text
String
Yes
Message text (1-4096 characters)
parse_mode
String
No
HTML, Markdown, or MarkdownV2
reply_markup
Object
No
Inline keyboard or reply keyboard
reply_parameters
Object
No
Reply to a specific message
POST /telegram/:token/deleteWebhook
Content-Type: application/json
{
"drop_pending_updates": true
}
Send Text Message
POST /telegram/:token/sendMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"text": "Hello, World!",
"parse_mode": "HTML"
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Target chat ID or @username |
| text | String | Yes | Message text (1-4096 characters) |
| parse_mode | String | No | HTML, Markdown, or MarkdownV2 |
| reply_markup | Object | No | Inline keyboard or reply keyboard |
| reply_parameters | Object | No | Reply to a specific message |
With HTML Formatting:
POST /telegram/:token/sendMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"text": "<b>Bold</b> and <i>italic</i> with <a href=\"https://example.com\">link</a>",
"parse_mode": "HTML"
}
With Inline Keyboard:
POST /telegram/:token/sendMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"text": "Choose an option:",
"reply_markup": {
"inline_keyboard": [
[
{"text": "Option 1", "callback_data": "opt1"},
{"text": "Option 2", "callback_data": "opt2"}
],
[
{"text": "Visit Website", "url": "https://example.com"}
]
]
}
}
Send Photo
POST /telegram/:token/sendPhoto
Content-Type: application/json
{
"chat_id": 6442870329,
"photo": "https://example.com/image.jpg",
"caption": "Image caption"
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID
photo
String
Yes
Photo URL or file_id
caption
String
No
Caption (0-1024 characters)
parse_mode
String
No
Caption parse mode
Send Document
POST /telegram/:token/sendDocument
Content-Type: application/json
{
"chat_id": 6442870329,
"document": "https://example.com/file.pdf",
"caption": "Document caption"
}
Send Video
POST /telegram/:token/sendVideo
Content-Type: application/json
{
"chat_id": 6442870329,
"video": "https://example.com/video.mp4",
"caption": "Video caption"
}
Send Audio
POST /telegram/:token/sendAudio
Content-Type: application/json
{
"chat_id": 6442870329,
"audio": "https://example.com/audio.mp3",
"caption": "Audio caption"
}
Send Location
POST /telegram/:token/sendLocation
Content-Type: application/json
{
"chat_id": 6442870329,
"latitude": 37.7749,
"longitude": -122.4194
}
Send Contact
POST /telegram/:token/sendContact
Content-Type: application/json
{
"chat_id": 6442870329,
"phone_number": "+1234567890",
"first_name": "John",
"last_name": "Doe"
}
Send Poll
POST /telegram/:token/sendPoll
Content-Type: application/json
{
"chat_id": 6442870329,
"question": "What is your favorite color?",
"options": [
{"text": "Red"},
{"text": "Blue"},
{"text": "Green"}
],
"is_anonymous": false
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID
question
String
Yes
Poll question (1-300 characters)
options
Array
Yes
Poll options (2-10 items)
is_anonymous
Boolean
No
Anonymous poll (default true)
type
String
No
regular or quiz
allows_multiple_answers
Boolean
No
Allow multiple answers
correct_option_id
Integer
No
Correct answer for quiz
Send Dice
POST /telegram/:token/sendDice
Content-Type: application/json
{
"chat_id": 6442870329,
"emoji": "🎲"
}
POST /telegram/:token/sendPhoto
Content-Type: application/json
{
"chat_id": 6442870329,
"photo": "https://example.com/image.jpg",
"caption": "Image caption"
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Target chat ID |
| photo | String | Yes | Photo URL or file_id |
| caption | String | No | Caption (0-1024 characters) |
| parse_mode | String | No | Caption parse mode |
POST /telegram/:token/sendDocument
Content-Type: application/json
{
"chat_id": 6442870329,
"document": "https://example.com/file.pdf",
"caption": "Document caption"
}
Send Video
POST /telegram/:token/sendVideo
Content-Type: application/json
{
"chat_id": 6442870329,
"video": "https://example.com/video.mp4",
"caption": "Video caption"
}
Send Audio
POST /telegram/:token/sendAudio
Content-Type: application/json
{
"chat_id": 6442870329,
"audio": "https://example.com/audio.mp3",
"caption": "Audio caption"
}
Send Location
POST /telegram/:token/sendLocation
Content-Type: application/json
{
"chat_id": 6442870329,
"latitude": 37.7749,
"longitude": -122.4194
}
Send Contact
POST /telegram/:token/sendContact
Content-Type: application/json
{
"chat_id": 6442870329,
"phone_number": "+1234567890",
"first_name": "John",
"last_name": "Doe"
}
Send Poll
POST /telegram/:token/sendPoll
Content-Type: application/json
{
"chat_id": 6442870329,
"question": "What is your favorite color?",
"options": [
{"text": "Red"},
{"text": "Blue"},
{"text": "Green"}
],
"is_anonymous": false
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID
question
String
Yes
Poll question (1-300 characters)
options
Array
Yes
Poll options (2-10 items)
is_anonymous
Boolean
No
Anonymous poll (default true)
type
String
No
regular or quiz
allows_multiple_answers
Boolean
No
Allow multiple answers
correct_option_id
Integer
No
Correct answer for quiz
Send Dice
POST /telegram/:token/sendDice
Content-Type: application/json
{
"chat_id": 6442870329,
"emoji": "🎲"
}
POST /telegram/:token/sendVideo
Content-Type: application/json
{
"chat_id": 6442870329,
"video": "https://example.com/video.mp4",
"caption": "Video caption"
}
POST /telegram/:token/sendAudio
Content-Type: application/json
{
"chat_id": 6442870329,
"audio": "https://example.com/audio.mp3",
"caption": "Audio caption"
}
Send Location
POST /telegram/:token/sendLocation
Content-Type: application/json
{
"chat_id": 6442870329,
"latitude": 37.7749,
"longitude": -122.4194
}
Send Contact
POST /telegram/:token/sendContact
Content-Type: application/json
{
"chat_id": 6442870329,
"phone_number": "+1234567890",
"first_name": "John",
"last_name": "Doe"
}
Send Poll
POST /telegram/:token/sendPoll
Content-Type: application/json
{
"chat_id": 6442870329,
"question": "What is your favorite color?",
"options": [
{"text": "Red"},
{"text": "Blue"},
{"text": "Green"}
],
"is_anonymous": false
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID
question
String
Yes
Poll question (1-300 characters)
options
Array
Yes
Poll options (2-10 items)
is_anonymous
Boolean
No
Anonymous poll (default true)
type
String
No
regular or quiz
allows_multiple_answers
Boolean
No
Allow multiple answers
correct_option_id
Integer
No
Correct answer for quiz
Send Dice
POST /telegram/:token/sendDice
Content-Type: application/json
{
"chat_id": 6442870329,
"emoji": "🎲"
}
POST /telegram/:token/sendLocation
Content-Type: application/json
{
"chat_id": 6442870329,
"latitude": 37.7749,
"longitude": -122.4194
}
POST /telegram/:token/sendContact
Content-Type: application/json
{
"chat_id": 6442870329,
"phone_number": "+1234567890",
"first_name": "John",
"last_name": "Doe"
}
Send Poll
POST /telegram/:token/sendPoll
Content-Type: application/json
{
"chat_id": 6442870329,
"question": "What is your favorite color?",
"options": [
{"text": "Red"},
{"text": "Blue"},
{"text": "Green"}
],
"is_anonymous": false
}
Parameter
Type
Required
Description
chat_id
Integer/String
Yes
Target chat ID
question
String
Yes
Poll question (1-300 characters)
options
Array
Yes
Poll options (2-10 items)
is_anonymous
Boolean
No
Anonymous poll (default true)
type
String
No
regular or quiz
allows_multiple_answers
Boolean
No
Allow multiple answers
correct_option_id
Integer
No
Correct answer for quiz
Send Dice
POST /telegram/:token/sendDice
Content-Type: application/json
{
"chat_id": 6442870329,
"emoji": "🎲"
}
POST /telegram/:token/sendPoll
Content-Type: application/json
{
"chat_id": 6442870329,
"question": "What is your favorite color?",
"options": [
{"text": "Red"},
{"text": "Blue"},
{"text": "Green"}
],
"is_anonymous": false
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Target chat ID |
| question | String | Yes | Poll question (1-300 characters) |
| options | Array | Yes | Poll options (2-10 items) |
| is_anonymous | Boolean | No | Anonymous poll (default true) |
| type | String | No | regular or quiz |
| allows_multiple_answers | Boolean | No | Allow multiple answers |
| correct_option_id | Integer | No | Correct answer for quiz |
POST /telegram/:token/sendDice
Content-Type: application/json
{
"chat_id": 6442870329,
"emoji": "🎲"
}
Supported emoji: 🎲 🎯 🎳 🏀 ⚽ 🎰
Editing Messages
Edit Message Text
POST /telegram/:token/editMessageText
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123,
"text": "Updated message text"
}
Edit Message Caption
POST /telegram/:token/editMessageCaption
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123,
"caption": "Updated caption"
}
Edit Message Reply Markup
POST /telegram/:token/editMessageReplyMarkup
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123,
"reply_markup": {
"inline_keyboard": [
[{"text": "New Button", "callback_data": "new"}]
]
}
}
Delete Message
POST /telegram/:token/deleteMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123
}
Forwarding & Copying
Forward Message
POST /telegram/:token/forwardMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
Copy Message
POST /telegram/:token/copyMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
Chat Information
Get Chat
POST /telegram/:token/getChat
Content-Type: application/json
{
"chat_id": 6442870329
}
Get Chat Administrators
POST /telegram/:token/getChatAdministrators
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member Count
POST /telegram/:token/getChatMemberCount
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member
POST /telegram/:token/getChatMember
Content-Type: application/json
{
"chat_id": -1001234567890,
"user_id": 6442870329
}
Bot Commands
Set My Commands
POST /telegram/:token/setMyCommands
Content-Type: application/json
{
"commands": [
{"command": "start", "description": "Start the bot"},
{"command": "help", "description": "Get help"},
{"command": "settings", "description": "Open settings"}
]
}
Get My Commands
GET /telegram/:token/getMyCommands
Delete My Commands
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Bot Profile
Get My Description
GET /telegram/:token/getMyDescription
Set My Description
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/editMessageCaption
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123,
"caption": "Updated caption"
}
POST /telegram/:token/editMessageReplyMarkup
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123,
"reply_markup": {
"inline_keyboard": [
[{"text": "New Button", "callback_data": "new"}]
]
}
}
Delete Message
POST /telegram/:token/deleteMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123
}
Forwarding & Copying
Forward Message
POST /telegram/:token/forwardMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
Copy Message
POST /telegram/:token/copyMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
Chat Information
Get Chat
POST /telegram/:token/getChat
Content-Type: application/json
{
"chat_id": 6442870329
}
Get Chat Administrators
POST /telegram/:token/getChatAdministrators
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member Count
POST /telegram/:token/getChatMemberCount
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member
POST /telegram/:token/getChatMember
Content-Type: application/json
{
"chat_id": -1001234567890,
"user_id": 6442870329
}
Bot Commands
Set My Commands
POST /telegram/:token/setMyCommands
Content-Type: application/json
{
"commands": [
{"command": "start", "description": "Start the bot"},
{"command": "help", "description": "Get help"},
{"command": "settings", "description": "Open settings"}
]
}
Get My Commands
GET /telegram/:token/getMyCommands
Delete My Commands
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Bot Profile
Get My Description
GET /telegram/:token/getMyDescription
Set My Description
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/deleteMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"message_id": 123
}
Forward Message
POST /telegram/:token/forwardMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
POST /telegram/:token/copyMessage
Content-Type: application/json
{
"chat_id": 6442870329,
"from_chat_id": 6442870329,
"message_id": 123
}
Chat Information
Get Chat
POST /telegram/:token/getChat
Content-Type: application/json
{
"chat_id": 6442870329
}
Get Chat Administrators
POST /telegram/:token/getChatAdministrators
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member Count
POST /telegram/:token/getChatMemberCount
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member
POST /telegram/:token/getChatMember
Content-Type: application/json
{
"chat_id": -1001234567890,
"user_id": 6442870329
}
Bot Commands
Set My Commands
POST /telegram/:token/setMyCommands
Content-Type: application/json
{
"commands": [
{"command": "start", "description": "Start the bot"},
{"command": "help", "description": "Get help"},
{"command": "settings", "description": "Open settings"}
]
}
Get My Commands
GET /telegram/:token/getMyCommands
Delete My Commands
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Bot Profile
Get My Description
GET /telegram/:token/getMyDescription
Set My Description
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/getChatAdministrators
Content-Type: application/json
{
"chat_id": -1001234567890
}
POST /telegram/:token/getChatMemberCount
Content-Type: application/json
{
"chat_id": -1001234567890
}
Get Chat Member
POST /telegram/:token/getChatMember
Content-Type: application/json
{
"chat_id": -1001234567890,
"user_id": 6442870329
}
Bot Commands
Set My Commands
POST /telegram/:token/setMyCommands
Content-Type: application/json
{
"commands": [
{"command": "start", "description": "Start the bot"},
{"command": "help", "description": "Get help"},
{"command": "settings", "description": "Open settings"}
]
}
Get My Commands
GET /telegram/:token/getMyCommands
Delete My Commands
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Bot Profile
Get My Description
GET /telegram/:token/getMyDescription
Set My Description
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/getChatMember
Content-Type: application/json
{
"chat_id": -1001234567890,
"user_id": 6442870329
}
Set My Commands
POST /telegram/:token/setMyCommands
Content-Type: application/json
{
"commands": [
{"command": "start", "description": "Start the bot"},
{"command": "help", "description": "Get help"},
{"command": "settings", "description": "Open settings"}
]
}
GET /telegram/:token/getMyCommands
Delete My Commands
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Bot Profile
Get My Description
GET /telegram/:token/getMyDescription
Set My Description
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/deleteMyCommands
Content-Type: application/json
{}
Get My Description
GET /telegram/:token/getMyDescription
POST /telegram/:token/setMyDescription
Content-Type: application/json
{
"description": "This bot helps you manage tasks."
}
Set My Name
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Files
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
POST /telegram/:token/setMyName
Content-Type: application/json
{
"name": "Task Bot"
}
Get File
POST /telegram/:token/getFile
Content-Type: application/json
{
"file_id": "AgACAgQAAxkDAAM..."
}
Response:
{
"ok": true,
"result": {
"file_id": "AgACAgQAAxkDAAM...",
"file_unique_id": "AQAD27ExGysnfVBy",
"file_size": 7551,
"file_path": "photos/file_0.jpg"
}
}
Download files from: https://api.telegram.org/file/bot<token>/<file_path>
Callback Queries
Answer Callback Query
POST /telegram/:token/answerCallbackQuery
Content-Type: application/json
{
"callback_query_id": "12345678901234567",
"text": "Button clicked!",
"show_alert": false
}
Code Examples
JavaScript
// Send a message
const response = await fetch(
'https://gateway.maton.ai/telegram/:token/sendMessage',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
chat_id: 6442870329,
text: 'Hello from JavaScript!'
})
}
);
const data = await response.json();
console.log(data);
Python
import os
import requests
# Send a message
response = requests.post(
'https://gateway.maton.ai/telegram/:token/sendMessage',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
json={
'chat_id': 6442870329,
'text': 'Hello from Python!'
}
)
print(response.json())
Python (urllib)
import urllib.request, os, json
data = json.dumps({
'chat_id': 6442870329,
'text': 'Hello from Python!'
}).encode()
req = urllib.request.Request(
'https://gateway.maton.ai/telegram/:token/sendMessage',
data=data,
method='POST'
)
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
response = json.load(urllib.request.urlopen(req))
print(json.dumps(response, indent=2))
Response Format
import os
import requests
# Send a message
response = requests.post(
'https://gateway.maton.ai/telegram/:token/sendMessage',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
json={
'chat_id': 6442870329,
'text': 'Hello from Python!'
}
)
print(response.json())
import urllib.request, os, json
data = json.dumps({
'chat_id': 6442870329,
'text': 'Hello from Python!'
}).encode()
req = urllib.request.Request(
'https://gateway.maton.ai/telegram/:token/sendMessage',
data=data,
method='POST'
)
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
response = json.load(urllib.request.urlopen(req))
print(json.dumps(response, indent=2))
Response Format
All Telegram Bot API responses follow this format:
Success:
{
"ok": true,
"result": { ... }
}
Error:
{
"ok": false,
"error_code": 400,
"description": "Bad Request: chat not found"
}
Notes
:token is automatically replaced with your bot token from the connection
- Chat IDs are integers for private chats and can be negative for groups
- All methods support both GET and POST, but POST is recommended for methods with parameters
- Text messages have a 4096 character limit
- Captions have a 1024 character limit
- Polls support 2-10 options
- File uploads require multipart/form-data (use URLs for simplicity)
- IMPORTANT: When piping curl output to
jq or other commands, environment variables like $MATON_API_KEY may not expand correctly in some shell environments
Error Handling
Status
Meaning
400
Missing Telegram connection or bad request
401
Invalid or missing Maton API key
429
Rate limited (Telegram limits vary by method)
4xx/5xx
Passthrough error from Telegram Bot API
Troubleshooting: API Key Issues
- Check that the
MATON_API_KEY environment variable is set:
echo $MATON_API_KEY
- Verify the API key is valid by listing connections:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Troubleshooting: Invalid App Name
:token is automatically replaced with your bot token from the connectionjq or other commands, environment variables like $MATON_API_KEY may not expand correctly in some shell environments| Status | Meaning |
|---|---|
| 400 | Missing Telegram connection or bad request |
| 401 | Invalid or missing Maton API key |
| 429 | Rate limited (Telegram limits vary by method) |
| 4xx/5xx | Passthrough error from Telegram Bot API |
Troubleshooting: API Key Issues
MATON_API_KEY environment variable is set:echo $MATON_API_KEY
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
- Ensure your URL path starts with
telegram. For example:
- Correct:
https://gateway.maton.ai/telegram/:token/sendMessage - Incorrect:
https://gateway.maton.ai/:token/sendMessage
Resources
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。