文档

Telegram Bot

试用

通过托管鉴权网关调用 Telegram Bot API,实现消息发送、投票、指令管理与更新处理。

它能做什么

通过托管鉴权的方式接入 Telegram Bot API,机器人 Token 保存在连接配置中,无需在每次请求里手填。支持发送文字消息(可使用 HTML/Markdown 格式与内联键盘)、图片、文档、音视频、位置、联系人、投票(含 quiz)、骰子表情消息;编辑、删除、转发或复制消息;查询 Chat 信息、管理员列表、成员数与单个成员;配置 Webhook、注册并维护斜杠指令菜单;以及读写机器人资料。可在同一账号下维护多个机器人连接,通过请求头切换目标连接。所有访问限定在已连接的 Telegram Bot API 账户范围内,任何写操作(create/update/delete)均需用户明确确认。

什么时候用它

  • 向指定 Chat 发送带内联键盘的格式化消息
  • 在 Telegram 群里发起投票或测验
  • 配置或替换机器人的 Webhook
  • 注册或更新机器人的斜杠指令菜单

技能文档

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://api.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://api.maton.ai/telegram/:token/{method}

The :token placeholder is automatically replaced with your bot token from the connection configuration. The {method} is 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

  1. Sign in or create an account at maton.ai
  2. Go to maton.ai/settings
  3. Copy your API key

Connection Management

Manage your Telegram bot connections at https://api.maton.ai.

List Connections

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.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://api.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://api.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": "{connection_id}",
    "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://api.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

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://api.maton.ai/telegram/:token/getMe')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '{connection_id}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

If you have multiple connections, always include this header to ensure requests go to the intended account.

Security & Permissions

  • Access is scoped to messages, chats, media, and bot commands within the connected Telegram Bot API account.
  • All write operations require explicit user approval. Before executing any create, update, or delete call, confirm the target resource and intended effect with the user.

API Reference

Bot Information

Get Bot Info

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
}
ParameterTypeRequiredDescription
offsetIntegerNoFirst update ID to return
limitIntegerNoNumber of updates (1-100, default 100)
timeoutIntegerNoLong polling timeout in seconds
allowed_updatesArrayNoUpdate 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"
}
ParameterTypeRequiredDescription
chat_idInteger/StringYesTarget chat ID or @username
textStringYesMessage text (1-4096 characters)
parse_modeStringNoHTML, Markdown, or MarkdownV2
reply_markupObjectNoInline keyboard or reply keyboard
reply_parametersObjectNoReply to a specific message

With HTML Formatting:

POST /telegram/:token/sendMessage
Content-Type: application/json

{
  "chat_id": 6442870329,
  "text": "Bold and italic with link",
  "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"
}
ParameterTypeRequiredDescription
chat_idInteger/StringYesTarget chat ID
photoStringYesPhoto URL or file_id
captionStringNoCaption (0-1024 characters)
parse_modeStringNoCaption 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
}
ParameterTypeRequiredDescription
chat_idInteger/StringYesTarget chat ID
questionStringYesPoll question (1-300 characters)
optionsArrayYesPoll options (2-10 items)
is_anonymousBooleanNoAnonymous poll (default true)
typeStringNoregular or quiz
allows_multiple_answersBooleanNoAllow multiple answers
correct_option_idIntegerNoCorrect answer for quiz

Send Dice

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..."
}

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/

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://api.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://api.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://api.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

StatusMeaning
400Missing Telegram connection or bad request
401Invalid or missing Maton API key
429Rate limited (Telegram limits vary by method)
4xx/5xxPassthrough error from Telegram Bot API

Troubleshooting: API Key Issues

  1. Check that the MATON_API_KEY environment variable is set:
echo $MATON_API_KEY
  1. Verify the API key is valid by listing connections:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.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

  1. Ensure your URL path starts with telegram. For example:
  • Correct: https://api.maton.ai/telegram/:token/sendMessage
  • Incorrect: https://api.maton.ai/:token/sendMessage

Resources

常见问题

机器人 Token 是如何管理的?
Token 保存在服务端的连接配置中,请求地址里的 :token 占位符会自动替换;调用方只需使用 Bearer Token 鉴权,无需在每次请求里粘贴机器人密钥。
能否同时管理多个机器人?
可以。同一账户下支持多个 Telegram 连接,每次请求通过 Maton-Connection 请求头指定目标连接即可路由到对应机器人。
写操作会自动执行吗?
不会。任何 create、update、delete 调用都需要用户明确确认后才能执行,且访问范围仅限已连接账户内的消息、聊天、媒体与机器人指令。

相关技能

Telegram Bot (core.telegram.org). Use this skill for ANY Telegram Bot request — reading, creating, updating, and deleting data. Whenever a task involves Telegram Bot, use this skill instead of calling the API directly.

8 次安装

通过托管 OAuth 代理调用 Slack API,实现发消息、管频道、列用户和定时投递。

249 次安装7 星标

通过 OAuth 代理调用 Twilio API,完成短信发送、语音外呼与电话号资源管理。

作者 byungkyu173 次安装8 星标

通过托管 OAuth 的代理调用 WhatsApp Business API,发送消息、管理模板与媒体。

758 次安装60 星标

通过统一鉴权的接口管理 ManyChat 订阅者、标签、自定义字段和 Messenger 消息发送。

152 次安装3 星标

通过单一 API 密钥调用 WATI API,完成 WhatsApp 消息收发与联系人管理。

25 次安装1 星标