电报 inline_keyboard 不工作 - PHP

Telegram inline_keyboard doesn't work - PHP

<?php
require_once('core.php');
$content = file_get_contents("php://input");
$update = json_decode($content , true);
$chat_id = $update["message"]['chat']['id'];
$text = $update["message"]['text'];
$message_id = $update["message"]['message_id'];
if($text == '/start'){
    $matn = 'Welcome';
    MessageRequestJson('sendMessage' , array('chat_id'=>$chat_id , 'text'=>$matn , 'reply_markup'=>array(
    "inline_keyboard" => array(array(array("text" => "My Button Text"))))));
}
?>

当用户向机器人发送“/start”时,我使用了 sendMessage 方法和响应 'Welcome'。 我使用了 reply_markup 和 inline_keyboard 但是当我 运行 我的代码和我发送 '/start' 它不起作用!

这是core.php代码:

<?php
const BOT_TOKEN =  'I passed token here!';
const API_URL = 'https://api.telegram.org/bot'.BOT_TOKEN.'/';

function MessageRequestJson($method , $parameters){
    if (!$parameters) {
        $parameters = array();
    }

    $parameters["method"] = $method;

    $handle = curl_init(API_URL);
    curl_setopt($handle , CURLOPT_RETURNTRANSFER , true);
    curl_setopt($handle , CURLOPT_CONNECTTIMEOUT , 5);
    curl_setopt($handle , CURLOPT_TIMEOUT , 60);
    curl_setopt($handle , CURLOPT_POSTFIELDS, json_encode($parameters));
    curl_setopt($handle , CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($handle);
    return $result;
}
?>

如果我运行你的代码,但是包含一个var_dump($result);电报returns出现以下错误:

Bad Request:

Can't parse inline keyboard button: Text buttons are unallowed in the inline keyboard

这是由无效 reply_markup 引起的,请考虑以下替代方法:

$matn = 'Welcome';
$keyboard = [
    "inline_keyboard" => [
        [
            [
                "text" => "My Button Text",
                "callback_data" => "test"
            ]
        ]
    ]
];
MessageRequestJson('sendMessage' , [ 'chat_id'=> $chat_id , 'text'=> $matn , 'reply_markup' => $keyboard ]);

我没有改变 MessageRequestJson()

运行 应用上述代码后的代码显示: