Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 02dc80a

Browse files
Enables usage of welcome message template for creating case ephemeral welcome messages (#5439)
* Enables usage of welcome message template for creating case ephemeral welcome messages. These messages pop up when participants are automatically or manually added to the case channel. * Remove unused imports. * Remove duplicate vars
1 parent 2fb62a3 commit 02dc80a

File tree

7 files changed

+216
-67
lines changed

7 files changed

+216
-67
lines changed

src/dispatch/case/flows.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from dispatch.conversation import flows as conversation_flows
1111
from dispatch.decorators import background_task
1212
from dispatch.document import flows as document_flows
13+
from dispatch.email_templates import service as email_template_service
14+
from dispatch.email_templates.enums import EmailTemplateTypes
1315
from dispatch.enums import DocumentResourceTypes, EventType, Visibility
1416
from dispatch.event import service as event_service
1517
from dispatch.group import flows as group_flows
@@ -130,10 +132,19 @@ def case_add_or_reactivate_participant_flow(
130132
case, [participant.individual.email], db_session
131133
)
132134

133-
# we send the welcome messages to the participant
134-
send_case_welcome_participant_message(
135-
participant_email=user_email, case=case, db_session=db_session
136-
)
135+
# check to see if there is an override welcome message template
136+
welcome_template = email_template_service.get_by_type(
137+
db_session=db_session,
138+
project_id=case.project_id,
139+
email_template_type=EmailTemplateTypes.welcome,
140+
)
141+
142+
send_case_welcome_participant_message(
143+
participant_email=user_email,
144+
case=case,
145+
db_session=db_session,
146+
welcome_template=welcome_template,
147+
)
137148

138149
return participant
139150

@@ -1040,13 +1051,27 @@ def case_create_resources_flow(
10401051
conversation_target=conversation_target,
10411052
)
10421053

1054+
# check to see if there is an override welcome message template
1055+
welcome_template = email_template_service.get_by_type(
1056+
db_session=db_session,
1057+
project_id=case.project_id,
1058+
email_template_type=EmailTemplateTypes.welcome,
1059+
)
1060+
10431061
for user_email in set(individual_participants):
10441062
send_participant_announcement_message(
10451063
db_session=db_session,
10461064
participant_email=user_email,
10471065
subject=case,
10481066
)
10491067

1068+
send_case_welcome_participant_message(
1069+
participant_email=user_email,
1070+
case=case,
1071+
db_session=db_session,
1072+
welcome_template=welcome_template,
1073+
)
1074+
10501075
event_service.log_case_event(
10511076
db_session=db_session,
10521077
source="Dispatch Core App",

src/dispatch/case/messaging.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
import logging
99

10+
from typing import Optional
11+
1012
from sqlalchemy.orm import Session
1113

1214
from dispatch.database.core import resolve_attr
15+
from dispatch.document import service as document_service
1316
from dispatch.case.models import Case, CaseRead
1417
from dispatch.messaging.strings import (
1518
CASE_CLOSE_REMINDER,
@@ -26,14 +29,13 @@
2629
CASE_PRIORITY_CHANGE,
2730
CASE_CLOSED_RATING_FEEDBACK_NOTIFICATION,
2831
MessageType,
32+
generate_welcome_message,
2933
)
3034
from dispatch.config import DISPATCH_UI_URL
35+
from dispatch.email_templates.models import EmailTemplates
3136
from dispatch.plugin import service as plugin_service
3237
from dispatch.event import service as event_service
3338
from dispatch.notification import service as notification_service
34-
from dispatch.plugins.dispatch_slack.case.messages import (
35-
create_welcome_ephemeral_message_to_participant,
36-
)
3739

3840
from .enums import CaseStatus
3941

@@ -310,6 +312,7 @@ def send_case_welcome_participant_message(
310312
participant_email: str,
311313
case: Case,
312314
db_session: Session,
315+
welcome_template: Optional[EmailTemplates] = None,
313316
):
314317
if not case.dedicated_channel:
315318
return
@@ -322,12 +325,52 @@ def send_case_welcome_participant_message(
322325
log.warning("Case participant welcome message not sent. No conversation plugin enabled.")
323326
return
324327

325-
welcome_message = create_welcome_ephemeral_message_to_participant(case=case)
328+
# we send the ephemeral message
329+
message_kwargs = {
330+
"name": case.name,
331+
"title": case.title,
332+
"description": case.description,
333+
"visibility": case.visibility,
334+
"status": case.status,
335+
"type": case.case_type.name,
336+
"type_description": case.case_type.description,
337+
"severity": case.case_severity.name,
338+
"severity_description": case.case_severity.description,
339+
"priority": case.case_priority.name,
340+
"priority_description": case.case_priority.description,
341+
"assignee_fullname": case.assignee.individual.name,
342+
"assignee_team": case.assignee.team,
343+
"assignee_weblink": case.assignee.individual.weblink,
344+
"reporter_fullname": case.reporter.individual.name,
345+
"reporter_team": case.reporter.team,
346+
"reporter_weblink": case.reporter.individual.weblink,
347+
"document_weblink": resolve_attr(case, "case_document.weblink"),
348+
"storage_weblink": resolve_attr(case, "storage.weblink"),
349+
"ticket_weblink": resolve_attr(case, "ticket.weblink"),
350+
"conference_weblink": resolve_attr(case, "conference.weblink"),
351+
"conference_challenge": resolve_attr(case, "conference.conference_challenge"),
352+
}
353+
faq_doc = document_service.get_incident_faq_document(
354+
db_session=db_session, project_id=case.project_id
355+
)
356+
if faq_doc:
357+
message_kwargs.update({"faq_weblink": faq_doc.weblink})
358+
359+
conversation_reference = document_service.get_conversation_reference_document(
360+
db_session=db_session, project_id=case.project_id
361+
)
362+
if conversation_reference:
363+
message_kwargs.update(
364+
{"conversation_commands_reference_document_weblink": conversation_reference.weblink}
365+
)
366+
326367
plugin.instance.send_ephemeral(
327368
conversation_id=case.conversation.channel_id,
328369
user=participant_email,
329370
text=f"Welcome to {case.name}",
330-
blocks=welcome_message,
371+
message_template=generate_welcome_message(welcome_template, is_incident=False),
372+
notification_type=MessageType.case_participant_welcome,
373+
**message_kwargs,
331374
)
332375

333376
log.debug(f"Welcome ephemeral message sent to {participant_email}.")

src/dispatch/conversation/flows.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,14 @@ def add_case_participants(
466466
return
467467

468468
try:
469-
plugin.instance.add_to_thread(
470-
case.conversation.channel_id,
471-
case.conversation.thread_id,
472-
participant_emails,
473-
)
469+
if case.has_thread:
470+
plugin.instance.add_to_thread(
471+
case.conversation.channel_id,
472+
case.conversation.thread_id,
473+
participant_emails,
474+
)
475+
elif case.has_channel:
476+
plugin.instance.add(case.conversation.channel_id, participant_emails)
474477
except Exception as e:
475478
event_service.log_case_event(
476479
db_session=db_session,

src/dispatch/messaging/email/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def get_template(message_type: MessageType, project_id: int):
3131
MessageType.case_notification: ("notification.mjml", None),
3232
MessageType.incident_participant_welcome: ("notification.mjml", None),
3333
MessageType.incident_tactical_report: ("tactical_report.mjml", None),
34+
MessageType.case_participant_welcome: ("notification.mjml", None),
3435
MessageType.incident_task_reminder: (
3536
"notification_list.mjml",
3637
INCIDENT_TASK_REMINDER_DESCRIPTION,

0 commit comments

Comments
 (0)