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

how to share InlineKeyboardButton #60

Closed mjavidm closed 7 years ago

mjavidm commented 7 years ago

hi; how to share InlineKeyboardButton to other chat “private”, “group”, “supergroup” or “channel” so that show completely?

Eleirbag89 commented 7 years ago

What do you mean ?

mjavidm commented 7 years ago

when you forward message with InlineKeyboardButton to other user group channel
only send text of forward message and InlineKeyboardButton not show

Eleirbag89 commented 7 years ago

I don't think you can do it. In https://core.telegram.org/bots/api#forwardmessage there isn't a field for the keyboard. I guess it's because the chat where you forward the message could not have the bot, so who would respond the InlineKeyboardButton click ?

mjavidm commented 7 years ago

Can be done I think by inlinequery is possible with 'reply_markup' , But how? :)

'switch_inline_query_current_chat' in 'buildInlineKeyboardButton' !!!

$option = [ [$telegram->buildInlineKeyboardButton( 'text'=> 'text1',)], [$telegram->buildInlineKeyboardButton( 'text'=> 'text2',)], [$telegram->buildInlineKeyboardButton( 'text'=> 'text3',)], [$telegram->buildInlineKeyboardButton( 'text'=> 'shareToOtherChat','switch_inline_query_current_chat'=>'!!??')] ]; $keyb = $telegram->buildInlineKeyBoard($option); https://core.telegram.org/bots/api#inlinekeyboardmarkup

Eleirbag89 commented 7 years ago

Idk, do some experiments and see what happens, the documentation of the parameter switch_inline_query_current_chat is really unclear. Start by setting it to an empty string.

mjavidm commented 7 years ago
//create inline keyboard :
$option = [
 [$telegram->buildInlineKeyboardButton( 'text'=> 'text1',)],
 [$telegram->buildInlineKeyboardButton( 'text'=> 'text2',)],
 [$telegram->buildInlineKeyboardButton( 'text'=> 'shareToOtherChat','switch_inline_query'=>'chek')]
 ];
 $keyb = $telegram->buildInlineKeyBoard($option);

// chek query and create inline keyboard 
if ( $result["inline_query"]["query"] == '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'=>''],
                            ['text'=>"text2",'url'=>''],
                            ['text'=>"shareToOtherChat",'switch_inline_query'=>'chek']
                        ]
                        ]],
    'thumb_url'=> "https://avatars2.githubusercontent.com/u/10547598?v=3&s=88",
    ]
    ] );

    $content =['inline_query_id' => $result["inline_query"]["id"],
    'results' => $results 
    ];
    $reply = $telegram->answerInlineQuery($content);

  }
Eleirbag89 commented 7 years ago

You need to populate the urls:

 'reply_markup'=>['inline_keyboard'=>[
    [
        ['text'=>"text1",'url'=>'http://google.it'],
        ['text'=>"text2",'url'=>'http://google.it'],
        ['text'=>"shareToOtherChat",'switch_inline_query'=>'chek']
    ]
]],

And the inline query id needs to be the one you get from telegram:

$data = $telegram->getData();
$content =['inline_query_id' => $data["inline_query"]["id"], 'results' => $results  ];