-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: combine filters in .wait() method #11
Comments
This is a good suggestion to specify multiple conditions that all need to be true. How would you suggest that people can specify that one of several conditions should be true? For example, I'd like to wait either for a photo, or the |
I think this may add more complexity so I suggest to filter using ctx or something like this:
|
I'm afraid that this won't work well. It implies that the plugin should check if the strings start with Most importantly, it is not a general way of combining the predicates. For example, we also have I agree that combining wait predicates is a desirable thing to do, and I'd love to have a good abstraction. Until now, we can already use I do not consider this issue as blocking. In other words, if we find a great way of combining things, I'd be happy to implement it. However, if we don't, I'll release 1.0 anyway, but in that case I'm of course open to adding it for a future feature release if we happen to find the right abstraction after 1.0. |
I've just known about I suggest postponing this feature after 1.0 release, we may get better ideas :) |
@mi3lix9 what do you think about this? const textOrPhotoMessage = await Promise.race([
conversation.waitFor(':text'),
conversation.waitFor(':photo'),
]) This does not work yet, but it is feasible to implement it. It is the logical OR for any operations. Analogously, it would be great to be able to do this: const text = await Promise.all([
conversation.waitFor(':text'),
conversation.waitFrom(ctx.from?.id),
]) I am not sure if this is possible to implement, but I would not mind to try. It is the logical AND for any operations. If we want, we could add aliases to make it easier to use, such as |
I like it, it is readable and easy to use,
It's easy also to be nested too
|
Correct, that's exactly what I meant. |
It would be cool if we can use forms also
|
Yes, this will automatically be possible if we implement the first suggestions. Forms are just syntactic sugar for |
I tried this piece of code
And it doesn't work It behaves like we haven't added Promise.add at all it needs two updates to work |
Exactly. That's what I meant when I said:
:) |
I compared my idea with yours, and still see your way is great and easy to read. |
for anyone interested: I wrote a very simple work around to combine the following
function waitFromMsg(
ctx: Conversation<SessionContext>,
user: number,
): Promise<Filter<SessionContext, 'message:text'> & { from: User }> {
const predicate = (ctx: SessionContext): ctx is Filter<SessionContext, 'message:text'> & { from: User } =>
ctx.from?.id === user && grammyContext.has.filterQuery('message:text')(ctx)
return ctx.waitUntil(predicate)
} |
|
With the unreleased version 2.0, this suggestion is already possible.
However, if you send a photo, the We can consider making wait calls cancellable via a cancellable promise. This would enable us to implement With v2, every update is only returned from a single wait call. There is no parallel resolving of wait calls. This means that the following suggestion becomes impossible (or rather, it means something else now).
Instead, we can consider returning a promise with extra methods that lets people narrow down the update further. Something based on chaining like |
Currently, it's not possible to combine filters in one code. Instead, every filter has its own function
.waitFor()
,.waitFrom()
, etc...I suggest adding params to
.wait()
function with filters, like this:The text was updated successfully, but these errors were encountered: