-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 978 Bytes
/
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
const core = require('@actions/core');
const { WebClient, ErrorCode } = require('@slack/web-api');
async function run() {
try {
const token = await core.getInput('token', { required: true });
const param = await core.getInput('payload', { required: true });
const web = new WebClient(token);
console.log('Input:', param);
const payload = JSON.parse(param);
console.log('Output:', JSON.stringify(payload));
return web.chat.postMessage(payload)
.then((result) => {
// The result contains an identifier for the message, `ts`.
console.log(`Successfully send message ${result.ts}`);
})
.catch((err) => {
if (err.code === ErrorCode.PlatformError) {
console.log(err.data);
} else {
console.log(err);
}
core.setFailed("Failed to send slack message");
});
} catch(err) {
console.log(err);
core.setFailed("Failed to send slack message");
}
}
run();