【问题标题】:Telegram Inline Bot won't showTelegram Inline Bot 不会显示
【发布时间】:2020-04-05 20:25:04
【问题描述】:

我正在尝试创建一个 Telegram Bot,我在 BotFather 设置中启用了内联,但是当我输入 bot 名称时,它不会显示除搜索之外的任何内容...

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

【问题讨论】:

    标签: php telegram telegram-bot php-telegram-bot


    【解决方案1】:

    GET 请求有长度限制。改为使用 curl 发出 POST 请求。您可以使用该函数调用带有参数($args)的 API 方法($method

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

    您也可以使用my php library,其中包含所有可供使用的 Telegram API 方法。

    【讨论】:

      猜你喜欢
      • 2017-01-11
      • 1970-01-01
      • 2017-06-02
      • 2022-08-23
      • 1970-01-01
      • 2021-06-20
      • 2018-09-22
      • 2019-08-07
      • 1970-01-01
      相关资源
      最近更新 更多