2

在电报机器人中通过发送消息方法发送消息时,有一种简单的方法可以禁用通知。但是,我们如何在使用 reply_markup 选项时禁用通知?

例如 ,

$url = "$website/sendMessage?chat_id=$chat_id&text=$text&    disable_notification=true";
file_get_contents($url);  // It works perfect`

但 ,

$keyboard =      [['text' => $text]];
$replymarkup =   [   
    'keyboard' => $keyboard ,
    'resize_keyboard' => true ,
    'one_time_keyboard' => true 
];
$encodemarkup = json_encode($replymarkup);
$welcome = $text;
$url = "$website/sendmessage?chat_id=$chat_id&text=$welcome&    disable_notification=true&reply_markup=$encodemarkup";
file_get_contents($url); //It does not mute notification
4

1 回答 1

0

您应该使用 POST 请求而不是 GET 请求发送数据。

尝试在单个 json 对象中发送所有内容:

$datatosend=[
    'chat_id'=> $myChatId,
    'text'=> $myText,
    'parse_mode' => 'Markdown',
    'disable_notification' => 'true',
    'inline_keyboard' => $inline_keyboard
];

$ch = curl_init($url . '/sendMessage');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($datatosend));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($ch, CURLOPT_ENCODING,  '');

$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
于 2019-01-03T09:35:04.927 回答