// 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