Send app report

Script slack Verified

by hugo697 ยท 11/29/2023

The script

Submitted by hugo697 Bun
Verified 5 days ago
1
import { WebClient } from "@slack/web-api";
2
import * as wmill from "windmill-client";
3
import { S3Object } from "windmill-client";
4

5
type Slack = {
6
  token: string;
7
};
8

9
/**
10
 * Send app report
11
 * Upload an app report (PDF or PNG) from Windmill object storage to a Slack channel.
12
 */
13
export async function main(
14
  slack: Slack,
15
  channel: string,
16
  screenshot: S3Object,
17
  app_path: string,
18
  kind: "pdf" | "png",
19
) {
20
  const bytes = await wmill.loadS3File(screenshot);
21
  if (!bytes) {
22
    throw new Error("Could not load the file from object storage");
23
  }
24

25
  const fullAppPath =
26
    Bun.env["WM_BASE_URL"] +
27
    "/apps/get/" +
28
    app_path +
29
    "?workspace=" +
30
    Bun.env["WM_WORKSPACE"];
31

32
  const client = new WebClient(slack.token);
33
  return await client.filesUploadV2({
34
    channel_id: channel,
35
    file: Buffer.from(bytes),
36
    filename: "report." + kind,
37
    initial_comment: "App report of " + " <" + fullAppPath + "|" + app_path + ">",
38
  });
39
}
40