-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (40 loc) · 1.29 KB
/
server.js
File metadata and controls
47 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
const express = require('express')
const Slapp = require('slapp')
const ConvoStore = require('slapp-convo-beepboop')
const Context = require('slapp-context-beepboop')
const Bot = require('./bot.js');
// Global variables
var bot = new Bot();
// use `PORT` env var on Beep Boop - default to 3000 locally
var port = process.env.PORT || 3000
var slapp = Slapp({
// Beep Boop sets the SLACK_VERIFY_TOKEN env var
verify_token: process.env.SLACK_VERIFY_TOKEN,
convo_store: ConvoStore(),
context: Context()
})
//*********************************************
// Setup different handlers for messages
//*********************************************
// FIXME temporary to test tasks generation
slapp.message('tasks', ['mention'], (msg) => {
bot.listTasks(msg, false);
})
slapp.action('pick_task_callback', 'pick', (msg, value) => {
console.log(msg);
// the task group id is msg.body.attachment_id - 1
bot.assignTask(msg.body.user, msg.body.attachment_id - 1, value);
// list the tasks again to remove the button
bot.listTasks(msg, true);
})
// attach Slapp to express server
var server = slapp.attachToExpress(express())
// start http server
server.listen(port, (err) => {
if (err) {
return console.error(err);
}
console.log(`Listening on port ${port}`);
bot.generateTasks();
})