def create_run_workflow_modal(incident_id: int, command: dict = None, db_session=None): """Creates a modal for running a workflow.""" trigger_id = command.get("trigger_id") incident = incident_service.get(db_session=db_session, incident_id=incident_id) workflows = workflow_service.get_enabled(db_session=db_session) if workflows: modal_create_template = build_workflow_blocks(incident=incident, workflows=workflows) dispatch_slack_service.open_modal_with_user( client=slack_client, trigger_id=trigger_id, modal=modal_create_template) else: blocks = [{ "type": "section", "text": { "type": "mrkdwn", "text": "No workflows are enabled. You can enable one in the Dispatch UI at /workflows.", }, }] dispatch_slack_service.send_ephemeral_message( slack_client, command["channel_id"], command["user_id"], "No workflows enabled.", blocks=blocks, )
def create_run_workflow_modal( user_id: str, user_email: str, channel_id: str, incident_id: int, command: dict, config: SlackConversationConfiguration = None, db_session=None, slack_client=None, ): """Creates a modal for running a workflow.""" trigger_id = command.get("trigger_id") incident = incident_service.get(db_session=db_session, incident_id=incident_id) workflows = workflow_service.get_enabled(db_session=db_session) workflows = [x for x in workflows if x.plugin_instance.enabled] if workflows: modal_create_template = run_workflow_view(incident=incident, workflows=workflows) open_modal_with_user(client=slack_client, trigger_id=trigger_id, modal=modal_create_template) else: blocks = [{ "type": "section", "text": { "type": "mrkdwn", "text": "No workflows are enabled or workflows plugin is not enabled. You can enable one in the Dispatch UI at /workflows.", }, }] send_ephemeral_message( slack_client, command["channel_id"], command["user_id"], "No workflows enabled.", blocks=blocks, )
def update_workflow_modal(action: dict, db_session=None): """Pushes an updated view to the run workflow modal.""" trigger_id = action["trigger_id"] incident_id = action["view"]["private_metadata"]["incident_id"] workflow_id = action["actions"][0]["selected_option"]["value"] selected_workflow = workflow_service.get(db_session=db_session, workflow_id=workflow_id) workflows = workflow_service.get_enabled(db_session=db_session) incident = incident_service.get(db_session=db_session, incident_id=incident_id) modal_template = build_workflow_blocks(incident=incident, workflows=workflows, selected_workflow=selected_workflow) modal_template["blocks"].append( { "type": "section", "text": { "type": "mrkdwn", "text": f"*Description* \n {selected_workflow.description}" }, }, ) modal_template["blocks"].append( { "block_id": RunWorkflowBlockFields.run_reason, "type": "input", "element": { "type": "plain_text_input", "multiline": True, "action_id": RunWorkflowBlockFields.run_reason, }, "label": { "type": "plain_text", "text": "Run Reason" }, }, ) modal_template["blocks"].append({ "type": "section", "text": { "type": "mrkdwn", "text": "*Parameters*" } }) if selected_workflow.parameters: for p in selected_workflow.parameters: modal_template["blocks"].append({ "block_id": f"{RunWorkflowBlockFields.param}-{p['key']}", "type": "input", "element": { "type": "plain_text_input", "placeholder": { "type": "plain_text", "text": "Value" }, }, "label": { "type": "plain_text", "text": p["key"] }, }) else: modal_template["blocks"].append({ "type": "section", "text": { "type": "mrkdwn", "text": "This workflow has no parameters." }, }) modal_template["callback_id"] = RunWorkflowCallbacks.submit_form dispatch_slack_service.update_modal_with_user( client=slack_client, trigger_id=trigger_id, view_id=action["view"]["id"], modal=modal_template, )