-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add Listener options and filtering hooks #724
Conversation
I like this. What do you think @technicalpickles |
Forgot to add async as a dependency for hubot |
Any chance of getting this merged? Is there anything I can do that would help? |
@@ -85,7 +86,7 @@ class Robot | |||
# callback - A Function that is called with a Response object. | |||
# | |||
# Returns nothing. | |||
respond: (regex, callback) -> | |||
respond: (regex, options, callback) -> |
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.
This would break all existing scripts. Maybe check the type of these arguments, and assign options to callback if it's a function?
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.
Looks like that is actually being handled in the TextListener constructor.
Any relevant updates to docs/scripting.md would be super helpful, otherwise no one would be able to discover you can do this without diving into the code. |
hook(@robot, this, @options, msg, cb) | ||
|
||
# Execute all hooks | ||
async.parallel wrappedHooks, (err, results) -> |
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.
Why parallel? Listeners are generally invoked in series, so it might not be obvious that hooks work different.
Also, shouldn't we be doing something with this err
?
Listener.hooks.push (robot, listener, options, message, cb) -> All interactions with hubot are done through the |
anyListenersExecuted = anyListenersExecuted || listenerExecuted | ||
cb(message.done) | ||
catch err | ||
# TODO provide useful info after catching an error (like a stacktrace!) |
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.
Is this comment stale? If you get an err, you it should have the stacktrace at this point.
So, it turns out this is something I've wanted for awhile, but I was just calling it something different: middleware. I had envisioned something like, passing a script name to a respond block, and then tracking metrics around how often it's called, or logging when scripts respond. Stuff like that. Middleware might have certain connotations though. Usually, you are either preventing the real action from happening, or preparing results for other hooks and/or the real action I'm not sure if I like To recap, my current concerns are:
|
Thanks for the feedback! I'll start addressing each concern right away. |
Wow, its been 3 weeks. Sorry about that. I did a lot of thinking about what it feels like we are trying to solve here and realized that:
First, a big fancy diagram of the current flow and a potential new flow (new flow is just adding in some new steps): https://www.lucidchart.com/documents/view/b7eade23-4254-45af-b164-2ad54674e61b/0 Current flow explained as I understand it:
Now, in the new flow, I am proposing we just extend the existing flow with three new constructs:
With all of that described out, I am realizing that it still doesn't solve my original problem of wanting to glue company-specific auth logic on top of existing scripts without having to fork every single hubot script. I think I might be able to implement it with some potentially crazy code inside a filter, but I'm not convinced I want to go there. Ideas welcome here... |
Just discovered http://github.com/Hammertime38/hubot-proxy, which looks like it may address some of the hooks. |
Based on the updates to #768, I'm going to work on rebuilding this in smaller pieces. I expect the end result to be a collection of individual pieces that eventually enable a variety of extensions like external authorization policy, rate limiting, and conditional audit logging. |
Enable Listener hooks that allow for complex match rules.
Example: only execute commands for users who have performed 2FA with hubot.