Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
added slack event listener - #4
Browse files Browse the repository at this point in the history
  • Loading branch information
nprail committed Jun 8, 2018
1 parent d399132 commit f5fca88
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 33 deletions.
134 changes: 102 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"author": "Filiosoft Open Source <[email protected]>",
"license": "MIT",
"dependencies": {
"@slack/events-api": "^1.0.1",
"body-parser": "^1.18.3",
"botkit": "^0.6.14",
"cookie-session": "^2.0.0-beta.3",
"dotenv": "^5.0.1",
Expand Down
3 changes: 3 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ require('./config/mongo')(config)
// configure passport
require('./config/passport')(app, config)

// configure slack
require('./config/slack')(app, config)

// configure routes
require('./routes')(app, config)

Expand Down
5 changes: 4 additions & 1 deletion server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const config = {
gitlabAppId: process.env.GITLAB_APP_ID,
gitlabAppSecret: process.env.GITLAB_APP_SECRET,
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
dbUri: process.env.MONGODB_URI || 'mongodb://localhost:27017/glib'
dbUri: process.env.MONGODB_URI || 'mongodb://localhost:27017/glib',
slack: {
verificationToken: process.env.SLACK_VERIFICATION_TOKEN
}
}

module.exports = config
3 changes: 3 additions & 0 deletions server/config/express.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cookieSession = require('cookie-session')
const exphbs = require('express-handlebars')
const bodyParser = require('body-parser')

module.exports = (app, config) => {
app.engine(
Expand All @@ -11,6 +12,8 @@ module.exports = (app, config) => {
)
app.set('view engine', '.hbs')

// You must use a body parser for JSON before mounting the adapter
app.use(bodyParser.json())
// cookieSession config
app.use(
cookieSession({
Expand Down
21 changes: 21 additions & 0 deletions server/config/slack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const sea = require('@slack/events-api')

module.exports = (app, config) => {
const slackEvents = sea.createSlackEventAdapter(
config.slack.verificationToken
)

app.use('/slack/events', slackEvents.expressMiddleware())

// Attach listeners to events by Slack Event "type". See: https://api.slack.com/events/message.im
slackEvents.on('message', event => {
console.log(
`Received a message event: user ${event.user} in channel ${
event.channel
} says ${event.text}`
)
})

// Handle errors (see `errorCodes` export)
slackEvents.on('error', console.error)
}

0 comments on commit f5fca88

Please sign in to comment.