Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a message to Telegram that includes a button that prompts the user to forward the message?

Many Telegram bots (e.g., @youtube) have a button you can click on to forward messages sent by the bot. When the user clicks on this button, Telegram opens a contact list that lets the user choose who to forward the message to.

How can I send a button like this? The closest thing I can find is forwardMessage but that expects chat_id target ID as a required parameter. But I won't have this target ID until the user selects who they want to forward to.

like image 629
Thomas Johnson Avatar asked Feb 27 '17 16:02

Thomas Johnson


People also ask

What is inline button in Telegram?

Switch to Inline buttons Pressing a switch to inline button prompts the user to select a chat, opens it and inserts the bot's username into the input field. You can also pass a query that will be inserted along with the username – this way your users will immediately get some inline results they can share.

How do I give someone a message bot on Telegram?

You have to use the @BotFather bot to set the Group Privacy off. This let the bot to access all the group messages. Please note that this change is not propagated automatically, so in case the bot is already in a group before turning off privacy mode, it will remain as it was before.

Is there any way to auto forward a message in a Telegram channel to a contact or group?

TForwarder can automatically forward messages for you by keyword or without any filters from selected telegram chats to needed telegram channel or group or directly for your friend. You can use app as a distribution of messages from any telegram chats (private channels, private groups, direct chats) into one chat.


1 Answers

If you want to share your content to specific chats, you have 2 options:

Option 1

If your bot has inline_mode enabled you can share content via a button that opens a inline_query in the chat selected. Basically, this is how @youtube bot works. To use this method you need to send an inline button with switch_inline_query as a field (documentation).

Example in Javascript:

bot.sendMessage(msg.chat.id, 'Share:', {
    reply_markup: {
        inline_keyboard: [[{
            text: 'Share with your friends',
            switch_inline_query: 'share'
        }]]
    }
})

This is the same example I use in my bot @livecoinbot, set a bitcoin address and use the share button.

Option 2

You can create a normal inline button or just simply send a link in a normal message, that will prompt the telegram client to share the content. Here is how you do it:

https://t.me/share/url?url=[url-to-send-here]&text=[text]

Example: Click here

like image 101
Mohamed Sohail Avatar answered Sep 28 '22 06:09

Mohamed Sohail