如何使用PHP在电报机器人中进行简单的测验和按钮答案?

时间:2016-07-14 00:50:09

标签: php telegram telegram-bot

我想做一个简单的问题和多项选择的答案,我想要的结果就像这张图片:this is picture for desired the multiple choice button
但结果不像我想要的那样是我的代码的结果图片:this is picture for not desired result
这是我尝试过的代码:

<?php
$token = "##################################";
$website = "https://api.telegram.org/bot".$token;

$array = array(array("1","2","3"));
$btn = array("keyboard" => $array,"hide_keyboard" => true,'selective' => true,);
$reply = json_encode($btn);
$url = $website."/sendmessage?chat_id=$chatIdtext=select : &reply_markup=".$reply;
file_get_contents($url);
?>

1 个答案:

答案 0 :(得分:0)

试试这段代码,结果可能就像你想要的那样。

<?php
$token = "######################################";
$website = "https://api.telegram.org/bot".$token;

$name1 = 'das';
$name2 = 'dsa';
$placeId1 = '1';
$placeId2 = '2';
$keyboard = [
            'inline_keyboard' => [[['text' =>  $name1, 'callback_data' => $placeId1]], [['text' =>  $name2, 'callback_data' => $placeId2]]],
        ];

$reply = json_encode($keyboard);
$url = $website."/sendmessage?chat_id=130434215&text=select : &reply_markup=".$reply;
file_get_contents($url);
?>