GET-запросы имеют ограничения по длине. Используйте curl, чтобы сделать запрос POST. Вы можете использовать эту функцию для вызова метода API ($method
) с параметрами ($args
)
function http_request($method, $args) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot{TOKEN}/$method?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
return $result;
}
В вашем случае
$infoUtente = "<b>Ciao! Io sono $username</b>\n\nIl mio chatId è <code>$chatId</code>\nIl mio nome è $name\nIl mio cognome è $cognome";
$risultati = [[
"type" => "article",
"id" => "0",
"title" => "Titolo del Result",
"input_message_content" => array("message_text" => "Testo del Result", "parse_mode" => "HTML"),
"reply_markup" => array("inline_keyboard" => [[array("text" => "CLICCA QUI", "url" => "google.com")], [array("text" => "CLICCA QUI", "callback_data" => "StampaMessaggio")]]),
"description" => "Descrizione del result",
],
[
"type" => "article",
"id" => "1",
"title" => "Invia le tue informazioni",
"input_message_content" => array("message_text" => "$infoUtente", "parse_mode" => "HTML"),
"reply_markup" => array("inline_keyboard" => [[array("text" => "CLICCA QUI", "url" => "google.com")], [array("text" => "CLICCA QUI", "callback_data" => "StampaMessaggio")]]),
"description" => "Descrizione del result",
],
];
$json = [
"inline_query_id" => $queryId,
"results" => $risultati,
"cache_time" => 0,
"switch_pm_text" => "Vai al Bot",
"switch_pm_parameter" => "123"
];
http_request("answerInlineQuery", $json);
Вы также можете использовать Моя php библиотека , которая содержит все готовые к использованию методы Telegram API.