我正在使用机器人发布重要新闻,但是当我使用sendMessage
发送到频道时,我收到以下错误:
{"ok":false,"error_code":403,"description":"Error: Forbidden: bot is not a participant of the channel"}
在变更日志中提到客户端无法向频道发送消息,那么还有其他方法吗?
因此,问题是如何将我的机器人添加到频道中?
我正在使用机器人发布重要新闻,但是当我使用sendMessage
发送到频道时,我收到以下错误:
{"ok":false,"error_code":403,"description":"Error: Forbidden: bot is not a participant of the channel"}
在变更日志中提到客户端无法向频道发送消息,那么还有其他方法吗?
因此,问题是如何将我的机器人添加到频道中?
sendMessage
的结果应包含一个 chat_id
,在删除频道名称后可将其用于后续操作。请注意保持翻译内容与原文意思一致,同时使其更加通俗易懂。 - Johannes KuhnAdd Admin
按钮。如果我检查移动和桌面客户端,我确实可以找到Add Addmin
按钮。
请检查并相应更新您的答案,以便人们不需要像这样经历3个不同的Web客户端。 - francis duviviertelegram.me/任意想要且可用的名称
该频道的ID将为@任意想要且可用的名称
现在设置您的机器人发送通知消息:
https://api.telegram.org/bot机器人TOKEN/sendMessage?chat_id=@任意想要且可用的名称&text=测试
机器人将通知的消息是:测试
我强烈建议对消息进行urlencode处理,例如
https://api.telegram.org/bot机器人TOKEN/sendMessage?chat_id=@任意想要且可用的名称&text=测试%20是否有效
在PHP中,您可以使用urlencode("测试是否有效");在JavaScript中,您可以使用encodeURIComponent("测试是否有效");
希望这有所帮助。
webK alpha 0.9.1
和webZ alpha 1.22.3
版本。 - francis duviviercurl -s \
-X POST \ https://api.telegram.org/bot<token>/getUpdates \ | jq .
{ "result": [
{
"message": {
"text": "/start",
"date": 1435176541,
"chat": {
"username": "yourusername",
"first_name": "yourfirstname",
"id": 65535
},
"from": {
"username": "yourusername",
"first_name": "yourfirstname",
"id": 65535
},
"message_id": 1
},
"update_id": 714636917
} ], "ok": true }
我们感兴趣的是属性result.message [0] .chat.id,请将这个信息保存在其他地方。
请注意,这只是一个示例,您可能想设置一些自动化来处理这些信息。现在我们如何发送消息?很简单,让我们看看这个片段。
curl -s \
-X POST \ https://api.telegram.org/bot<token>/sendMessage \
-d text="A message from your bot" \
-d chat_id=65535 \ | jq .
其中chat_id是之前保存的信息。
希望这能有所帮助。