forked from BeepBoopHQ/starter-node-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
171 lines (130 loc) · 4.3 KB
/
Copy pathindex.js
File metadata and controls
171 lines (130 loc) · 4.3 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var Botkit = require('botkit')
var http = require('http');
var querystring = require('querystring')
var kinveyRequest = function(mode, id, date)
{
var options = {
hostname: 'baas.kinvey.com',
protocol: 'http:',
path: '/rpc/kid_Zk0NE5LXpg/custom/confirmation?mode=' + mode,
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic a2lkX1prME5FNUxYcGc6YjZmMjU3NjU0YmIwNDY4YzllZTI1MjgyNTNhMmI3NWI='
}
};
// var options = {
// hostname: 'requestb.in',
// path: '/ywaq7oyw',
// port: 80,
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Basic a2lkX1prME5FNUxYcGc6YjZmMjU3NjU0YmIwNDY4YzllZTI1MjgyNTNhMmI3NWI='
// }
// };
var req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});
// write data to request body
req.write(`{"id" : "${id}", "date" : "${date}"}`);
req.end();
};
var PORT = process.env.PORT || 8080
var TOKEN = process.env.SLACK_TOKEN
var VERIFY_TOKEN = process.env.SLACK_VERIFY_TOKEN
var controller = Botkit.slackbot({
// reconnect to Slack RTM when connection goes bad
retry: Infinity,
debug: false
})
var bot = controller.spawn({token: TOKEN}).startRTM()
bot.api.team.info({}, function(err, res){
if(err){
return console.error(err)
}
controller.storage.teams.save({id: res.team.id}, (err) => {
if(err){
console.error(err)
}
})
})
controller.setupWebserver(PORT, function (err, webserver) {
if (err) {
console.error(err)
process.exit(1)
}
//webserver.use(logger('tiny'))
// Setup our slash command webhook endpoints
controller.createWebhookEndpoints(webserver)
})
controller.on('bot_channel_join', function (bot, message) {
bot.reply(message, "I'm here!")
})
controller.hears(['hello', 'hi'], ['direct_mention'], function (bot, message) {
bot.reply(message, 'Hello.')
})
controller.hears(['helloo', 'hie'], ['direct_message'], function (bot, message) {
bot.reply(message, 'Hello.')
bot.reply(message, 'It\'s nice to talk to you directly.')
})
controller.hears('.*', ['mention'], function (bot, message) {
bot.reply(message, 'You really do care about me. :heart:')
})
controller.hears('help', ['direct_message', 'direct_mention'], function (bot, message) {
var help = 'I will respond to the following messages: \n' +
'`bot hi` for a simple message.\n' +
'`bot attachment` to see a Slack attachment message.\n' +
'`@<your bot\'s name>` to demonstrate detecting a mention.\n' +
'`bot help` to see this again.'
bot.reply(message, help)
})
controller.hears(['attachment'], ['direct_message', 'direct_mention'], function (bot, message) {
var text = 'Beep Beep Boop is a ridiculously simple hosting platform for your Slackbots.'
var attachments = [{
fallback: text,
pretext: 'We bring bots to life. :sunglasses: :thumbsup:',
title: 'Host, deploy and share your bot in seconds.',
image_url: 'https://storage.googleapis.com/beepboophq/_assets/bot-1.22f6fb.png',
title_link: 'https://beepboophq.com/',
text: text,
color: '#7CD197'
}]
bot.reply(message, {
attachments: attachments
}, function (err, resp) {
console.log(err, resp)
})
})
controller.hears('.*', ['direct_message', 'direct_mention'], function (bot, message) {
bot.reply(message, 'Sorryyyy <@' + message.user + '>, I don\'t understand. \n')
})
controller.on('interactive_message_callback', function(bot, message) {
// check message.actions and message.callback_id to see what action to take...
var message_callback = message.callback_id.split('-');
if(message.actions[0].name == "si")
{
bot.replyInteractive(message, {
text: 'Gracias por confirmar:thumbsup:'
});
kinveyRequest("present", message_callback[0], message_callback[1]);
}
else{
bot.replyInteractive(message, {
text: 'Gracias por notificarnos :thumbsup: Se buscara un *substituto*'
});
//kinveyRequest("abscent", message_callback[0], message_callback[1]);
}
});