简体   繁体   中英

how to create inline button for share message telegram bot php

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM