aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-09-27 12:14:52 +0200
committerNoah Loomans <noahloomans@gmail.com>2017-09-27 12:14:52 +0200
commit512c9689b5124656f37086619087a277262c3e03 (patch)
treef78c112b465accce2f289aa766f17af65cee1c0c
parentdfe3d68edaddd71b020f39ae676ac7e1ec3d7c04 (diff)
Support all types of users
-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`
- }
- ]
})
})