Skip to content

Commit

Permalink
Adds a subscribe button to incident notifications (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Nov 8, 2021
1 parent 18279fd commit 9ef6592
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/user-guide/incident-participant.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ After an incident is marked stable, Dispatch continues to help with incident man
In addition to Dispatch engaging individuals that will be directly responsible for managing the incident, it provides notifications for general awareness throughout the organization.

{% hint style="info" %}
The new incident notification message includes a "Join Incident" button; this allows individuals to add themselves to the incident \(and its resources\) without involvement from the incident commander.
The new incident notification message includes a "Join" button; this allows individuals to add themselves to the incident \(and its resources\) without involvement from the incident commander.
{% endhint %}

## Self-service engagement
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/conversation/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ConversationCommands(DispatchEnum):

class ConversationButtonActions(DispatchEnum):
invite_user = "invite-user"
subscribe_user = "subscribe-user"
provide_feedback = "provide-feedback"
update_task_status = "update-task-status"
monitor_link = "monitor-link"
12 changes: 10 additions & 2 deletions src/dispatch/incident/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ def daily_report(db_session: SessionLocal, project: Project):
"title": incident.title,
"type": incident.incident_type.name,
"type_description": incident.incident_type.description,
"buttons": [],
}

if incident.status != IncidentStatus.closed:
item.update(
item["buttons"].append(
{
"button_text": "Join Incident",
"button_text": "Subscribe",
"button_value": f"{incident.project.organization.slug}-{incident.id}",
"button_action": f"{ConversationButtonActions.subscribe_user}-{incident.status}-{idx}",
}
)
item["buttons"].append(
{
"button_text": "Join",
"button_value": f"{incident.project.organization.slug}-{incident.id}",
"button_action": f"{ConversationButtonActions.invite_user}-{incident.status}-{idx}",
}
Expand Down
25 changes: 19 additions & 6 deletions src/dispatch/messaging/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,31 @@ class MessageType(DispatchEnum):
"title": "{{name}} Incident Notification",
"title_link": "{{ticket_weblink}}",
"text": INCIDENT_NOTIFICATION_PURPOSES_FYI,
"button_text": "Join Incident",
"button_value": "{{organization_slug}}-{{incident_id}}",
"button_action": ConversationButtonActions.invite_user,
"buttons": [
{
"button_text": "Subscribe",
"button_value": "{{organization_slug}}-{{incident_id}}",
"button_action": ConversationButtonActions.subscribe_user,
},
{
"button_text": "Join",
"button_value": "{{organization_slug}}-{{incident_id}}",
"button_action": ConversationButtonActions.invite_user,
},
],
}

INCIDENT_NAME_WITH_ENGAGEMENT_NO_DESCRIPTION = {
"title": "{{name}}",
"title_link": "{{ticket_weblink}}",
"text": "{{ignore}}",
"button_text": "{{button_text}}",
"button_value": "{{button_value}}",
"button_action": "{{button_action}}",
"buttons": [
{
"button_text": "{{button_text}}",
"button_value": "{{button_value}}",
"button_action": "{{button_action}}",
}
],
}

INCIDENT_NAME = {
Expand Down
29 changes: 29 additions & 0 deletions src/dispatch/plugins/dispatch_slack/actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from pydantic import ValidationError
from fastapi import BackgroundTasks
from sqlalchemy.sql.functions import user

from dispatch.conversation import service as conversation_service
from dispatch.conversation.enums import ConversationButtonActions
Expand Down Expand Up @@ -132,6 +133,7 @@ def block_action_functions(action: str):
"""Interprets the action and routes it to the appropriate function."""
action_mappings = {
ConversationButtonActions.invite_user: [add_user_to_conversation],
ConversationButtonActions.subscribe_user: [add_user_to_tactical_group],
ConversationButtonActions.provide_feedback: [create_rating_feedback_modal],
ConversationButtonActions.update_task_status: [update_task_status],
ConversationButtonActions.monitor_link: [monitor_link],
Expand Down Expand Up @@ -229,6 +231,33 @@ def handle_block_action(
)


@slack_background_task
def add_user_to_tactical_group(
user_id: str,
user_email: str,
channel_id: str,
incident_id: int,
action: dict,
config: SlackConversationConfiguration = None,
db_session=None,
slack_client=None,
):
"""Adds a user to the incident tactical group."""
incident = incident_service.get(db_session=db_session, incident_id=incident_id)
if not incident:
message = "Sorry, we cannot add you to this incident. It does not exist."
dispatch_slack_service.send_ephemeral_message(slack_client, channel_id, user_id, message)
elif incident.status == IncidentStatus.closed:
message = f"Sorry, we cannot subscribe you to a closed incident. Please, reach out to the incident commander ({incident.commander.individual.name}) for details."
dispatch_slack_service.send_ephemeral_message(slack_client, channel_id, user_id, message)
else:
incident_flows.add_participant_to_tactical_group(
user_email=user_email, incident=incident, db_session=db_session
)
message = f"Success! We've subscribed you to incident {incident.name}. You will recieve all tactical reports about this incident."
dispatch_slack_service.send_ephemeral_message(slack_client, channel_id, user_id, message)


@slack_background_task
def add_user_to_conversation(
user_id: str,
Expand Down
22 changes: 19 additions & 3 deletions src/dispatch/static/dispatch/src/incident/IncidentStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
<v-icon> mdi-account-plus </v-icon>
</v-btn>
</template>
<span>Join Incident</span>
<span>Join</span>
</v-tooltip>
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
<v-btn icon v-bind="attrs" v-on="on" @click="subscribeToIncident(id)">
<v-icon> mdi-email-plus </v-icon>
</v-btn>
</template>
<span>Subscribe</span>
</v-tooltip>
</div>
<div v-if="status == 'Stable'">
Expand All @@ -23,7 +31,15 @@
<v-icon> mdi-account-plus </v-icon>
</v-btn>
</template>
<span>Join Incident</span>
<span>Join</span>
</v-tooltip>
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
<v-btn icon v-bind="attrs" v-on="on" @click="subscribeToIncident(id)">
<v-icon> mdi-email-plus </v-icon>
</v-btn>
</template>
<span>Subscribe</span>
</v-tooltip>
</div>
<div v-if="status == 'Closed'">
Expand Down Expand Up @@ -52,7 +68,7 @@ export default {
},
methods: {
...mapActions("incident", ["joinIncident"]),
...mapActions("incident", ["joinIncident", "subscribeToIncident"]),
},
}
</script>

0 comments on commit 9ef6592

Please sign in to comment.