在PHP中使用回复键盘标记时禁用电报机器人的通知

时间:2017-07-11 16:50:26

标签: php php-telegram-bot

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

例如,

public class Field : Panel
    {
        static Field()
        {

        }

        protected override Size MeasureOverride(Size availableSize)
        {
            Size size = new Size(double.PositiveInfinity, double.PositiveInfinity);
            foreach (UIElement element in base.InternalChildren)
                element.Measure(size);
            return new Size();
        }

        protected override Size ArrangeOverride(Size arrangeSize)
        {
            foreach (UIElement element in InternalChildren)
            {
                Rect bounds = new Rect(new Point(0,0), element.DesiredSize);
                element.Arrange(bounds);
            }
            return arrangeSize;
        }
        public void CreateField(Field element)
        {
            element.Children.Add(new Cell());
        }
    }

但是,

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

1 个答案:

答案 0 :(得分: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);