Skip to content
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

Receive middleware docs tweaks #1038

Merged
merged 2 commits into from
Aug 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,15 @@ BLACKLISTED_USERS = [

robot.receiveMiddleware (context, next, done) ->
if context.response.message.user.id in BLACKLISTED_USERS
# Don't process this message further.
context.response.message.finish()

# If the message starts with 'hubot' or the alias pattern, this user was
# explicitly trying to run a command, so respond with an error message.
if context.response.message.text?.match(robot.respondPattern(''))
context.response.reply "I'm sorry @#{context.response.message.user.name}, but I'm configured to ignore your commands."
context.response.message.finish()

# Don't process further middleware.
done()
else
next(done)
Expand All @@ -779,7 +785,6 @@ Receive middleware callbacks receive three arguments, `context`, `next`, and
`done`. See the [middleware API](#execution-process-and-api) for a description
of `next` and `done`. Receive middleware context includes these fields:
- `response`
- all parts of the standard response API are included in the middleware API. See [Send & Reply](#send--reply).
- this response object will not have a `match` property, as no listeners have been run yet to match it.
- middleware may decorate the response object with additional information (e.g. add a property to `response.message.user` with a user's LDAP groups)
- middleware may modify the `response.message` object
- note: the textual message (`response.message.text`) should be considered immutable in listener middleware