1
Send app report
One script reply has been approved by the moderators Verified
Created by hugo697 152 days ago Viewed 5170 times
0
Submitted by hugo697 Bun
Verified 152 days ago
1
type Slack = {
2
  token: string;
3
};
4
type Base64 = string
5
export async function main(
6
  slack: Slack,
7
  channel: string,
8
  screenshot: Base64,
9
  app_path: string,
10
  kind: 'pdf' | 'png',
11
) {
12
  const formData = new FormData();
13
  formData.append("token", slack.token);
14
  formData.append("file", new Blob([Buffer.from(screenshot, "base64")], {
15
    type: kind === "pdf" ? "application/pdf" : "image/png"
16
  }), "report." + kind);
17
  formData.append("channels", channel);
18
  const fullAppPath = Bun.env["WM_BASE_URL"] + '/apps/get/' + app_path + '?workspace=' + Bun.env["WM_WORKSPACE"]
19
  formData.append("initial_comment", "App report of " + " <" + fullAppPath + "|" + app_path + ">");
20
  return await (
21
    await fetch("https://slack.com/api/files.upload", {
22
      method: "POST",
23
      body: formData,
24
    })
25
  ).json();
26
}
27