【问题标题】:Telegram bot doesn't respond to messages in channel?Telegram bot 不响应频道中的消息?
【发布时间】:2016-10-01 17:56:43
【问题描述】:

我在电报中创建了一个频道,并添加了一个机器人作为频道的管理员。当我向频道发送消息时,机器人没有回答,为什么?

我可以使用 /sendmessage

发送消息

https://api.telegram.org/bot[key]/sendmessage?chat_id=@MyChannelID&text=This 文字是从机器人到频道。

我正在使用:https://github.com/Eleirbag89/TelegramBotPHP

这是一个简单的机器人测试代码:

 <?php 

include 'connection.php';
include("Telegram.php");
define('bot_id', '227493781:AAE2x0l3BRrjGN3S8wMVo9zOTYbbwr8');
$telegram = new Telegram(bot_id);

$text = $telegram->Text();
$chat_id = $telegram->ChatID();

if ($text == "call") {
    $content = array('chat_id' => $chat_id, 'text' => "This is test     message!!!");
    $telegram->sendMessage($content);   
 }

?>

【问题讨论】:

  • 您是否在@BotFather 中设置了/setprivacy?
  • 是的,我启用了隐私,机器人是频道的管理员之一。聊天机器人在群聊中有响应,但在频道中没有。

标签: php channel telegram-bot


【解决方案1】:

聊天机器人无法在频道中接收消息,您只能发送消息。

更新: 机器人现在可以从频道接收更新,如果它们被添加为管理员

【讨论】:

    【解决方案2】:

    您可以通过以下方式获取 chanell 中最后一条消息的信息:

    messageId = message[-1].message_id

    messageText = message[-1].text

    所有你想要的;)

    【讨论】:

      【解决方案3】:

      在收到消息后尝试记录消息,然后查看响应...

      我刚刚检查并能够让机器人响应频道中发送的命令(机器人是频道中的管理员)

      确保您将其发送到正确的频道,如果您使用频道 ID,它应该类似于 -1001254460186,如果您使用频道用户名,它应该以 @ 开头...

      【讨论】:

      • 欢迎来到 SO。这不是对已有两年多的原始问题的完整答案。请参阅stackoverflow.com/help/how-to-answer 获取指导。
      • 谢谢,请记住答案指南,因为我在相关问题部分的旁边看到了这个问题,我是否应该尝试回答“旧”的问题
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2017-08-07
      • 2017-11-28
      • 2021-04-06
      • 1970-01-01
      • 2021-06-11
      • 2021-11-28
      相关资源
      最近更新 更多