def report_incident_from_submitted_form( user_id: str, user_email: str, channel_id: str, incident_id: int, action: dict, config: SlackConversationConfiguration = None, db_session: SessionLocal = None, slack_client=None, ): submitted_form = action.get("view") parsed_form_data = parse_submitted_form(submitted_form) # Send a confirmation to the user blocks = create_incident_reported_confirmation_message( title=parsed_form_data[IncidentBlockId.title], description=parsed_form_data[IncidentBlockId.description], incident_type=parsed_form_data[IncidentBlockId.type]["value"], incident_priority=parsed_form_data[IncidentBlockId.priority]["value"], ) send_ephemeral_message( client=slack_client, conversation_id=channel_id, user_id=user_id, text="", blocks=blocks, ) tags = [] for t in parsed_form_data.get(IncidentBlockId.tags, []): # we have to fetch as only the IDs are embedded in slack tag = tag_service.get(db_session=db_session, tag_id=int(t["value"])) tags.append(tag) project = {"name": parsed_form_data[IncidentBlockId.project]["value"]} incident_in = IncidentCreate( title=parsed_form_data[IncidentBlockId.title], description=parsed_form_data[IncidentBlockId.description], incident_type={"name": parsed_form_data[IncidentBlockId.type]["value"]}, incident_priority={"name": parsed_form_data[IncidentBlockId.priority]["value"]}, project=project, tags=tags, ) if not incident_in.reporter: incident_in.reporter = ParticipantUpdate(individual=IndividualContactRead(email=user_email)) # Create the incident incident = incident_service.create(db_session=db_session, incident_in=incident_in) incident_flows.incident_create_flow( incident_id=incident.id, db_session=db_session, organization_slug=incident.project.organization.slug, )
def report_incident_from_submitted_form( user_id: str, user_email: str, incident_id: int, action: dict, db_session: Session = Depends(get_db), ): submitted_form = action.get("view") # Fetch channel id from private metadata field channel_id = submitted_form.get("private_metadata") parsed_form_data = parse_submitted_form(submitted_form) requested_form_title = parsed_form_data.get(IncidentSlackViewBlockId.title) requested_form_description = parsed_form_data.get( IncidentSlackViewBlockId.description) requested_form_incident_type = parsed_form_data.get( IncidentSlackViewBlockId.type) requested_form_incident_priority = parsed_form_data.get( IncidentSlackViewBlockId.priority) # send a confirmation to the user msg_template = create_incident_reported_confirmation_msg( title=requested_form_title, incident_type=requested_form_incident_type.get("value"), incident_priority=requested_form_incident_priority.get("value"), ) dispatch_slack_service.send_ephemeral_message( client=slack_client, conversation_id=channel_id, user_id=user_id, text="", blocks=msg_template, ) # create the incident incident = incident_service.create( db_session=db_session, title=requested_form_title, status=IncidentStatus.active, description=requested_form_description, incident_type=requested_form_incident_type, incident_priority=requested_form_incident_priority, reporter_email=user_email, ) incident_flows.incident_create_flow(incident_id=incident.id)
def report_incident_from_submitted_form( user_id: str, user_email: str, channel_id: str, incident_id: int, action: dict, db_session: Session = None, slack_client=None, ): submitted_form = action.get("view") parsed_form_data = parse_submitted_form(submitted_form) requested_form_title = parsed_form_data.get(IncidentSlackViewBlockId.title) requested_form_description = parsed_form_data.get(IncidentSlackViewBlockId.description) requested_form_incident_type = parsed_form_data.get(IncidentSlackViewBlockId.type) requested_form_incident_priority = parsed_form_data.get(IncidentSlackViewBlockId.priority) # Send a confirmation to the user blocks = create_incident_reported_confirmation_message( title=requested_form_title, description=requested_form_description, incident_type=requested_form_incident_type.get("value"), incident_priority=requested_form_incident_priority.get("value"), ) dispatch_slack_service.send_ephemeral_message( client=slack_client, conversation_id=channel_id, user_id=user_id, text="", blocks=blocks, ) # Create the incident incident = incident_service.create( db_session=db_session, title=requested_form_title, status=IncidentStatus.active, description=requested_form_description, incident_type=requested_form_incident_type, incident_priority=requested_form_incident_priority, reporter_email=user_email, tags=[], # The modal does not currently support tags ) incident_flows.incident_create_flow(incident_id=incident.id)
def report_incident_from_submitted_form( user_id: str, user_email: str, channel_id: str, incident_id: int, action: dict, db_session: SessionLocal = None, slack_client=None, ): submitted_form = action.get("view") parsed_form_data = parse_submitted_form(submitted_form) # Send a confirmation to the user blocks = create_incident_reported_confirmation_message( title=parsed_form_data[IncidentBlockId.title], description=parsed_form_data[IncidentBlockId.description], incident_type=parsed_form_data[IncidentBlockId.type]["value"], incident_priority=parsed_form_data[IncidentBlockId.priority]["value"], ) send_ephemeral_message( client=slack_client, conversation_id=channel_id, user_id=user_id, text="", blocks=blocks, ) tags = [] for t in parsed_form_data.get(IncidentBlockId.tags, []): tags.append({"id": t["value"]}) incident_in = IncidentCreate( title=parsed_form_data[IncidentBlockId.title], description=parsed_form_data[IncidentBlockId.description], incident_type={"name": parsed_form_data[IncidentBlockId.type]["value"]}, incident_priority={"name": parsed_form_data[IncidentBlockId.priority]["value"]}, project={"name": parsed_form_data[IncidentBlockId.project]["value"]}, reporter=IndividualContactCreate(email=user_email), tags=tags, ) # Create the incident incident = incident_service.create(db_session=db_session, incident_in=incident_in) incident_flows.incident_create_flow(incident_id=incident.id, db_session=db_session)