获取频道Chat ID
具体的操作步骤如下:
1. 将机器人添加为频道管理员
2. 在频道发布任意消息
3. 访问相同API接口获取更新:https://api.telegram.org/bot{our_bot_token}/getUpdates
4. 在返回数据中查找:
{
"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(注意包含 -100前缀)
6. 测试频道消息发送
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-1001xxxxxx062&text=test123
7. 当我们正确设置了机器人令牌(bot token)和聊天 ID(chat ID)后,消息 “test123” 应该会发送到我们的 Telegram 频道中。