-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (36 loc) · 1.33 KB
/
server.js
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
var Botkit = require('botkit') // require botkit module
var token = process.env.SLACK_TOKEN // get slack token passed as variable
// Setup new slackbot with botkit
var controller = Botkit.slackbot({
debug: false,
json_file_store: 'data'
});
// Check that token was passed
if (!token) {
console.error('SLACK_TOKEN is required')
}
// Start Slack’s Bot Real Time Messaging API (RTM)
controller.spawn({
token: token
}).startRTM(function(err,bot,payload) {
if (err) {
throw new Error(err)
}
});
controller.hears(['hi'], ['direct_mention','direct_message'], function(bot, message) {
var userID = message.user // the ID of the user that mentioned 'up'
var user = "<@"+userID+">" // wrap around like this to create an @ mention of the user
controller.storage.users.save({id: message.user, objectives:"Object content *here*"});
bot.reply(message, {
text: "Nice to meet you " + user
}); // send reply
})
controller.hears(['objectives'], ['direct_mention','direct_message'], function(bot, message) {
var userID = message.user // the ID of the user that mentioned 'up'
var user = "<@"+userID+">" // wrap around like this to create an @ mention of the user
controller.storage.users.get(message.user, function(err, user_data) {
bot.reply(message, {
text: user + ' ' + user_data.objectives
});
});
})