1 | import { WebClient } from '@slack/web-api'; |
2 | import dayjs from "dayjs"; |
3 |
|
4 | type Slack = { |
5 | token: string; |
6 | }; |
7 |
|
8 | export async function main( |
9 | path: string, |
10 | is_flow: boolean, |
11 | schedule_path: string, |
12 | success_result: object, |
13 | success_started_at: string, |
14 | slack: Slack, |
15 | channel: string, |
16 | ) { |
17 | const baseUrl = process.env["WM_BASE_URL"]; |
18 | const scheduleUrl = baseUrl + "/runs?schedule_path=" + |
19 | encodeURIComponent(schedule_path); |
20 | const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") + |
21 | path; |
22 | const web = new WebClient(slack.token); |
23 |
|
24 | await web.chat.postMessage({ |
25 | channel, |
26 | text: `Schedule ${schedule_path} was successful`, |
27 | blocks: [ |
28 | { |
29 | "type": "section", |
30 | "text": { |
31 | "type": "mrkdwn", |
32 | "text": `*Schedule <${scheduleUrl}|${schedule_path}> was successful*:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`, |
33 | }, |
34 | }, |
35 | ], |
36 | attachments: [ |
37 | { |
38 | color: "#00ff00", |
39 | "blocks": [ |
40 | { |
41 | "type": "section", |
42 | "text": { |
43 | "type": "mrkdwn", |
44 | "text": `Started at: ${dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)") |
45 | }\n\`\`\`\n${JSON.stringify(success_result)}\n\`\`\``, |
46 | }, |
47 | }, |
48 | ], |
49 | }, |
50 | ], |
51 | }); |
52 | } |