我正在使用我的机器人来讲述重要新闻,但是当我使用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"}
在更改日志中,他们提到无法通过客户端向通道发送消息,但是另一种方法是什么?
那么,问题是,如何将我的机器人添加到频道中?
这就是我将机器人添加到我的频道并设置通知的方式:
telegram.me/whateverIWantAndAvailable _
频道 ID 将是 @whateverIWantAndAvailable
现在设置您的机器人通过在此处推送消息来发送通知:
https://api.telegram.org/botTOKENOFTHEBOT/sendMessage?chat_id= @whateverIWantAndAvailable &text=测试
机器人将通知的消息是:测试
我强烈建议像这样的消息的 urlencode
https://api.telegram.org/botTOKENOFTHEBOT/sendMessage?chat_id= @whateverIWantAndAvailable &text= Testing%20if%20this%20works
在 php 中你可以使用 urlencode("Test if this works"); 在 js 中你可以编码URIComponent("Test if this works");
我希望它有帮助
您是否使用正确的 chat_id 并在地址中的“bot”之后包含您的 bot 令牌?(api.telegram.org/bot令牌/sendMessage)
这个页面解释了一些关于发送的事情(在“sendMessage”部分)——基本的东西,但我经常忘记基础知识。
去引用:
为了使用 sendMessage 方法,我们需要使用正确的 chat_id。
首先,让我们通过 Telegram 客户端向我们的机器人发送 /start 命令。
发送此命令后,让我们执行 getUpdates 命令。
curl -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 是之前保存的信息。
我希望这会有所帮助。