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 Teams 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} teamName - Microsoft Teams "Team" Name. |
23 | * @param {string} channelName - Teams Channel Name |
24 | * @param {string} [message] - Optional custom message to include in the Teams 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.requestInteractiveTeamsApproval` call fails. |
30 | * |
31 | * Example inputs: |
32 | * teamName: "Windmill", |
33 | * channelName: "General", |
34 | * message: "Please approve this request", |
35 | * approver: "approver123", |
36 | * defaultArgsJson: { foo: ["choice1", "choice2"], bar: ["optionA", "optionB"] }, |
37 | * dynamicEnumsJson: { key1: "value1", key2: 42 } |
38 | * ); |
39 | */ |
40 | export async function main( |
41 | teamName: string, |
42 | channelName: string, |
43 | message?: string, |
44 | approver?: string, |
45 | defaultArgsJson?: DefaultArgs, |
46 | dynamicEnumsJson?: Enums |
47 | ) { |
48 | await wmill.requestInteractiveTeamsApproval({ |
49 | teamName, |
50 | channelName, |
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 | } |
64 |
|