Skip to content

Conversation

@JhnBer
Copy link
Contributor

@JhnBer JhnBer commented Aug 21, 2025

No description provided.

Copy link
Member

@punyflash punyflash left a 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);
Copy link
Member

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): bool

In 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.

Copy link
Member

@punyflash punyflash Aug 22, 2025

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.

@punyflash punyflash changed the title Telebot 3.x to 4.x breaking changes fix Refactor RequestInputHandler to use Chat ID Aug 22, 2025
@punyflash punyflash added the enhancement New feature or request label Aug 22, 2025
JhnBer added 4 commits August 25, 2025 08:10
- support request by User|Chat $target, and additional User and thread_id params
@JhnBer JhnBer requested a review from punyflash August 25, 2025 07:25
@punyflash
Copy link
Member

Huge thanks!

@punyflash punyflash merged commit 817e3dd into westacks:4.x Aug 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants