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

Direct add participants and allow for new participants via messages. #2952

Merged
merged 2 commits into from
Feb 7, 2023
Merged
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
10 changes: 10 additions & 0 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ def case_new_create_flow(*, case_id: int, organization_slug: OrganizationSlug, d
)
# wait until all resources are created before adding suggested participants
individual_participants = [x.email for x, _ in individual_participants]

for email in individual_participants:
# we don't rely on on this flow to add folks to the conversation because in this case
# we want to do it in bulk
case_add_or_reactivate_participant_flow(
db_session=db_session,
user_email=email,
case_id=case.id,
add_to_conversation=False,
)
conversation_plugin.instance.add_to_thread(
case.conversation.channel_id,
case.conversation.thread_id,
Expand Down
12 changes: 12 additions & 0 deletions src/dispatch/participant/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def get_by_incident_id_and_conversation_id(
)


def get_by_case_id_and_conversation_id(
*, db_session, case_id: int, user_conversation_id: str
) -> Optional[Participant]:
"""Get participant by case and user_conversation id."""
return (
db_session.query(Participant)
.filter(Participant.case_id == case_id)
.filter(Participant.user_conversation_id == user_conversation_id)
.one_or_none()
)


def get_all(*, db_session) -> List[Optional[Participant]]:
"""Get all participants."""
return db_session.query(Participant)
Expand Down
17 changes: 17 additions & 0 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ def assignee_select(
)


@message_dispatcher.add(
subject="case", exclude={"subtype": ["channel_join", "channel_leave"]}
) # we ignore channel join and leave messages
def handle_new_participant_message(
ack: Ack, user: DispatchUser, context: BoltContext, db_session: Session, client: WebClient
) -> None:
"""Looks for new participants that have starting chatting for the first time."""
ack()
participant = case_flows.case_add_or_reactive_participant_flow(
case_id=context["subject"].id,
user_email=user.email,
db_session=db_session,
add_to_conversation=False,
)
participant.user_conversation_id = context["user_id"]


@message_dispatcher.add(
subject="case", exclude={"subtype": ["channel_join", "channel_leave"]}
) # we ignore channel join and leave messages
Expand Down
12 changes: 9 additions & 3 deletions src/dispatch/plugins/dispatch_slack/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ def user_middleware(
)
db_session = refetch_db_session(slug)

participant = participant_service.get_by_incident_id_and_conversation_id(
db_session=db_session, incident_id=context["subject"].id, user_conversation_id=user_id
)
if context["subject"].type == "incident":
participant = participant_service.get_by_incident_id_and_conversation_id(
db_session=db_session, incident_id=context["subject"].id, user_conversation_id=user_id
)
else:
participant = participant_service.get_by_case_id_and_conversation_id(
db_session=db_session, case_id=context["subject"].id, user_conversation_id=user_id
)

if participant:
context["user"] = user_service.get_or_create(
db_session=db_session,
Expand Down