Telegram bot get get找不到chat找不到'当PHP中的消息转发时出错

发布于 2025-02-01 16:06:04 字数 2264 浏览 2 评论 0原文

我遇到的错误是:  糟糕的请求:找不到 当我想从机器人是管理员的组中转发一条消息时。

方案:

  • 一个名为@puccipruebas的公共小组,其中bot(@comitentesbot)与我一起是管理员(@fpucci)。
  • 测试用户(@fernandopucci)
  • i(@fpucci)和测试用户(@fernandopucci)先前已私下写给bot。

这个想法是,当成员在小组中写作时,机器人将信息转发给我。

当我在小组中写入例如  这是一条测试消息时,bot会收到此数据:

Array ( 
    [update_id] => 768460433 
    [message] => Array ( 
        [message_id] => 8 
        [from] => Array (
            [id] => 1026410801 
            [is_bot] => 
            [first_name] => ??????????????????????¸ ??? 
            [last_name] => ??????????????? 
            [username] => FPucci 
            [language_code] => es 
        ) 
        [chat] => Array ( 
            [id] => -1001511892400 
            [title] => PucciPruebas 
            [username] => PucciPublico 
            [type] => supergroup 
        ) 
        [date] => 1653597954 
        [text] => This is a test message 
    )
)

PHP中的代码是:

$tipo = $datain["message"]["chat"]["type"]; 
$chatid = $datain["message"]["chat"]["id"]; 
$msgid = $datain["message"]["message_id"]; 
$title = $datain["message"]["chat"]["title"];
if ("private"==$tipo || "PucciPruebas"==$title)
    Reenviar("@fpucci", $chatid, $msgid);

function Reenviar ($a_chat, $from_chat, $message){ 
    global $chatId, $comitentesapi; 
    $params=[ 
        'chat_id' => "$a_chat",
        'from_chat_id' => "$from_chat", 
        'message_id' => "$message", 
    ]; 
    $ch = curl_init("$comitentesapi/forwardMessage"); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($params)); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $result = curl_exec($ch);
    curl_close($ch);
}

那么,我缺少,忘记或做错了什么?

- - - - -编辑 - - - - 我在 curl_close($ ch)之后附加,以下行作为发送消息的其他方式,并获得相同的结果:

file_get_contents("$comitentesapi/forwardMessage?disable_notification=true&chat_id=$a_chat&from_chat_id=$from_chat&message_id=$message&parse_mode=HTML");

I am getting errors like: Bad Request: chat not found when I want to forward a message from a group where the bot is an administrator.

Scenario:

  • A public group called @PucciPruebas where the bot (@Comitentesbot) is an admin along with me (@fpucci).
  • A test user (@fernandoPucci)
  • I (@fpucci) and the test user (@fernandopucci) have previously written to the bot privately.

The idea is that when a member writes in the group, the bot forwards the message to me privately.

When I write in the group for example This is a test message, the bot receives this data:

Array ( 
    [update_id] => 768460433 
    [message] => Array ( 
        [message_id] => 8 
        [from] => Array (
            [id] => 1026410801 
            [is_bot] => 
            [first_name] => ??????????????????????¸ ??? 
            [last_name] => ??????????????? 
            [username] => FPucci 
            [language_code] => es 
        ) 
        [chat] => Array ( 
            [id] => -1001511892400 
            [title] => PucciPruebas 
            [username] => PucciPublico 
            [type] => supergroup 
        ) 
        [date] => 1653597954 
        [text] => This is a test message 
    )
)

The code in PHP is:

$tipo = $datain["message"]["chat"]["type"]; 
$chatid = $datain["message"]["chat"]["id"]; 
$msgid = $datain["message"]["message_id"]; 
$title = $datain["message"]["chat"]["title"];
if ("private"==$tipo || "PucciPruebas"==$title)
    Reenviar("@fpucci", $chatid, $msgid);

function Reenviar ($a_chat, $from_chat, $message){ 
    global $chatId, $comitentesapi; 
    $params=[ 
        'chat_id' => "$a_chat",
        'from_chat_id' => "$from_chat", 
        'message_id' => "$message", 
    ]; 
    $ch = curl_init("$comitentesapi/forwardMessage"); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($params)); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $result = curl_exec($ch);
    curl_close($ch);
}

So, what am I missing, forgetting, or doing wrong?

---------edit--------
I append after the curl_close($ch), the following line as other way to send the message, and get the same result:

file_get_contents("$comitentesapi/forwardMessage?disable_notification=true&chat_id=$a_chat&from_chat_id=$from_chat&message_id=$message&parse_mode=HTML");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文