1
votes

i am trying to create an inline bot for telegram with php. I have followed the steps with the BotFather. I have created the bot, taken the token, setinline and set the placeholder message. I have set the webhook and it's working. But when i type the bot in the message i do get nothing and if I send the message, just nothing happen. The webhook is working, I have tried it with normal messages.

This is my code, after a while I just give up and get it from a blog, edited it a bit.

$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",
          ],  
        ]
      ]);
     }
    }

The bot still show me nothing. I think i just skipped a step.

1
What does Bot API response to you? - ihoru
@ihoru nothing. Does not give me nothing. - Giorgio Catenacci

1 Answers

2
votes

The results need to have the key message_text inside the input_message_content.
Therefore a result could look like this:

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