How to create user profile URL from Telegram bot message sender data

I’m building a Telegram bot and need help with generating profile links for users who send messages. I can retrieve basic user information when processing incoming messages, but I’m stuck on how to convert this data into an actual clickable profile link.

Here’s what I’m working with:

@Override
public void handleIncomingMessage(Update msgUpdate) {
    User sender = msgUpdate.getMessage().getFrom();
    // Available data: sender.getFirstName(), sender.getLastName()
    // Also have: sender.getId() which returns a numeric value
    // Question: How do I turn this numeric ID into a working Telegram profile URL?
}

I can access the sender’s name and user ID, but I’m not sure about the correct way to format these into a proper Telegram profile link. What’s the right approach here?

Use the numeric ID from sender.getId() to create user profile links in your Telegram bot. The format is tg://user?id= plus the user’s ID. These links only work inside Telegram clients though. In Java: String profileLink = "tg://user?id=" + sender.getId(); If you need links that work outside Telegram, use usernames instead in the format https://t.me/username. Just remember that not everyone has a username.

heads up - tg://user?id= works great but won’t show usernames in the link text. you’ll just get “User123” instead of their actual name. for nicer looking links, grab their firstname: String linkText = sender.getFirstName(); String url = "tg://user?id=" + sender.getId(); then format it however your bot displays messages