mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
interactive slack approvals: more improvements / nits (#5012)
* enum -> enums, client function docs * advanced -> suspend -> form
This commit is contained in:
@@ -631,14 +631,45 @@ class Windmill:
|
||||
message: str = None,
|
||||
approver: str = None,
|
||||
default_args_json: dict = None,
|
||||
dynamic_enum_json: dict = None,
|
||||
dynamic_enums_json: dict = None,
|
||||
) -> None:
|
||||
"""
|
||||
Request interactive Slack approval
|
||||
:param slack_resource_path: Slack resource path
|
||||
:param channel_id: Slack channel
|
||||
:param message: Message to send to Slack
|
||||
:param approver: Approver name
|
||||
Sends an interactive approval request via Slack, allowing optional customization of the message, approver, and form fields.
|
||||
|
||||
**[Enterprise Edition Only]** To include form fields in the Slack approval request, use the "Advanced -> Suspend -> Form" functionality.
|
||||
Learn more at: https://www.windmill.dev/docs/flows/flow_approval#form
|
||||
|
||||
:param slack_resource_path: The path to the Slack resource in Windmill.
|
||||
:type slack_resource_path: str
|
||||
:param channel_id: The Slack channel ID where the approval request will be sent.
|
||||
:type channel_id: str
|
||||
:param message: Optional custom message to include in the Slack approval request.
|
||||
:type message: str, optional
|
||||
:param approver: Optional user ID or name of the approver for the request.
|
||||
:type approver: str, optional
|
||||
:param default_args_json: Optional dictionary defining or overriding the default arguments for form fields.
|
||||
:type default_args_json: dict, optional
|
||||
:param dynamic_enums_json: Optional dictionary overriding the enum default values of enum form fields.
|
||||
:type dynamic_enums_json: dict, optional
|
||||
|
||||
:raises Exception: If the function is not called within a flow or flow preview.
|
||||
:raises Exception: If the required flow job or flow step environment variables are not set.
|
||||
|
||||
:return: None
|
||||
|
||||
**Usage Example:**
|
||||
>>> client.request_interactive_slack_approval(
|
||||
... slack_resource_path="/u/alex/my_slack_resource",
|
||||
... channel_id="admins-slack-channel",
|
||||
... message="Please approve this request",
|
||||
... approver="approver123",
|
||||
... default_args_json={"key1": "value1", "key2": 42},
|
||||
... dynamic_enums_json={"foo": ["choice1", "choice2"], "bar": ["optionA", "optionB"]},
|
||||
... )
|
||||
|
||||
**Notes:**
|
||||
- This function must be executed within a Windmill flow or flow preview.
|
||||
- The function checks for required environment variables (`WM_FLOW_JOB_ID`, `WM_FLOW_STEP_ID`) to ensure it is run in the appropriate context.
|
||||
"""
|
||||
workspace = self.workspace
|
||||
flow_job_id = os.environ.get("WM_FLOW_JOB_ID")
|
||||
@@ -662,8 +693,8 @@ class Windmill:
|
||||
params["flow_step_id"] = os.environ.get("WM_FLOW_STEP_ID")
|
||||
if default_args_json:
|
||||
params["default_args_json"] = json.dumps(default_args_json)
|
||||
if dynamic_enum_json:
|
||||
params["dynamic_enum_json"] = json.dumps(dynamic_enum_json)
|
||||
if dynamic_enums_json:
|
||||
params["dynamic_enums_json"] = json.dumps(dynamic_enums_json)
|
||||
|
||||
self.get(
|
||||
f"/w/{workspace}/jobs/slack_approval/{os.environ.get('WM_JOB_ID', 'NO_JOB_ID')}",
|
||||
@@ -1026,7 +1057,7 @@ def request_interactive_slack_approval(
|
||||
message: str = None,
|
||||
approver: str = None,
|
||||
default_args_json: dict = None,
|
||||
dynamic_enum_json: dict = None,
|
||||
dynamic_enums_json: dict = None,
|
||||
) -> None:
|
||||
return _client.request_interactive_slack_approval(
|
||||
slack_resource_path=slack_resource_path,
|
||||
@@ -1034,7 +1065,7 @@ def request_interactive_slack_approval(
|
||||
message=message,
|
||||
approver=approver,
|
||||
default_args_json=default_args_json,
|
||||
dynamic_enum_json=dynamic_enum_json,
|
||||
dynamic_enums_json=dynamic_enums_json,
|
||||
)
|
||||
|
||||
@init_global_client
|
||||
|
||||
Reference in New Issue
Block a user