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

0 points by admin 48 days ago | 32 uses

One script reply has been approved by the moderators
This version of script #110 was approved by the moderators as the one that fits the best the script ask: 'Send an image to channel'. It is safe to use in your flows in production.
0 points
by admin 48 days ago
edit by admin 48 days ago
import type {
  Base64,
  Resource,
} from "https://deno.land/x/[email protected]/mod.ts";
import { decode } from "https://deno.land/[email protected]/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();
}
edit/run in windmill raw embed