Skip to content

Instantly share code, notes, and snippets.

@sweetyclem
Created June 6, 2020 18:10
Show Gist options
  • Save sweetyclem/51c5cb47b559e965dc139b30e5a1ef7d to your computer and use it in GitHub Desktop.
Save sweetyclem/51c5cb47b559e965dc139b30e5a1ef7d to your computer and use it in GitHub Desktop.
const { createEventAdapter } = require('@slack/events-api')
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET
const slackEvents = createEventAdapter(slackSigningSecret)
function listenForEvents(app) {
app.use('/events', slackEvents.requestListener())
}
slackEvents.on('app_mention', (event) => {
console.log(`Received an app_mention event from user ${event.user} in channel ${event.channel}`)
})
// All errors in listeners are caught here. If this weren't caught, the program would terminate.
slackEvents.on('error', (error) => {
console.log(`error: ${error}`)
})
module.exports.listenForEvents = listenForEvents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment