-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.js
31 lines (26 loc) · 944 Bytes
/
slack.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
// require modules needed to send Slack messages
const { WebClient } = require('@slack/client');
// export module for main script
module.exports = {
dashHandler : function (sender, providerConfig) {
postMessage(sender, providerConfig);
}
};
// postMessage uses the Slack api's method chat.postMessage
// Documentation:
// https://api.slack.com/methods/chat.postMessage
function postMessage(sender, providerConfig) {
const web = new WebClient(providerConfig.token);
let arguments = {};
for (let [key, value] of Object.entries(providerConfig)) {
arguments[key] = value;
}
for (let [key, value] of Object.entries(sender.providerConfig)) {
arguments[key] = value;
}
web.chat.postMessage(arguments).then((res) => {
console.log('Slack: Sent message: ', res.message.text);
}).catch(error => {
console.error('Slack: an error occurred: ', error.data.error);
});
}