I am making Telegram Bot and I have two inline buttons. I need to do that when the user clicks on a button bot would answer like "Hi @username". How to do that?
- November 14, 2020
- 128 views
- 0 votes
- 2 Answers
-
I am making Telegram Bot and I have two inline buttons. I need to do that when the user clicks on a button bot would answer like "Hi @username". How to do that?
2
Answers
Any message objects that you receive contains ‘from’ as a key to the User object which contains ‘first_name’ and other attributes (https://core.telegram.org/bots/api#user).
With the aiogram library, which I recommend, you can do something like this:
I found a way to do this! You need to add
username = "@" + str(message.from_user.username)
and thenbot.send_message(message.chat.id, "Hi " + username)