2016-06-13 102 views
1

我正在尝试使用php为电报创建一个内联bot。我已经跟随了Bot Bot的步骤。我已经创建了bot,取得了令牌,设置并设置了占位符消息。我设置了webhook,它正在工作。但是当我在消息中输入机器人时,我什么也得不到,如果我发送消息,就什么都没有发生。 webhook正在工作,我用普通的消息试了一下。Telegram Inline Bot没有显示任何内联

这是我的代码,过了一段时间我只是放弃并从博客中获取它,编辑了一下。

$content = file_get_contents("php://input"); 
$update = json_decode($content, true); 

$chatID = $update["message"]["chat"]["id"]; 
//sendMessage(print_r($update,true), $chatID); 

if (isset($update["inline_query"])) { 
    $inlineQuery = $update["inline_query"]; 
    $queryId = $inlineQuery["id"]; 
    $queryText = $inlineQuery["query"]; 

if (isset($queryText) && $queryText !== "") { 
    apiRequestJson("answerInlineQuery", [ 
    "inline_query_id" => $queryId, 
    "results" => ($queryText), 
    "cache_time" => 86400, 
    ]); 
} 
else { 
     apiRequestJson("answerInlineQuery", [ 
     "inline_query_id" => $queryId, 
     "results" => [ 
      [ 
      "type" => "article", 
      "id" => "0", 
      "title" => "TEST", 
      "message_text" => "TEST", 
      ], 
     ] 
     ]); 
    } 
    } 

机器人仍然没有显示任何东西。 我想我只是跳了一步。

+0

Bot API对您的回应是什么? – ihoru

+0

@ihoru什么都没有。不给我什么。 –

回答

2

结果需要在input_message_content之内有关键message_text
因此,结果可能如下所示:

$results = array(
    array(
     "type" => "article", 
     "id" => "1", 
     "title" => "Title", 
     "description" => "Description", 
     "input_message_content" => array(
      "message_text" => "<code>Message 1</code>", 
      "parse_mode" => "HTML" 
     ) 
    ) 
); 

$postData = array(
    "inline_query_id" => $inlineQuery["id"], 
    "results" => json_encode($results), 
    "cache_time" => 0 
); 
+0

感谢m8,现在内联工作对我来说很有帮助。但我也需要发送'parse_mod'标签,如果我写: '“input_message_content”=> array([“message_text”=>“Messages Text”,“parse_mode”=>“HTML”])' Nothing works再次... –

+0

你可能只需要去掉'input_message_content'中额外的'[]''。我通过一个工作示例编辑了我的答案。 – Maak