Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create inline button for share message telegram bot php

Tags:

php

bots

telegram

I have a message to which I want to add an inline button. When clicking this button the user can forward this message to groups. How can I do this?

$keyboard = [
    'inline_keyboard' => [
    [['text' => 'forward me to groups']],
]];
HTTPRequest("sendMessage", [
    "chat_id" => $request["message"]["chat"]["id"],
    "text" => "this is a message",
    "reply_markup" => json_encode($keyboard)
]);
like image 910
no3ignal no3ignal Avatar asked Nov 24 '16 19:11

no3ignal no3ignal


1 Answers

There is a solution that i can think of. Aaccording to Telegram API documentation, you can pass an optional parameter called switch_inline_query. This is not the application of switch_inline_query but it can do what you want. Your code will be like this:

$keyboard = [
'inline_keyboard' => [
[['text' => 'forward me to groups'], 'switch_inline_query' => 'this is a message'],
]];
HTTPRequest("sendMessage", [
    "chat_id" => $request["message"]["chat"]["id"],
    "text" => "this is a message",
    "reply_markup" => json_encode($keyboard)
]);

Pressing the inline button will prompt the user to select one of their groups or chats, open that chat and insert the bot‘s username and the specified message:
@Yourbot This is a message
and by pressing send button message will be sent.

like image 65
Vahid Msm Avatar answered Oct 21 '22 05:10

Vahid Msm