-
-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor RequestInputHandler to use Chat ID #132
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
Conversation
- RequestInputHandler.php breaking changes fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be glad if you could implement this as you touched it. Thanks for pointing it out. Would be nice if you could cover the new behavior with unit tests as well
| public static function request(TeleBot $bot, User|Chat $target): bool | ||
| { | ||
| return static::storage($bot)->set($user->id, static::class); | ||
| return static::storage($bot)->set($target->id, static::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chat and User are different entities. Their IDs match in case it's a private chat with the bot, but in case it's group/supergroup/channel, they will be different. If you check the trigger method, you can see that currently handler matches by User's ID, and it should not be changed this way. I agree that Chat should be used primary in this case, though. That's a bottleneck I forgot to fix when was releasing 4.x.
If you want to add checks for Chat ID, the correct and backward compatible way to do it will be this:
public static function request(TeleBot $bot, Chat|User $target, ?User $user = null): boolIn that case, we can cover those 3 scenarios:
RequestInputHandler::request($bot, $user): awaits message in ANY chat from SPECIFIC user (current behavior)RequestInputHandler::request($bot, $chat): awaits message in SPECIFIC chat from ANY user (will work for private chats in a same way, but also useful for group chats)RequestInputHandler::request($bot, $chat, $user): awaits message in SPECIFIC chat from SPECIFIC user (mainly for group chats)
I think we can store keys in format, something like user_<id>, chat_<id> and chat_<id>_user_<id>. trigger method should be refactored as well to read those keys correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also forgot another case, there is message_thread_id, which is also the case where you could possibly want to match the message (in supergroups). Can be added as another optional parameter as well. If you add it, there also should be a check that current chat is supergroup, before storing it.
This reverts commit fd2794c.
- support request by User|Chat $target, and additional User and thread_id params
|
Huge thanks! |
No description provided.