From 7066d4cd723dfdf34e19b57f2f9805274a352ca5 Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 7 May 2024 09:47:19 -0700 Subject: [PATCH 1/2] Add welcome ephemeral message to dedicated channel cases --- .../dispatch_slack/case/interactive.py | 13 +++++++- .../plugins/dispatch_slack/case/messages.py | 33 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/interactive.py b/src/dispatch/plugins/dispatch_slack/case/interactive.py index 64a4a89b0b9e..8dd2945a6235 100644 --- a/src/dispatch/plugins/dispatch_slack/case/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/case/interactive.py @@ -55,6 +55,7 @@ from dispatch.plugins.dispatch_slack.case.messages import ( create_case_message, create_signal_engagement_message, + create_welcome_ephemeral_message_to_participant, ) from dispatch.plugins.dispatch_slack.config import SlackConversationConfiguration from dispatch.plugins.dispatch_slack.decorators import message_dispatcher @@ -940,15 +941,25 @@ def handle_new_participant_added( participants = re.findall(r"\<\@([a-zA-Z0-9]*)\>", payload["text"]) for user_id in participants: try: + case: Case = context["subject"] user_email = get_user_email(client=client, user_id=user_id) participant = case_flows.case_add_or_reactivate_participant_flow( - case_id=context["subject"].id, + case_id=case.id, user_email=user_email, db_session=db_session, add_to_conversation=False, ) participant.user_conversation_id = user_id + if case.dedicated_channel: + welcome_message = create_welcome_ephemeral_message_to_participant( + case=context["subject"] + ) + client.chat_postEphemeral( + text=welcome_message, + channel=payload["channel"], + user=payload["user"], + ) except Exception as e: log.warn(f"Error adding participant {user_id} to Case {context['subject'].id}: {e}") continue diff --git a/src/dispatch/plugins/dispatch_slack/case/messages.py b/src/dispatch/plugins/dispatch_slack/case/messages.py index 0d6e0990ca75..8968f6554fe2 100644 --- a/src/dispatch/plugins/dispatch_slack/case/messages.py +++ b/src/dispatch/plugins/dispatch_slack/case/messages.py @@ -362,3 +362,36 @@ def create_signal_engagement_message( ) return Message(blocks=blocks).build()["blocks"] + + +def create_welcome_ephemeral_message_to_participant(case: Case) -> Message: + blocks = [ + Section( + text="You've been added to this case, because we think you may be able to help resolve it. Please review the case details below and reach out to the case assignee if you have any questions.", + ), + Section( + text=f"*Title* \n {case.title}", + ), + Section( + text=f"*Description* \n {case.description}", + ), + Section( + text=f"*Visibility - {case.visibility}*", + ), + Section( + text=f"*Status - {case.status}*", + ), + Section( + text=f"*Type - {case.case_type.name}*", + ), + Section( + text=f"*Severity - {case.case_severity.name}*", + ), + Section( + text=f"*Priority - {case.case_priority.name}*", + ), + Section( + text=f"*Reporter - {case.reporter.individual.name}*", + ), + ] + return Message(blocks=blocks).build()["blocks"] From f56908e7ce70c1e01864e5fd6665dffc57e2223d Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 7 May 2024 10:48:43 -0700 Subject: [PATCH 2/2] Update src/dispatch/plugins/dispatch_slack/case/interactive.py --- src/dispatch/plugins/dispatch_slack/case/interactive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/interactive.py b/src/dispatch/plugins/dispatch_slack/case/interactive.py index 8dd2945a6235..162afc9897c4 100644 --- a/src/dispatch/plugins/dispatch_slack/case/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/case/interactive.py @@ -953,7 +953,7 @@ def handle_new_participant_added( participant.user_conversation_id = user_id if case.dedicated_channel: welcome_message = create_welcome_ephemeral_message_to_participant( - case=context["subject"] + case=case ) client.chat_postEphemeral( text=welcome_message,