Request Interactive Slack Approval Approval
One script reply has been approved by the moderators Verified

Request Interactive Slack Approval

Created by hugo697 355 days ago Picked 17 times
Submitted by hugo697 Bun
Verified 231 days ago
1
import * as wmill from "windmill-client"
2

3
type Enums = {
4
  [key: string]: string[]
5
}
6

7
type DefaultArgs = {
8
  [key: string]: any
9
}
10

11
type ResApproval = {
12
  enums?: Enums
13
  default_args?: DefaultArgs
14
}
15

16
/**
17
 * Sends an interactive approval request via Slack and optionally returns dynamic enums and default arguments.
18
 *
19
 * [Enterprise Edition Only] To include form fields in the slack approval request, go to Advanced -> Suspend -> Form and define a form
20
 * Learn more at https://www.windmill.dev/docs/flows/flow_approval#form
21
 * 
22
 * @param {string} slackResourcePath - The path to the Slack resource in Windmill.
23
 * @param {string} channelId - The Slack channel ID where the approval request will be sent.
24
 * @param {string} [message] - Optional custom message to include in the Slack approval request.
25
 * @param {string} [approver] - Optional user ID or name of the approver for the request.
26
 * @param {DefaultArgs} [defaultArgsJson] - Optional object defining or overriding the default arguments to a form field.
27
 * @param {Enums} [dynamicEnumsJson] - Optional object overriding the enum default values of an emum form field .
28
 * 
29
 * @throws {Error} If the `wmill.requestInteractiveSlackApproval` call fails.
30
 * 
31
 * Example inputs:
32
 *   slackResourcePath: "/u/alex/my_slack_resource",
33
 *   "admins-slack-channel", 
34
 *   "Please approve this request",
35
 *   "approver123",
36
 *   { foo: ["choice1", "choice2"], bar: ["optionA", "optionB"] },
37
 *   { key1: "value1", key2: 42 }
38
 * );
39
 */
40
export async function main(
41
  slackResourcePath: string,
42
  channelId: string,
43
  message?: string,
44
  approver?: string,
45
  defaultArgsJson?: DefaultArgs,
46
  dynamicEnumsJson?: Enums,
47
) {
48
  await wmill.requestInteractiveSlackApproval({
49
    slackResourcePath,
50
    channelId,
51
    message,
52
    approver,
53
    defaultArgsJson,
54
    dynamicEnumsJson,
55
  })
56

57
  const returnObject: ResApproval = {}
58

59
  if (dynamicEnumsJson) returnObject.enums = dynamicEnumsJson
60
  if (defaultArgsJson) returnObject.default_args = defaultArgsJson
61

62
  return returnObject
63
}