[Python] How to create a Telegram user mention link that works across all devices and profile...

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a Telegram bot, and I want to generate clickable user mentions in admin reports. These mentions should:


    • Link to the user's profile


    • Work on all platforms


    • Handle any kind of Telegram profile:


    • Users with a @username


    • Users without a username (only display name)

    My issue:

    I'm using this approach to build the mention:

    mention = f'<a href="tg://user?id={user.id}">{user.full_name}</a>'


    It works for most users, but:

    On some devices (especially iOS), clicking the link doesn't open the profile Sometimes the name isn't rendered as a link at all

    I'm not sure if I should use tg://user?id=... or https://t.me/username, or how to fall back when there's no username

    Continue reading...

Compartilhe esta Página