aboutsummaryrefslogtreecommitdiff
path: root/src/server/routes/slack.js
blob: 780e7c08666e4c0aacec71065206b2793a830cf4 (plain)
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
const express = require('express')
const router = express.Router()

const getUserIndex = require('../lib/getUserIndex')

router.all('/', function (req, res, next) {
  getUserIndex().then(users => {
    const query = req.body.text
    const user =
      users.filter(user => user.value === query)[0]

    if (!user) {
      res.json({
        "response_type": "ephemeral",
        "mrkdwn": true,
        "text": `Sorry, I tried my best, but I couldn't find _${query}_`
      })
      return
    }

    res.json({
      "response_type": "in_channel",
      "text": `Here is the schedule of _${query}_`,
      "mrkdwn": true,
      "attachments": [
        {
          "fallback": `https://beta.rooster.hetmml.nl/${user.type}/${user.value}`,
          "image_url": `https://beta.rooster.hetmml.nl/get/${user.type}/${user.value}.png`
        }
      ]
    })
  })
})

module.exports = router