为什么电报键盘不发送 Guzzle 请求
Why Telegram keyboard not send with Guzzle request
$params = [
'chat_id' => $this->chatID,
'text' => 'What?',
'reply_markup' => [
'resize_keyboard' => true,
'keyboard' => [
[
['text' => 'text1'],
['text' => 'text2'],
]
]
]
];
$this->client->request('POST', $this->apiUrl . '/sendMessage', array('query' => $params));
消息有效!但是keboards没有显示。
问题似乎是 Guzzle 没有对任何深度查询参数进行 urlencode,在发送到 Guzzle 之前,我已经设法通过在键盘上使用 json_encode
来发送键盘;
<?php
use GuzzleHttp\Client;
require_once __DIR__ . '/vendor/autoload.php';
CONST CHAT_ID = '~~';
CONST TOKEN = '~~';
CONST BASE = 'https://api.telegram.org/bot' . TOKEN;
$client = new Client();
$client->request('POST', BASE . '/sendMessage', [
'query' => [
'chat_id' => CHAT_ID,
'text' => 'Hi Maxim!',
'reply_markup' => json_encode([
"inline_keyboard" => [
[
[
"text" => "Yes",
"callback_data" => "yes"
],
[
"text" => "No",
"callback_data" => "no"
]
]
]
])
]
]);
$params = [
'chat_id' => $this->chatID,
'text' => 'What?',
'reply_markup' => [
'resize_keyboard' => true,
'keyboard' => [
[
['text' => 'text1'],
['text' => 'text2'],
]
]
]
];
$this->client->request('POST', $this->apiUrl . '/sendMessage', array('query' => $params));
消息有效!但是keboards没有显示。
问题似乎是 Guzzle 没有对任何深度查询参数进行 urlencode,在发送到 Guzzle 之前,我已经设法通过在键盘上使用 json_encode
来发送键盘;
<?php
use GuzzleHttp\Client;
require_once __DIR__ . '/vendor/autoload.php';
CONST CHAT_ID = '~~';
CONST TOKEN = '~~';
CONST BASE = 'https://api.telegram.org/bot' . TOKEN;
$client = new Client();
$client->request('POST', BASE . '/sendMessage', [
'query' => [
'chat_id' => CHAT_ID,
'text' => 'Hi Maxim!',
'reply_markup' => json_encode([
"inline_keyboard" => [
[
[
"text" => "Yes",
"callback_data" => "yes"
],
[
"text" => "No",
"callback_data" => "no"
]
]
]
])
]
]);