我正在尝试使用新的“reply_parameters”方法回复 Telegram 中的消息,但由于某种原因,该消息在发送时没有回复前一条消息。但是,如果我使用“reply_to_message_id”方法,一切正常。
<?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);
}
如何让“reply_parameters”回复消息?
'reply_parameters' => json_encode(['message_id' => $messageId, 'chat_id' => $chat_id])