0

I am trying to create a Telegram Bot, I enabled inline from BotFather settings but when I type the bot name it won't show anything except Search...

  $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",

          ],
  ];
  $risultati = json_encode($risultati,true);
  $url = $GLOBALS[website]."/answerInlineQuery?inline_query_id=$queryId&results=$risultati&cache_time=0&switch_pm_text=Vai al Bot&switch_pm_parameter=123";
  file_get_contents($url);
  exit();
Erry215
  • 326
  • 1
  • 4
  • 15

1 Answers1

0

GET requests have lenght restrictions. Use curl to make POST request instead. You can use this function to call an API method ($method) with parameters ($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;
}


In your case


$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);

You can also use my php library which contains all the Telegram API methods ready to use.

GioIacca9
  • 406
  • 4
  • 8