> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.omegatheme.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How

# 创建 Telegram 机器人并获取 Bot Token

1. 打开 Telegram 应用，搜索 `@BotFather`  
2. 点击 **Start**  
3. 点击 **Menu -> /newbot** 或直接输入 `/newbot` 并发送  
4. 按提示操作，直到收到如下信息：
5. 我们的 Bot Token 就是：`63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c`（**请务必不要分享给任何人**）



# 获取私聊 Chat ID

1. 搜索并打开我们新创建的 Telegram 机器人  
2. 点击 **Start** 或发送一条消息  
3. 在浏览器中打开：  
   `https://api.telegram.org/bot{our_bot_token}/getUpdates`  
* 注意：Token 前需加上 `bot` 前缀  
* 例如：`https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates`
4. 将会看到类似如下的 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"
}
}
]
}
5. 查看 `result.0.message.chat.id`，这里的 Chat ID 是：`21xxxxx38`  
6. 测试发送消息：  
   `https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=21xxxxx38&text=test123`  
7. 如果 Bot Token 和 Chat ID 正确，消息 `test123` 会出现在机器人私聊中。



# 获取频道 Chat ID

1. 将机器人添加到频道  
2. 在频道中发送一条消息  
3. 打开：`https://api.telegram.org/bot{our_bot_token}/getUpdates`  
4. 会看到类似的 JSON：
{
"ok": true,
"result": [
{
"update_id": 838xxxx36,
"channel_post": {...},
"chat": {
"id": -1001xxxxxx062,
"title": "....",
"type": "channel"
},
"date": 1703065989,
"text": "test"
}
}
]
}
5. 查看 `result.0.channel_post.chat.id`，这里的 Chat ID 是：`-1001xxxxxx062`  
6. 测试发送消息：  
   `https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-1001xxxxxx062&text=test123`  
7. 如果设置正确，`test123` 将出现在频道中。



# 获取群聊 Chat ID

最简单的方法是使用 Telegram 桌面版。

1. 在桌面版中打开 Telegram  
2. 将机器人添加到群聊  
3. 在群聊中发送一条消息  
4. 右键消息并点击 **复制消息链接**  
* 链接示例：`https://t.me/c/194xxxx987/11/13`  
* 格式：`https://t.me/c/{group_chat_id}/{group_topic_id}/{message_id}`  
* 群聊 ID 就是：`194xxxx987`
5. 使用 API 时需要在群聊 ID 前加 `-100` 前缀：`-100194xxxx987`  
6. 测试发送消息：  
   `https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-100194xxxx987&text=test123`  
7. 如果设置正确，`test123` 将出现在群聊中。



# 获取群聊话题（Topic）ID

如果要向群聊中的特定话题发送消息，需要获取话题 ID。

1. 与上一步类似，复制消息链接，如：`https://t.me/c/194xxxx987/11/13`  
* 此处 `11` 就是 **话题 ID**  
2. 发送消息示例（使用 `message_thread_id` 参数）：  
   `https://api.telegram.org/bot783114779:AAEuRWDTFD2UQ7agBtFSuhJf2-NmvHN3OPc/sendMessage?chat_id=-100194xxxx987&message_thread_id=11&text=test123`  
3. 如果设置正确，`test123` 将出现在对应话题中。
