Search... Ctrl + K

Send an image to channel (slack)
One script reply has been approved by the moderators Verified

Created by admin 116 days ago Used 37 times 0 Points

No comments yet

Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import type {
  Base64,
  Resource,
} from "https://deno.land/x/windmill@v1.30.0/mod.ts";
import { decode } from "https://deno.land/std@0.152.0/encoding/base64.ts";

export async function main(
  image: Base64,
  channel: string,
  slack: Resource<"slack">,
  imagename: string = "image.png",
) {
  const formData = new FormData();
  formData.append("token", slack.token);
  formData.append(
    "file",
    new File([decode(image)], imagename),
  );
  formData.append("channels", channel);
  formData.append("filename", "image.png");
  formData.append("filetype", imagename);

  return await (await fetch("https://slack.com/api/files.upload", {
    method: "POST",
    body: formData,
  })).json();
}

Submitted by admin 116 days ago

Edited 116 days ago

No comments yet