How to make user hyperlink in python telegram bot?

Question:

Stack overflow!

I’m using telebot module for my telegram bot (from telebot import types).
I want to send messages to telegram users.
In this messages I want to paste a link to another telegram users.

My code is:

linked_user = '[username](tg://user?id=999999999)'
bot.send_message(
    admin_chat_id, f'{linked_user}',
    parse_mode='MarkdownV2',
    disable_web_page_preview=True)

I expect that admin will receive a message with username in it.
And if admin will click on the text, he will be redirected to the linked_user’s profile…

The problem is:

It’s not always a hyperlinked text. It can be a plain text…
With some user’s chat.id’s it works well, with other – don’t!

I tried to make decisions from the fact, than not every telegram user have 9-digit chat.id – but it’s not the reason too…

So I want to make hyperlink for EVERY user… don’t know how to do that, so please help me!)

Asked By: ML777

||

Answers:

Some Users have specific privacy settings. So even though you can pm them, you cant "publish" their usernames so anyone else can Contact them. So you are not doing anything wrong.

Answered By: JyR27

Straight method.

From inside telegram

bot = telebot.TeleBot(ACCESS_TOKEN)

BOT_LINK = f"tg://user?id={bot.user.id}"

From web

BOT_LINK_EXTERNAL = f"https://t.me/{bot.user.username}"
Answered By: Evgene