aiogram / aiogram

aiogram is a modern and fully asynchronous framework for Telegram Bot API written in Python using asyncio
https://aiogram.dev
MIT License
4.54k stars 819 forks source link

Improving mentions in group chats: Implementing username recognition and optimizing mentions #1237

Closed NurgisaA closed 1 year ago

NurgisaA commented 1 year ago

I use for example the command in group chats /rp User1 @user2 ...

User - has type text_mention and can get id @user1 - does not have username or id

I can get by offset and length username. But when searching the database, I can't be sure that the user hasn't changed username. Is there any way to avoid errors and does telegram api support it?

[MessageEntity(type='bot_command', offset=0, length=3, url=None, user=None, language=None, custom_emoji_id=None), MessageEntity(type='text_mention', offset=4, length=7, url=None, user=User(id=0000000000, is_bot=False, first_name='first name', last_name=None, username=None, language_code=None, is_premium=None, added_to_attachment_menu=None, can_join_groups=None, can_read_all_group_messages=None, supports_inline_queries=None), language=None, custom_emoji_id=None), MessageEntity(type='mention', offset=12, length=10, url=None, user=None, language=None, custom_emoji_id=None)]

JrooTJunior commented 1 year ago

Telegram has no methods to get user by username.

If you want to know usernames you should save (and update) it from ALL incoming messages to some storage (DB) but you don't have and you can't have any guarantees of data relevance.

JrooTJunior commented 1 year ago

I will close this issue, if you have further questions, please open a new issue or discussion.