phptelegram-botphp-telegram-bot

The new method 'reply_parameters' is not working


I'm trying to respond to a message in Telegram using the new "reply_parameters" method, but for some reason, the message is sent without a reply to the previous one. However, if I use the "reply_to_message_id" method, everything works fine.

<?php
 
    //set Variables
    define('BOT_URL', 'https://api.telegram.org/bot');
    define('BOT_TOKEN', '');
    $url = BOT_URL . BOT_TOKEN;
 
    //Get updates
    $content = file_get_contents("php://input");
    $update = json_decode($content, true);
 
    if (isset($update['message']['text'])) {
        $message = $update['message']['text'];
        $messageId = $update['message']['message_id'];
        $chat_id = $update['message']['chat']['id'];
        $threadId = $update['message']['message_thread_id'];
        $username = $update['message']['from']['username'];
 
        switch ($message) {
            case "/start":
                sendMessage($chat_id, $messageId, "Hi, {$username}", $threadId);
        }
    }
 
    function sendRequest($method, $arr = []) {
        global $url;
 
        $ch = curl_init();
        $options = array(
            CURLOPT_URL => $url . $method,
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => http_build_query($arr),
            CURLOPT_RETURNTRANSFER => true
        );
        curl_setopt_array($ch, $options);
        $response = curl_exec($ch);
        curl_close($ch); 
 
        return $response;
    }
  
 
    function sendMessage($chat_id, $messageId, $message, $threadId) {
        global $url;
 
        $data = [
            'chat_id' => $chat_id,
            'text' => $message,
            'message_thread_id' => $threadId,
            'reply_parameters' => [
                'message_id' => $messageId,
                'chat_id' => $chat_id,
            ]
        ];
 
        sendRequest('/sendMessage', $data);
    }

How can I make 'reply_parameters' respond to a message?


Solution

  • All types used in the Bot API must be JSON objects. Accordingly, reply_parameters must be a JSON object, so wrapping the array in the json_encode() function will work.

    'reply_parameters' => json_encode(['message_id' => $messageId, 'chat_id' => $chat_id])