Edits history of script submission #22359 for ' Ask channel for approval (discord)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    import { getResumeUrls } from "windmill-client@1";
    
    type DiscordWebhook = {
      webhook_url: string;
    };
    
    export async function main(discord_webhook: DiscordWebhook, message: string = "A flow is requesting an approval to be resumed") {
    
      const { approvalPage } = await getResumeUrls();
    
      const fullMessage = `${message} [approval page](${approvalPage})`;
    
      const response = await fetch(`${discord_webhook.webhook_url}?wait=true`, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ content: fullMessage }),
      });
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`);
      }
      return await response.json();
    }
    

    Submitted by hugo989 6 days ago