8

I want mention users even those which do not have a username.

If a user has set up a username I return

Hi @username 

as an answer but if a user does not have one I can't do that.

I tried using the unique User ID e.g.

@5642166

but that did not work.

How can I achieve that?

Charuක
  • 12,953
  • 5
  • 50
  • 88
john
  • 81
  • 1
  • 1
  • 2

2 Answers2

5

According to official documentation it is possible to mention user by its numerical id with markup:

Markdown style

To use this mode, pass Markdown in the parse_mode field when using sendMessage. Use the following syntax in your message:

[inline mention of a user](tg://user?id=123456789)

and you can also use HTML style :

HTML style

To use this mode, pass HTML in the parse_mode field when using sendMessage. The following tags are currently supported:

<a href="tg://user?id=123456789">inline mention of a user</a>
GameO7er
  • 2,028
  • 1
  • 18
  • 33
0

The example below should work.

context.bot.send_message(chat_id=update.effective_chat.id, 
                         parse_mode = ParseMode.MARKDOWN_V2, 
                         text = "[inline mention of a user](tg://user?id=123456789)")