forked from adobe-apiplatform/openwhisk-kegbot-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack-action.js
executable file
·54 lines (46 loc) · 1.61 KB
/
slack-action.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
/*
* @returns {Promise}
*/
function main(params) {
return new Promise(
(resolve, reject) => {
//send message to slack channel
try {
var IncomingWebhook = require("@slack/client").IncomingWebhook;
} catch (err) {
console.log(err);
reject({
"message": "Could not load @slack/client",
"error": err.toString()
}
);
}
if(params !== null && params.slack_webhook_url !== null)
{
var url = params.slack_webhook_url;
var webhook = new IncomingWebhook(url);
var slack_message_text = 'Hello there from JS';
console.log(params);
if(params !== null && params.source !== null && params.source === "creative-cloud" && params.asset !== null )
{
slack_message_text = 'Creative Cloud Event : ' + params.type + ' of type ' + params.asset.mime_type;
}
webhook.send(slack_message_text,
function (err, res) {
if (err) {
console.log('Error:', err);
reject(params);
} else {
console.log('Message sent: ', res);
resolve(params);
}
});
}
else
{
resolve({payload: params});
}
}
);
}
export default main;