Send error to slack channel

Script· failure slack Verified

by rubenfiszel · 1/30/2023

The script

Submitted by hugo989 Bun
Verified 6 days ago
1
import { WebClient } from "@slack/web-api";
2

3
type Slack = {
4
  token: string;
5
};
6
export async function main(
7
  message: string,
8
  name: string,
9
  channel: string,
10
  slack: Slack,
11
) {
12
  const web = new WebClient(slack.token);
13
  const flow_id = Bun.env.WM_FLOW_JOB_ID;
14
  const text = (message = `Flow [${flow_id}](${Bun.env
15
    .WM_BASE_URL}/run/${flow_id}?workspace=${Bun.env
16
    .WM_WORKSPACE}) had an error:\n${name}: ${message}`);
17
  await web.chat.postMessage({
18
    channel,
19
    text,
20
  });
21
  return { message, flow_id };
22
}
23

Other submissions
  • Submitted by rubenfiszel Deno
    Created 398 days ago
    1
    import { WebClient } from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    type Slack = {
    4
      token: string;
    5
    };
    6
    export async function main(
    7
      message: string,
    8
      name: string,
    9
      channel: string,
    10
      slack: Slack,
    11
    ) {
    12
      const web = new WebClient(slack.token);
    13
      const flow_id = Deno.env.get("WM_FLOW_JOB_ID");
    14
      const text = (message = `Flow [${flow_id}](${Deno.env.get(
    15
        "WM_BASE_URL",
    16
      )}/run/${flow_id}?workspace=${Deno.env.get(
    17
        "WM_WORKSPACE",
    18
      )}) had an error:\n${name}: ${message}`);
    19
      await web.chat.postMessage({
    20
        channel,
    21
        text,
    22
      });
    23
      return { message, flow_id };
    24
    }
    25