-
Notifications
You must be signed in to change notification settings - Fork 12
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
New Plugin: Message Awaiter #13
Comments
This is mainly what I have done making bots for telegram / qq, I'm not sure whether wechaty have more elegant way to do this, sorry if I'm trying to solve an non-exist problem. |
Hi @ssine , thank you very much for explaining your idea in detail, and I fully agree with you that we definitely need a dialog helper function ( This week I'm also thinking about another way to deal with this problem, like the I have left my reviews on your PR, please follow them and do not hesitate to ask me if you have any questions. We will be able to merge it after you switch your related code to use the Looking forward to use your MessageAwaiter plugin, cheers! |
Glad to know that the idea is valuable. Regarding dialog as two streams feels like a higher level of abstraction and would be very useful. I have updated the PR, thanks :) |
close this as PR has merged |
Plugin Name
Message Awaiter
Description
During my experience of developinng bots (telegram, coolq, and newly on wechaty), I find that all the frameworks provide a callback mechanism when message is received. However, this clear and simple api is indirect when developing dialogs with multiple message sending and receiving.
For example, I have a bot that asks what I've done and record it everyday. This happens every 11pm:
so after message 1, 3 are sent, the bot begin to wait for my reply. Such dialog pattern is common and intuitive, but is indirect to implement in EventEmitter's api. To do this, we can make a state machine for each dialog, or pass subsequent logic into callback function, but neither of them matches the simplicity of
await bot.newMessageFrom(...)
.This plugin returns a Promise object that resolves when a new message that satisfies some condition (from whom, text pattern matching, timing) is received (and manages the lifecycle of the listener function), so that the dialog logic in code can continue uninterrupted. The code pattern would look like this:
The text was updated successfully, but these errors were encountered: