How to make that when you click on the text it was copied pytelegrambotapi

10,070

Solution 1

If I understand you correctly, you wish to send a message, that when the user presses it, the text is automatically copied to the user's clipboard, just like the BotFather sends the API token?

enter image description here


This is done by the MarkDown parse_mode;
Send a message with &parse_mode=MarkDown and wrap the 'pressable' text in back-ticks (`):

Hi. `Press me!`!
https://api.telegram.org/bot<token>/sendMessage?chat_id=<id>&text=Hi! `Press me!`&parse_mode=MarkDown

enter image description here


EDIT: Bases on OP's comment you're looking for a solution.
From there documentation;

bot.send_message(
    chat_id=chat_id, 
    text="*bold* _italic_ `fixed width font` [link](http://google.com).", 
    parse_mode=telegram.ParseMode.MARKDOWN
)

Solution 2

You can simply by editing the text in following manner Write ``` then write your text then again write that 3 character . Bingo!!!

Share:
10,070

Related videos on Youtube

DanDyFun
Author by

DanDyFun

Updated on June 04, 2022

Comments

  • DanDyFun
    DanDyFun almost 2 years

    I am writing a telegram to the bot. I ran into such a problem. I need the bot to send a message (text) when clicked on which it was copied (as a token from @BotFather)

  • DanDyFun
    DanDyFun over 4 years
    Yes, but I do not quite understand how to realize it in the python. Let's say, there is a code snippet: bot.send_message(message.chat.id, 'Hello, my owner') How to do that the fragment of the text (owner) could be copied?
  • DanDyFun
    DanDyFun over 4 years
    Maybe: bot.send_message(message.chat.id, 'Hello, my owner', parse_mode=Markdown) ?
  • DanDyFun
    DanDyFun over 4 years
    Maybe: bot.send_message(message.chat.id, 'Hello, my `owner`', parse_mode=Markdown) ?