diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-09-27 12:57:19 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-09-27 12:57:19 +0200 |
commit | 71aea288b5e54cc68793b6b133b4efb55812699d (patch) | |
tree | ebfc11d37982e016a835c98297d7a7f75f7959b1 /src/server/routes | |
parent | 19f6b19ce8d7f434b669887b86bcf78b2241f22f (diff) |
Add !help to slack bot
Diffstat (limited to 'src/server/routes')
-rw-r--r-- | src/server/routes/slack.js | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/server/routes/slack.js b/src/server/routes/slack.js index 780e7c0..e256f14 100644 --- a/src/server/routes/slack.js +++ b/src/server/routes/slack.js @@ -3,22 +3,20 @@ const router = express.Router() const getUserIndex = require('../lib/getUserIndex') -router.all('/', function (req, res, next) { - getUserIndex().then(users => { - const query = req.body.text +function generateResponse(query) { + return getUserIndex().then(users => { const user = users.filter(user => user.value === query)[0] if (!user) { - res.json({ + return { "response_type": "ephemeral", "mrkdwn": true, "text": `Sorry, I tried my best, but I couldn't find _${query}_` - }) - return + } } - res.json({ + return { "response_type": "in_channel", "text": `Here is the schedule of _${query}_`, "mrkdwn": true, @@ -28,8 +26,35 @@ router.all('/', function (req, res, next) { "image_url": `https://beta.rooster.hetmml.nl/get/${user.type}/${user.value}.png` } ] - }) + } }) +} + +router.all('/', function (req, res, next) { + const query = req.body.text || req.query.text + + if (query.indexOf('!') === 0) { + switch (query) { + case "!help": + res.json({ + "response_type": "ephemeral", + "mrkdwn": true, + "text": "Here are some examples on how you can use me\n>/rooster 18561\n\n>/rooster akh\n\n>/rooster 6-5H2\n\n>/rooster 008-mk\n\nPlease note that the following does not work (yet)", + "attachments": [{ + "text": "/rooster 5h2", + "color": "danger" + }] + }) + default: + res.json({ + "response_type": "ephemeral", + "text": "Unrecognized command, try !help" + }) + break; + } + } + + generateResponse(query).then((json) => res.json(json)) }) module.exports = router |