Skip to content

Instantly share code, notes, and snippets.

@hashedhyphen
Last active May 4, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashedhyphen/e25c64094a3738d2efb42459f26fcd06 to your computer and use it in GitHub Desktop.
Save hashedhyphen/e25c64094a3738d2efb42459f26fcd06 to your computer and use it in GitHub Desktop.
// https://github.com/slackapi/bolt/blob/43b8b78042752778484edd6018a37464bbfae2f5/src/middleware/builtin.ts#L208-L23
function matchText(pattern) {
return async ({ event, context, next }) => {
let tempMatches
if (event.text === undefined) {
return
}
// Filter out messages that don't contain the pattern
if (typeof pattern === "string") {
if (!event.text.includes(pattern)) {
return
}
} else {
tempMatches = event.text.match(pattern)
if (tempMatches !== null) {
context["matches"] = tempMatches
} else {
return
}
}
await next()
}
}
app.event("app_mention", matchText("ping"), async ({ event, say }) => {
// do stuff
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment