电报机器人如何从他们发送的消息中获取到用户配置文件的链接

发布于 2025-01-25 10:56:20 字数 387 浏览 2 评论 0原文

我正在使用Telegram Bot,并且有此方法可以获取用户消息。 我需要找到一种方法来获取发送此消息的用户的链接 我看到有这种方法,但我不知道如何将它们连接到“链接”到个人资料

   @Override
    public void onUpdateReceived(Update update) {
      update.getMessage().getFrom();
       // i have: getFirstName(), getLastName() - not helping
       // i have also getId() - but its a number how do i convert it to a link to telegram profile ?

}

I'm working with telegram bot and i have this method to get user messages.
I need to find a way to get a link to the user who send this message
I saw there are this method, but i dont know how to connect them to a "link" to a profile

   @Override
    public void onUpdateReceived(Update update) {
      update.getMessage().getFrom();
       // i have: getFirstName(), getLastName() - not helping
       // i have also getId() - but its a number how do i convert it to a link to telegram profile ?

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ低調成傷 2025-02-01 10:56:20

拥有用户名是电报的可选,设置它意味着其他人将能够在不知道电话号码的情况下与用户联系。只有在Telegram设置中选择用户名的用户才有一个配置文件链接,并且该链接是https://t.me/&username&username&ggt;的链接。

对于普通消息,您可以通过update.getMessage()。getfrom()。getUsername()并使用它来创建配置文件链接,请注意,对于许多用户,此值将为空,请注意(这意味着他们没有配置文件链接)。

另外,如果保留聊天ID的数据库,则可以通过 getchat 电报API调用。这可能很有用,因为虽然用户可以随时更改用户名(这意味着他们的配置文件链接也会更改),但用户的聊天ID随着时间的推移而持续不变,并且getChat 方法将始终为您提供。最新信息。

Having username is optional on Telegram, setting it up means other people will be able to contact the user without knowing their phone number. Only users that chose their username in Telegram settings have a profile link, and the link is of the form https://t.me/<username>.

For ordinary messages, you can get the username via update.getMessage().getFrom().getUsername() and use it to create profile links, however, note that for many users this value will be empty (meaning they don't have a profile link).

Also, if you keep database of chat IDs, you can get usernames of the users via getChat Telegram API call. This can be useful because while usernames can be changed by the user any time (meaning their profile link will also change), chat ID of the user is constant over time and the getChat method will always provide you with the most recent information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文