PHP 中的电报机器人自定义键盘
2022-08-30 20:43:33
我正在尝试用自定义键盘在PHP中制作一个Telegram Bot。邮件已传递,但自定义键盘将不起作用。$keyb = array('keyboard' => array(array(“A”, “B”)));也没有成功。
sendMessage 方法引用对象的 ReplyKeyboardMarkup。为 ReplyKeyboardMarkup 创建数组不起作用。还试图json_encode($keyb),但这也不是解决方案。
我在GitHub中搜索了示例,但我没有找到使用自定义键盘的示例。Telegram在iPhone和桌面上运行,都是最新的。
示例代码:
$url = "https://api.telegram.org/bot<token>/sendMessage";
$keyb = array('ReplyKeyboardMarkup' => array('keyboard' => array(array("A", "B"))));
$content = array('chat_id' => <chat_id>, 'reply_markup' => $keyb, 'text' => "Test");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //fix http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);