Eleirbag89 / TelegramBotPHP

A very simple PHP Telegram Bot API for sending messages.
http://eleirbag89.github.io/TelegramBotPHP
MIT License
809 stars 342 forks source link

sample cod of InlineQuery #58

Closed mjavidm closed 7 years ago

mjavidm commented 7 years ago

hi, plz put sample code of InlineQuery I looked but not found

Eleirbag89 commented 7 years ago

This is an example i used for a gamebot:

if ($data["inline_query"] !== null && $data["inline_query"] != "") {
    $query = $data["inline_query"]["query"];

    if (strpos("testText", $query) !== false) {
        $results = json_encode(array( array('type' => "game", 'id'=> "1", 'game_short_name' => "game_name") ) );
        $content = array('inline_query_id' => $data["inline_query"]["id"], 'results' => $results );
        $reply = $telegram->answerInlineQuery($content);
    }

}
mjavidm commented 7 years ago

Thank you But how it works? How to cal it...

Eleirbag89 commented 7 years ago

first follow this steps: https://core.telegram.org/bots/api#inline-mode

then in any chat you should be able to write a message like @botusername testText and the if should trigger. You need of course to change $resulto your inline query result (https://core.telegram.org/bots/api#inlinequeryresult), idk what you want to do. Example of InlineQueryResultGif $results = json_encode(array( array('type' => "gif", 'id'=> "1", 'gif_url' => "http://gifUrl.gif", 'thumb_url'=>"http://thumburl.gif") ) );

Eleirbag89 commented 7 years ago

Example 4 gifs:

if ($data["inline_query"] !== null && $data["inline_query"] != "") {
    $query = $data["inline_query"]["query"];

    if (strpos("testText", $query) !== false) {
        $results = json_encode(array( array('type' => "gif", 'id'=> "1", 'gif_url' => "http://i1260.photobucket.com/albums/ii571/LMFAOSPEAKS/LMFAO/113481459.gif", 'thumb_url'=>"http://i1260.photobucket.com/albums/ii571/LMFAOSPEAKS/LMFAO/113481459.gif") ) );
        $content = array('inline_query_id' => $data["inline_query"]["id"], 'results' => $results );
        $reply = $telegram->answerInlineQuery($content);
    }

    if (strpos("dance", $query) !== false) {
        $results = json_encode(array( array('type' => "gif", 'id'=> "1", 'gif_url' => "https://media.tenor.co/images/cbbfdd7ff679e2ae442024b5cfed229c/tenor.gif", 'thumb_url'=>"https://media.tenor.co/images/cbbfdd7ff679e2ae442024b5cfed229c/tenor.gif") ) );
        $content = array('inline_query_id' => $data["inline_query"]["id"], 'results' => $results );
        $reply = $telegram->answerInlineQuery($content);
    }   
}

Try it on cowmooobot: @cowmooobot dance

mjavidm commented 7 years ago

Thank you not work :( I set "dance" command /setinline in @botfother and put code in hook.php

and in other chat calling bot nothing , not work

but call @cowmooobot dance and show gif dancing ...

Eleirbag89 commented 7 years ago

Be sure your Telegram.php is update. Also can you post some the code of your bot, just the part where you manage the telegram's incoming messages ?

mjavidm commented 7 years ago

OK Alright! thank you very much pleas put sample code of InlineQueryResultArticle completely how to create InputMessageContent !! not work!

Eleirbag89 commented 7 years ago

did you try $results = json_encode(array( array('type' => "article", 'id'=> "1", 'title' => "The title", 'input_message_content'=>array('message_text' => "Text message") ) ) ); ?

mjavidm commented 7 years ago

yes, but not put "array"! thank you