【问题标题】:Telegram Bot Keyboard Button电报机器人键盘按钮
【发布时间】:2021-03-25 16:59:19
【问题描述】:

我遇到了 Telegram Keyboard 的问题,我想在我的数组中发送一个字符串,用于带有“#”的标记 但是使用“#”它不起作用 我访问了一个和我一样的机器人,效果很好,在键盘按钮中显示“#”

我该如何解决这个问题??

$string = "#number 1";//This # 

$markup[] = [
    ["text" =>  $string ]
];

$keyboard = [
    "keyboard" => $markup,
    "resize_keyboard" => true
];

return $r = file_get_contents("https://api.telegram.org/bot" . TOKEN . "/sendMessage?chat_id="
    . $chat_id . "&text=" . urlencode("MENU") . "&reply_markup=" . json_encode($keyboard));

【问题讨论】:

    标签: php telegram telegram-bot php-telegram-bot


    【解决方案1】:

    # 会干扰请求 url。

    你应该逃避它以防止这种情况发生。

    最简单的解决方案是在包含任何特殊字符的文本上使用urlencode() 函数:

    <?php
    
        $chat_id = ;
        CONST TOKEN = '';
    
        $keyboard = [
            "keyboard" => [
                [
                    ["text" =>  urlencode('Test -> #') ]
                ]
            ],
            "resize_keyboard" => true
        ];
    
        return file_get_contents("https://api.telegram.org/bot" . TOKEN . "/sendMessage?chat_id="
            . $chat_id . "&text=" . urlencode("MENU") . "&reply_markup=" . json_encode($keyboard));
    

    将产生:

    【讨论】:

      猜你喜欢
      • 2018-03-23
      • 2016-03-22
      • 2020-10-08
      • 2020-10-10
      • 2018-09-25
      • 1970-01-01
      • 2017-08-01
      • 2022-10-05
      • 2018-12-03
      相关资源
      最近更新 更多