-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
128 lines (118 loc) · 3.39 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const IncomingWebhook = require('@slack/client').IncomingWebhook;
const shortid = require("shortid");
const url = 'https://hooks.slack.com/services/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';
let actions = [];
actions.push({
options: {
username: "Projeto "+shortid.generate(),
"attachments": [{
"title": "Projeto criado",
"author_name": "diogenesjcs",
"color": "#3F51B5"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
"attachments": [{
"title": "Projeto removido",
"author_name": "diogenesjcs",
"color": "#F44336"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
text: "",
"attachments": [{
"title": "Projeto atualizado",
"text": "Adicionada funcionalidade de criação de usuários de forma dinâmica.",
"author_name": "diogenesjcs",
"color": "#009688"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
text:"",
"attachments": [{
"title": "Projeto atualizado",
"text": "Removida funcionalidade de criação de usuários de forma dinâmica.",
"author_name": "diogenesjcs",
"color": "#009688"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
text:"",
"attachments": [{
"title": "Projeto atualizado",
"text": "Adicionada conexão com banco de dados MongoDB",
"author_name": "diogenesjcs",
"color": "#009688"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
text:"",
"attachments": [{
"title": "Relatório",
"text": "Criado modelo de relatório PDF",
"author_name": "diogenesjcs",
"color": "#607D8B"
}]
}
});
actions.push({
options: {
username: "Projeto "+shortid.generate(),
text:"",
"unfurl_media": true,
"attachments": [{
"fallback": "Required plain-text summary of the attachment.",
"title": "Bug",
"text": "Problema na conexão de campo de formulário",
"author_name": "diogenesjcs",
"image_url" : "http://static.ziggi.uol.com.br/imagens_programas/screenshots/big_1355505946_10994.jpg",
"thumb_url" : "http://static.ziggi.uol.com.br/imagens_programas/screenshots/big_1355505946_10994.jpg",
"color": "#000000"
}]
}
});
const shuffle = (a) => {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
const randomInt = (low, high) => {
return Math.floor(Math.random() * (high - low) + low);
}
const randomMessages = (url, actions) => {
shuffle(actions);
if(actions.length>0)
sendMessage(url, actions.shift().options);
};
const sendMessage = (url, options) => {
const webhook = new IncomingWebhook(url, options);
webhook.send(options, function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Message sent: ', res);
}
});
};
setInterval(() => {
randomMessages(url, actions)
}, 5000);