Пример #1
0
def run_workflow_submitted_form(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict,
    db_session=None,
    slack_client=None,
):
    """Runs an external flow."""
    submitted_form = action.get("view")
    parsed_form_data = parse_submitted_form(submitted_form)

    params = {}
    named_params = []
    for i in parsed_form_data.keys():
        if i.startswith(RunWorkflowBlockId.param):
            key = i.split("-")[1]
            value = parsed_form_data[i]
            params.update({key: value})
            named_params.append({"key": key, "value": value})

    workflow_id = parsed_form_data.get(
        RunWorkflowBlockId.workflow_select)["value"]
    run_reason = parsed_form_data.get(RunWorkflowBlockId.run_reason)
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)
    workflow = workflow_service.get(db_session=db_session,
                                    workflow_id=workflow_id)

    creator_email = get_user_email(slack_client, action["user"]["id"])

    instance = workflow_service.create_instance(
        db_session=db_session,
        instance_in=WorkflowInstanceCreate(
            workflow={"id": workflow.id},
            incident={"id": incident.id},
            creator={"email": creator_email},
            run_reason=run_reason,
            parameters=named_params,
        ),
    )
    params.update({
        "incident_id": incident.id,
        "incident_name": incident.name,
        "instance_id": instance.id
    })

    workflow.plugin.instance.run(workflow.resource_id, params)

    send_workflow_notification(
        incident.conversation.channel_id,
        INCIDENT_WORKFLOW_CREATED_NOTIFICATION,
        db_session,
        instance_creator_name=instance.creator.individual.name,
        workflow_name=instance.workflow.name,
        workflow_description=instance.workflow.description,
    )
Пример #2
0
def list_my_tasks(incident_id: int, command: dict = None, db_session=None):
    """Returns the list of incident tasks to the user as an ephemeral message."""
    user_email = dispatch_slack_service.get_user_email(slack_client, command["user_id"])
    list_tasks(
        incident_id=incident_id,
        command=command,
        db_session=db_session,
        by_creator=user_email,
        by_assignee=user_email,
    )
Пример #3
0
async def handle_slack_action(*, db_session, client, request,
                              background_tasks):
    """Handles slack action message."""
    # We resolve the user's email
    user_id = request["user"]["id"]
    user_email = dispatch_slack_service.get_user_email(client, user_id)

    request["user"]["email"] = user_email

    # When there are no exceptions within the dialog submission, your app must respond with 200 OK with an empty body.
    response_body = {}
    if request.get("view"):
        handle_modal_action(request, background_tasks)
        if request["type"] == "view_submission":
            # For modals we set "response_action" to "clear" to close all views in the modal.
            # An empty body is currently not working.
            response_body = {"response_action": "clear"}
    elif request["type"] == "dialog_submission":
        handle_dialog_action(request, background_tasks, db_session=db_session)
    elif request["type"] == "block_actions":
        handle_block_action(request, background_tasks)

    return response_body