-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
47 lines (39 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var express = require('express')
var morgan = require('morgan')
var bodyParser = require('body-parser')
var VERIFY_TOKEN = process.env.SLACK_VERIFY_TOKEN
if (!VERIFY_TOKEN) {
console.error('SLACK_VERIFY_TOKEN is required')
process.exit(1)
}
var PORT = process.env.PORT
if (!PORT) {
console.error('PORT is required')
process.exit(1)
}
var app = express()
app.use(morgan('dev'))
app.route('/beepboop')
.get(function (req, res) {
res.sendStatus(200)
})
.post(bodyParser.urlencoded({ extended: true }), function (req, res) {
if (req.body.token !== VERIFY_TOKEN) {
return res.sendStatus(401)
}
var message = 'boopbeep'
// Handle any help requests
if (req.body.text === 'help') {
message = "Sorry, I can't offer much help, just here to beep and boop"
}
res.json({
response_type: 'ephemeral',
text: message
})
})
app.listen(PORT, function (err) {
if (err) {
return console.error('Error starting server: ', err)
}
console.log('Server successfully started on port %s', PORT)
})