How
创建 Telegram 机器人并获取 Bot Token
- 打开 Telegram 应用,搜索
@BotFather
- 点击 Start
- 点击 Menu -> /newbot 或直接输入
/newbot
并发送 - 按提示操作,直到收到如下信息:
- 我们的 Bot Token 就是:
63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c
(请务必不要分享给任何人)
获取私聊 Chat ID
- 搜索并打开我们新创建的 Telegram 机器人
- 点击 Start 或发送一条消息
- 在浏览器中打开:
https://api.telegram.org/bot{our_bot_token}/getUpdates
- 注意:Token 前需加上
bot
前缀 - 例如:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates
- 将会看到类似如下的 JSON:
{
"ok": true,
"result": [
{
"update_id": 83xxxxx35,
"message": {
"message_id": 2643,
"from": {...},
"chat": {
"id": 21xxxxx38,
"first_name": "...",
"last_name": "...",
"username": "@username",
"type": "private"
},
"date": 1703062972,
"text": "/start"
}
}
]
}
- 查看
result.0.message.chat.id
,这里的 Chat ID 是:21xxxxx38
- 测试发送消息:
- 如果 Bot Token 和 Chat ID 正确,消息
test123
会出现在机器人私聊中。
获取频道 Chat ID
- 将机器人添加到频道
- 在频道中发送一条消息
- 打开:
https://api.telegram.org/bot{our_bot_token}/getUpdates
- 会看到类似的 JSON:
{
"ok": true,
"result": [
{
"update_id": 838xxxx36,
"channel_post": {...},
"chat": {
"id": -1001xxxxxx062,
"title": "....",
"type": "channel"
},
"date": 1703065989,
"text": "test"
}
}
]
}
- 查看
result.0.channel_post.chat.id
,这里的 Chat ID 是:-1001xxxxxx062
- 测试发送消息:
- 如果设置正确,
test123
将出现在频道中。
获取群聊 Chat ID
最简单的方法是使用 Telegram 桌面版。
- 在桌面版中打开 Telegram
- 将机器人添加到群聊
- 在群聊中发送一条消息
- 右键消息并点击 复制消息链接
- 链接示例:
https://t.me/c/194xxxx987/11/13
- 格式:
https://t.me/c/{group_chat_id}/{group_topic_id}/{message_id}
- 群聊 ID 就是:
194xxxx987
- 使用 API 时需要在群聊 ID 前加
-100
前缀:-100194xxxx987
- 测试发送消息:
- 如果设置正确,
test123
将出现在群聊中。
获取群聊话题(Topic)ID
如果要向群聊中的特定话题发送消息,需要获取话题 ID。
- 与上一步类似,复制消息链接,如:
https://t.me/c/194xxxx987/11/13
- 此处
11
就是 话题 ID
- 发送消息示例(使用
message_thread_id
参数):
- 如果设置正确,
test123
将出现在对应话题中。
更新于: 11/08/2025
谢谢!