-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (24 loc) · 823 Bytes
/
app.js
File metadata and controls
32 lines (24 loc) · 823 Bytes
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
const express = require('express')
const app = express()
const port = process.env.PORT || 9090
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: true }))
//Creating a test endpoint to ensure server is working as expected.
app.get('/', (req, res) => {
res.status(200).send('Hello World')
})
app.post ('/hello', (req, res, next) => {
let userName = req.body.user_name
let botPayload = {
text: 'Hi ' + userName + ' ! Welcome to the BatCave :bat:'
}
//conditional to prevent infinite loop, only retunr payload if user is NOT slackbot.
if(userName !== 'slackbot') {
return res.status(200).json(botPayload)
} else {
return res.status(200).end()
}
})
app.listen(port, (req, res) => {
console.log(`Listening on port ${port}`)
})