-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (88 loc) · 2.63 KB
/
index.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
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
'use strict';
var fs = require('fs');
const redis = require('redis');
const client = redis.createClient();
//Import bot
let Bot = require('./bot.js');
//Import server
let Serve = require('./src/app/server.js')
//Mock JSON
//Bot construction
const bot = new Bot({
token: process.env.SLACK_TOKEN,
autoReconnect: true,
autoMark: true
});
const server = new Serve();
//Hello Message
bot.respondTo('hello', (message, channel, user) => {
bot.send(`Hi, ${user.name}! What can I do for you today?`, channel)
bot.send('You can start by asking me to \`create a docker\` file', channel)
}, true);
//Hello Message
/*bot.respondTo('', (message, channel, user) => {
if(message.text.toLowerCase() != "hello" && message.text.toLowerCase() != "create a docker" && message.text.toLowerCase()!= "yes deploy" && message.text.toLowerCase()!= "commands"){
console.log(message.text.toLowerCase());
bot.send('I donot understand this. Try `commands` ', channel)
}
}, true);
*/
bot.respondTo('commands', (message, channel, user) => {
client.get(user.name, (err, reply) => {
if (err) {
console.log(err);
return;
}
//console.log(JSON.stringify(message) +"MESSAGE")
bot.send("I respond to \n`hello` , `create a docker` or `yes deploy` ", channel);
});
});
//HTML message
bot.respondTo('Create a Docker', (path, channel, user) => {
bot.send('Please fill this form to create a dockerfile\n http://localhost:8081#uid='+user.id, channel);
}, true);
//Redis connection
client.on('error', (err) => {
console.log('Error ' + err);
});
client.on('connect', () => {
console.log('Connected to Redis!');
});
//Storing in Redis
bot.respondTo('store', (message, channel, user) => {
let msg = getArgs(message.text);
console.log(msg);
client.set(user.name, msg, (err) => {
if (err) {
bot.send('Oops! I tried to store that but something went wrong :(', channel);
} else {
bot.send(`Okay ${user.name}, I will remember that for you.`, channel);
}
});
}, true);
bot.respondTo('deploy', (message, channel, user) => {
client.get(user.name, (err, reply) => {
if (err) {
console.log(err);
return;
}
bot.deployImage(function(data){
bot.send("Your app has been deployed at " + data, channel);
});
});
}, true);
//Retrieve from Redis
bot.respondTo('retrieve', (message, channel, user) => {
client.get(user.name, (err, reply) => {
if (err) {
console.log(err);
return;
}
bot.send('Here\'s what I remember: ' + reply, channel);
console.log(`Retrieved: ${reply}`);
});
});
// Take the message text and return the arguments
function getArgs(msg) {
return msg.split(' ').slice(1);
}