电报机器人如何从他们发送的消息中获取到用户配置文件的链接
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拥有用户名是电报的可选,设置它意味着其他人将能够在不知道电话号码的情况下与用户联系。只有在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.