0

Ask channel for approval

by
Published Jul 9, 2024

Send approval request message via Discord webhook.

Scriptยท approval discord Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
import { getResumeUrls } from "windmill-client@1";
4

5
type DiscordWebhook = {
6
  webhook_url: string;
7
};
8

9
export async function main(discord_webhook: DiscordWebhook, message: string = "A flow is requesting an approval to be resumed") {
10

11
  const { approvalPage } = await getResumeUrls();
12

13
  const fullMessage = `${message} [approval page](${approvalPage})`;
14

15
  const response = await fetch(`${discord_webhook.webhook_url}?wait=true`, {
16
    method: "POST",
17
    headers: {
18
      "Content-Type": "application/json",
19
    },
20
    body: JSON.stringify({ content: fullMessage }),
21
  });
22
  if (!response.ok) {
23
    throw new Error(`${response.status} ${await response.text()}`);
24
  }
25
  return await response.json();
26
}
27

Other submissions
  • Submitted by henri186 Deno
    Created 398 days ago
    1
    import discordwebhook from "https://deno.land/x/discordwebhook/mod.ts";
    2
    import { getResumeUrls } from "https://deno.land/x/[email protected]/mod.ts";
    3
    
    
    4
    type DiscordWebhook = {
    5
      webhook_url: string;
    6
    };
    7
    
    
    8
    export async function main(discord_webhook: DiscordWebhook, message: string = "A flow is requesting an approval to be resumed") {
    9
    
    
    10
      const webhook = new discordwebhook(discord_webhook.webhook_url);
    11
    
    
    12
      const { approvalPage } = await getResumeUrls();
    13
      
    14
      const fullMessage = `${message} [approval page](${approvalPage})`;
    15
    
    
    16
      const ret = await webhook.createMessage(fullMessage);
    17
      return ret;
    18
    }
    19