Skip to content

Commit

Permalink
Direct add participants and allow for new participants via messages. (#…
Browse files Browse the repository at this point in the history
…2952)

* Direct add participants

* Update src/dispatch/case/flows.py

Co-authored-by: Will Sheldon <[email protected]>

---------

Co-authored-by: Will Sheldon <[email protected]>
  • Loading branch information
kevgliss and wssheldon authored Feb 7, 2023
1 parent 00cba5f commit 6d79742
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
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

0 comments on commit 6d79742

Please sign in to comment.