编程语言
首页 > 编程语言> > 电报Bot嵌入式键盘不显示PHP

电报Bot嵌入式键盘不显示PHP

作者:互联网

以下代码有效,它添加了自定义键盘键“ Button1”和“ Button2”

$keyboard = [
              'keyboard' => [['Button1'],['Button2']],
              'resize_keyboard' => true,
              'one_time_keyboard' => true,
              'selective' => true
            ];

$keyboard = json_encode($keyboard, true);

$sendto = API_URL."sendmessage?chat_id=".$chatID."&text=".$reply."&parse_mode=HTML&reply_markup=$keyboard";

虽然出于我的目的,我需要使用嵌入式键盘,但是我无法使其正常工作

$keyboard = [
             'inline_keyboard' => [['Button1' =>  'test', 'callback_data' => 'test'],
            ];

要么

$keyboard = [                       
             'inline_keyboard' => [['Button1' =>  'test'],['callback_data' => 'test']],
            ];

不起作用.如果有人有一个可行的示例,或者可以指出我的示例出了什么问题,我将不胜感激.

链接到文档:https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating

解决方法:

好像您缺少一个额外的数组. Reply_markup应该如下所示:

$keyboard = array(
    "inline_keyboard" => array(array(array("text" => "My Button Text", "callback_data" => "myCallbackData")))
);

标签:telegram-bot,telegram,php-telegram-bot,php
来源: https://codeday.me/bug/20191111/2022621.html