run a job that sends a message to Slack

Script windmill Verified

by admin ยท 10/22/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * run a job that sends a message to Slack
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    hub_script_path?: string;
9
    channel?: string;
10
    test_msg?: string;
11
    [k: string]: unknown;
12
  }
13
) {
14
  const url = new URL(
15
    `${BASE_URL}/api/w/${workspace}/workspaces/run_slack_message_test_job`
16
  );
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "Bearer " + WM_TOKEN,
23
    },
24
    body: JSON.stringify(body),
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.text();
31
}
32