0
Send an image to channel
One script reply has been approved by the moderators Verified
Created by admin 821 days ago Viewed 9287 times
0
Submitted by admin Deno
Verified 821 days ago
1
import type { Base64 } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
2
import { decode } from "https://deno.land/std@0.152.0/encoding/base64.ts";
3

4
type Slack = {
5
  token: string;
6
};
7
export async function main(
8
  image: Base64,
9
  channel: string,
10
  slack: Slack,
11
  imagename: string = "image.png",
12
) {
13
  const formData = new FormData();
14
  formData.append("token", slack.token);
15
  formData.append("file", new File([decode(image)], imagename));
16
  formData.append("channels", channel);
17
  formData.append("filename", "image.png");
18
  formData.append("filetype", imagename);
19

20
  return await (
21
    await fetch("https://slack.com/api/files.upload", {
22
      method: "POST",
23
      body: formData,
24
    })
25
  ).json();
26
}
27