V
V
Vlad Gapanovich2021-04-19 22:00:49
Java
Vlad Gapanovich, 2021-04-19 22:00:49

How to get telegram username?

I am making a Telegram bot and would like to get the username after writing "/start".
ChatId I was able to get through gatChatId.
But with UserName there was a misunderstanding. How to get it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mimocodil, 2021-04-25
@Mario172

To get a username, write:
update.getMessage().getFrom().getUserName()
But the user may not have a username. However, you can find out his "first name" and "last name":
update.getMessage().getFrom().getFirstName()
update.getMessage().getFrom().getLastName()
In addition, you can also extract information about the language of his system from the user:
update.getMessage().getFrom().getLanguageCode()
Returns a string in IETF format , for example "ru" for Russian

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question