Eleirbag89 / TelegramBotPHP

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

Inline_Keyboard problem In AnswerInlineQuery Method #205

Closed Mohsen322 closed 3 years ago

Mohsen322 commented 4 years ago

im very confused why the buttun i created didnt attaching to inline answers. its work fine with normal methods like sendMessage, sendPhoto and etc. but in inline method i got error. here is my sample code:

if($msgType == 'inline_query'){
    $option = array( 
        array(
            $telegram->buildInlineKeyboardButton("TEST BUTTUN","","on")
        )
    );
    $keyb = $telegram->buildInlineKeyBoard($option);

    $results = [
            ['type' => 'article', 'id' => mt_rand(1,100), 'title' => 'test 2', 'message_text' => 'sent keyb 2', 'reply_markup' => $keyb]
        ];    

$content = array('inline_query_id' => $inline_query_id, "results" => json_encode($results), 'cache_time' => 5);
$telegram->answerInlineQuery($content);
}

$content = array('chat_id' => $chat_id, 'text' => json_encode($data, JSON_PRETTY_PRINT), 'reply_markup' => $keyb);
$telegram->sendMessage($content);

I TESTED BUTTON WITH sendMessage and here the result: image

and got this error in inline mode:

description: Bad Request: field "reply_markup" must be of type Object

the json passed:

[{"type":"article","id":7,"title":"test 2","message_text":"sent keyb 2","reply_markup":"{\"inline_keyboard\":[[{\"text\":\"\\u0641\\u0639\\u0627\\u0644 \\u06a9\\u0646\",\"callback_data\":\"on\"}]]}"}]

Eleirbag89 commented 4 years ago

I use this as an example:

if ($data["inline_query"] !== null && $data["inline_query"] != "") {  
   $query = $data["inline_query"]["query"];    
   if ( $query == 'chek') {  
      $option = array( array ( $telegram->buildInlineKeyboardButton("Test", $url="http://google.it"),
            $telegram->buildInlineKeyboardButton("Test2", $url="http://google.it"), 
            $telegram->buildInlineKeyboardButton("shareToOtherChat", "", "", "chek", "", "") ) );                 

       $results= json_encode( [ [ 'type' => "article", 'id'=> "1", 'title'=> "chek inline keybord ", 'description'=> "test ", 'caption'=> "caption" , 'input_message_content'=> ['message_text' => "you can share inline keyboard to other chat"], 'reply_markup'=>['inline_keyboard'=>[       [        ['text'=>"text1",'url'=>'http://google.it'],        ['text'=>"text2",'url'=>'http://google.it'],        ['text'=>"shareToOtherChat",'switch_inline_query'=>'chek']       ]       ]], 'thumb_url'=> "https://avatars2.githubusercontent.com/u/10547598?v=3&s=88", ] ] ); 

      $content =['inline_query_id' => $data["inline_query"]["id"], 'results' => $results ]; 
      $reply = $telegram->answerInlineQuery($content); 
   }    
   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);  
   }   
}
Mohsen322 commented 4 years ago

good temporary Solution :)))

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.