aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/routes/slack.js40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/server/routes/slack.js b/src/server/routes/slack.js
index 5dc7047..abd0154 100644
--- a/src/server/routes/slack.js
+++ b/src/server/routes/slack.js
@@ -1,24 +1,34 @@
const express = require('express')
const router = express.Router()
+const getUserIndex = require('../lib/getUserIndex')
+
router.all('/', function (req, res, next) {
- if (!/^[0-9]+$/.test(req.body.text)) {
+ getUserIndex().then(users => {
+ const query = req.query.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": "ephemeral",
- "text": "Only student id's are currently supported, more comming soon!"
+ "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`
+ }
+ ]
})
- return
- }
- res.json({
- "response_type": "in_channel",
- "text": `Here is the schedule of _${req.body.text}_`,
- "mrkdwn": true,
- "attachments": [
- {
- "fallback": `https://beta.rooster.hetmml.nl/s/${req.body.text}`,
- "image_url": `https://beta.rooster.hetmml.nl/get/s/${req.body.text}.png`
- }
- ]
})
})