Skip to content

Commit

Permalink
Enhance Incident Notification Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jennafauconnier committed Oct 28, 2024
1 parent 9934cf5 commit e4c6bfe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/firefighter/incidents/forms/create_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def trigger_incident_workflow(
self,
creator: User,
impacts_data: dict[str, ImpactLevel],
source_channel: Any,
*args: Any,
**kwargs: Any,
) -> None:
Expand All @@ -89,4 +90,5 @@ def trigger_incident_workflow(
create_incident_conversation.send(
"create_incident_form",
incident=incident,
source_channel=source_channel
)
15 changes: 13 additions & 2 deletions src/firefighter/slack/messages/slack_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,23 @@ def get_text(self) -> str:
return f"Incident #{self.incident.id} might not need an incident channel, as it is {self.incident.priority.name}."


class SlackMessageIncidentCreationWarning(SlackMessageSurface):
id = "ff_incident_creation_warning"
class SlackMessageIncidentOpeningWarning(SlackMessageSurface):
id = "ff_incident_opening_warning"

def __init__(self, channel: Any):
self.channel = channel
super().__init__()

def get_text(self) -> str:
return f"<@{self.channel["user_id"]}> is opening an incident at the moment. Please wait before creating one. :ballot_box_with_ballot:"


class SlackMessageIncidentCreationRedirection(SlackMessageSurface):
id = "ff_incident_creation_redirection"

def __init__(self, channel: Any):
self.channel = channel
super().__init__()

def get_text(self) -> str:
return f"A new incident has just been created in #{self.channel.name}. You can go there to follow the incident."
13 changes: 13 additions & 0 deletions src/firefighter/slack/signals/create_incident_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from firefighter.incidents.signals import create_incident_conversation
from firefighter.slack.messages.slack_messages import (
SlackMessageDeployWarning,
SlackMessageIncidentCreationRedirection,
SlackMessageIncidentDeclaredAnnouncement,
SlackMessageIncidentDeclaredAnnouncementGeneral,
)
Expand All @@ -37,13 +38,15 @@
@receiver(signal=create_incident_conversation)
def create_incident_slack_conversation(
incident: Incident,
source_channel: IncidentChannel,
*_args: Any,
**_kwargs: Any,
) -> None | int:
"""Main process to open an incident channel, set it up and invite responders. It MUST be called when an incident is created.
Args:
incident (Incident): The incident to open. It should be saved before calling this function, and have its first incident update created.
source_channel (IncidentChannel): The channel from which the incident was opened, used for sending notifications and updates.
"""
channel: IncidentChannel | None = IncidentChannel.objects.create_incident_channel(
Expand Down Expand Up @@ -132,4 +135,14 @@ def create_incident_slack_conversation(
incident=incident,
channel=channel,
)

notify_incident_created(channel=channel, source_channel=source_channel)

return None


def notify_incident_created(channel: IncidentChannel, source_channel: IncidentChannel) -> None:
"""Notify the Slack channel that the incident has been created."""
message = SlackMessageIncidentCreationRedirection(channel)

source_channel.send_message_and_save(message)
8 changes: 6 additions & 2 deletions src/firefighter/slack/views/modals/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class OpenModal(SlackModal):
def open_modal_aio(self, ack: Ack, body: dict[str, Any], **kwargs: Any) -> None:
super().open_modal_aio(ack, body, **kwargs)
from firefighter.slack.messages.slack_messages import ( # noqa: PLC0415
SlackMessageIncidentCreationWarning,
SlackMessageIncidentOpeningWarning,
)

warning_message = SlackMessageIncidentCreationWarning(channel=body)
warning_message = SlackMessageIncidentOpeningWarning(channel=body)

channel, _ = Conversation.objects.get_or_create(
channel_id=body["channel_id"],
Expand All @@ -80,6 +80,8 @@ def open_modal_aio(self, ack: Ack, body: dict[str, Any], **kwargs: Any) -> None:
},
)

self.source_channel = channel

channel.send_message_and_save(warning_message)

def build_modal_fn(
Expand Down Expand Up @@ -157,6 +159,7 @@ def build_modal_fn(
*set_details_blocks,
*done_review_blocks,
]

return View(
type="modal",
title="Create an incident"[:24],
Expand Down Expand Up @@ -516,6 +519,7 @@ def handle_modal_fn( # type: ignore
details_form.trigger_incident_workflow(
creator=user,
impacts_data=data.get("impact_form_data") or {},
source_channel=self.source_channel
)
except: # noqa: E722
logger.exception("Error triggering incident workflow")
Expand Down

0 comments on commit e4c6bfe

Please sign in to comment.