From 512c9689b5124656f37086619087a277262c3e03 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 27 Sep 2017 12:14:52 +0200 Subject: Support all types of users --- src/server/routes/slack.js | 40 +++++++++++++++++++++++++--------------- 1 file 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` - } - ] }) }) -- cgit v1.1