Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables usage of welcome message template for creating case ephemeral welcome messages #5439

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from dispatch.conversation import flows as conversation_flows
from dispatch.decorators import background_task
from dispatch.document import flows as document_flows
from dispatch.email_templates import service as email_template_service
from dispatch.email_templates.enums import EmailTemplateTypes
from dispatch.enums import DocumentResourceTypes, EventType, Visibility
from dispatch.event import service as event_service
from dispatch.group import flows as group_flows
Expand Down Expand Up @@ -130,10 +132,19 @@ def case_add_or_reactivate_participant_flow(
case, [participant.individual.email], db_session
)

# we send the welcome messages to the participant
send_case_welcome_participant_message(
participant_email=user_email, case=case, db_session=db_session
)
# check to see if there is an override welcome message template
welcome_template = email_template_service.get_by_type(
db_session=db_session,
project_id=case.project_id,
email_template_type=EmailTemplateTypes.welcome,
)

send_case_welcome_participant_message(
participant_email=user_email,
case=case,
db_session=db_session,
welcome_template=welcome_template,
)

return participant

Expand Down Expand Up @@ -1039,13 +1050,27 @@ def case_create_resources_flow(
conversation_target=conversation_target,
)

# check to see if there is an override welcome message template
welcome_template = email_template_service.get_by_type(
db_session=db_session,
project_id=case.project_id,
email_template_type=EmailTemplateTypes.welcome,
)

for user_email in set(individual_participants):
send_participant_announcement_message(
db_session=db_session,
participant_email=user_email,
subject=case,
)

send_case_welcome_participant_message(
participant_email=user_email,
case=case,
db_session=db_session,
welcome_template=welcome_template,
)

event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
Expand Down
53 changes: 48 additions & 5 deletions src/dispatch/case/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import logging

from typing import Optional

from sqlalchemy.orm import Session

from dispatch.database.core import resolve_attr
from dispatch.document import service as document_service
from dispatch.case.models import Case, CaseRead
from dispatch.messaging.strings import (
CASE_CLOSE_REMINDER,
Expand All @@ -26,14 +29,13 @@
CASE_PRIORITY_CHANGE,
CASE_CLOSED_RATING_FEEDBACK_NOTIFICATION,
MessageType,
generate_welcome_message,
)
from dispatch.config import DISPATCH_UI_URL
from dispatch.email_templates.models import EmailTemplates
from dispatch.plugin import service as plugin_service
from dispatch.event import service as event_service
from dispatch.notification import service as notification_service
from dispatch.plugins.dispatch_slack.case.messages import (
create_welcome_ephemeral_message_to_participant,
)

from .enums import CaseStatus

Expand Down Expand Up @@ -310,6 +312,7 @@ def send_case_welcome_participant_message(
participant_email: str,
case: Case,
db_session: Session,
welcome_template: Optional[EmailTemplates] = None,
):
if not case.dedicated_channel:
return
Expand All @@ -322,12 +325,52 @@ def send_case_welcome_participant_message(
log.warning("Case participant welcome message not sent. No conversation plugin enabled.")
return

welcome_message = create_welcome_ephemeral_message_to_participant(case=case)
# we send the ephemeral message
message_kwargs = {
"name": case.name,
"title": case.title,
"description": case.description,
"visibility": case.visibility,
"status": case.status,
"type": case.case_type.name,
"type_description": case.case_type.description,
"severity": case.case_severity.name,
"severity_description": case.case_severity.description,
"priority": case.case_priority.name,
"priority_description": case.case_priority.description,
"assignee_fullname": case.assignee.individual.name,
"assignee_team": case.assignee.team,
"assignee_weblink": case.assignee.individual.weblink,
"reporter_fullname": case.reporter.individual.name,
"reporter_team": case.reporter.team,
"reporter_weblink": case.reporter.individual.weblink,
"document_weblink": resolve_attr(case, "case_document.weblink"),
"storage_weblink": resolve_attr(case, "storage.weblink"),
"ticket_weblink": resolve_attr(case, "ticket.weblink"),
"conference_weblink": resolve_attr(case, "conference.weblink"),
"conference_challenge": resolve_attr(case, "conference.conference_challenge"),
}
faq_doc = document_service.get_incident_faq_document(
db_session=db_session, project_id=case.project_id
)
if faq_doc:
message_kwargs.update({"faq_weblink": faq_doc.weblink})

conversation_reference = document_service.get_conversation_reference_document(
db_session=db_session, project_id=case.project_id
)
if conversation_reference:
message_kwargs.update(
{"conversation_commands_reference_document_weblink": conversation_reference.weblink}
)

plugin.instance.send_ephemeral(
conversation_id=case.conversation.channel_id,
user=participant_email,
text=f"Welcome to {case.name}",
blocks=welcome_message,
message_template=generate_welcome_message(welcome_template, is_incident=False),
notification_type=MessageType.case_participant_welcome,
**message_kwargs,
)

log.debug(f"Welcome ephemeral message sent to {participant_email}.")
Expand Down
13 changes: 8 additions & 5 deletions src/dispatch/conversation/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,14 @@ def add_case_participants(
return

try:
plugin.instance.add_to_thread(
case.conversation.channel_id,
case.conversation.thread_id,
participant_emails,
)
if case.has_thread:
plugin.instance.add_to_thread(
case.conversation.channel_id,
case.conversation.thread_id,
participant_emails,
)
elif case.has_channel:
plugin.instance.add(case.conversation.channel_id, participant_emails)
except Exception as e:
event_service.log_case_event(
db_session=db_session,
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/messaging/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_template(message_type: MessageType, project_id: int):
MessageType.case_notification: ("notification.mjml", None),
MessageType.incident_participant_welcome: ("notification.mjml", None),
MessageType.incident_tactical_report: ("tactical_report.mjml", None),
MessageType.case_participant_welcome: ("notification.mjml", None),
MessageType.incident_task_reminder: (
"notification_list.mjml",
INCIDENT_TASK_REMINDER_DESCRIPTION,
Expand Down
Loading
Loading