Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to be mentioned with a text_mention even when they have a username #26863

Open
jez9999 opened this issue Sep 28, 2023 · 5 comments
Open

Comments

@jez9999
Copy link

jez9999 commented Sep 28, 2023

Is your feature request related to a problem?

So here's the thing: I'd like to be able to specify to my bot which users are added to a particular list, by user ID. That's the only thing attached to a user that won't change so the username is no good, it has to be user ID. In my group, I need to be able to say something like:

/someFeature@MyBot adduser JoeBloggs

If the user doesn't have a username, great, I can just hit @JoeB, hit tab, and the Telegram app will let me mention the user. My bot will receive a text_mention message entity including their user ID.

But if they do have a username - say "jb123" - the Telegram app will mention the user using @jb123, and all my bot gets is a mention message entity with a string that has their username. Telegram provides no mechanism to get the user ID from the username, so my bot has no way to get the user's ID.

Describe the solution you'd like

The Telegram client should provide some mechanism to choose to mention users by text_mention, even if the user has a username, allowing the message to include the user's user ID.

Describe alternatives you've considered

Telegram's bot API could either provide a way to lookup user ID by username, or just provide the user ID with a mention message entity. Unfortunately it doesn't, and for some reason they've not added anything like this in years so it looks like it won't ever happen.

I've also seen the suggestion that your bot could track users in a group as they join and associate them in its own database with username, holding onto their user ID as well. Apart from the fact that this adds a whole lot of extra baggage for a small gain, it still isn't a reliable way of doing things. Consider that the user joins the group with username "jb123" and you record their user ID along with that username. They then change their username to "jb234". Now I type:

/someFeature@MyBot adduser @jb234

The bot doesn't know about jb234 because it still has the user's old username. So as far as I can tell there is literally no reliable way for a bot to get the user's ID by username right now, meaning that the only way to tell the bot the user ID is to mention them by text_mention instead.

Additional context

Relevant APIs:

The user would be mentioned with this: https://core.telegram.org/constructor/inputMessageEntityMentionName
... instead of this: https://core.telegram.org/constructor/messageEntityMention

(actually it looks like the latter is just received, and generated automatically by Telegram when it sees an @username)

@Aokromes
Copy link
Collaborator

i supose this needs api support.

@jez9999
Copy link
Author

jez9999 commented Sep 28, 2023

I think the ability to mention by text_mention is actually possible right now? Clearly it'd be nice if the API would provide user ID on a regular @mention too. Does anyone here have the ability to contact the API devs? I've found it virtually impossible to get through to them.

@aNNiMON
Copy link

aNNiMON commented Sep 28, 2023

Telegram X Android allows you to mention a user with username. You type "@Jb1" then long press on a user "JoeBloggs" in the list and the "Mention" popup appears with predefined mention "JoeBloggs" where you can change a name for this user, then the text mention is created and you can continue to type a message. So. I suppose the API support is already there.
Something similar with a long press on the username in a list, but without a popup can be implemented here, I think.

But @jez9999 wouldn't it be easier for your bot to get the user id from the reply? Instead of just sending the command "/someFeature@MyBot adduser JoeBloggs" you can reply to any message from JoeBloggs with the command "/someFeature@MyBot adduser"

@jez9999
Copy link
Author

jez9999 commented Sep 28, 2023

I don't understand your point exactly. If I want to send a command to add a user, why would I have a message from that user to which I could reply?

@jez9999
Copy link
Author

jez9999 commented Nov 27, 2023

Any chance a dev could get this implemented? I'd have thought it might be a day's work. I was gonna try to do it myself but I can't even build thanks to bug #26012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants