aboutsummaryrefslogtreecommitdiff
path: root/src/server/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/routes')
-rw-r--r--src/server/routes/slack.js41
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