diff --git a/src/gradient_labs/_conversation_assign.py b/src/gradient_labs/_conversation_assign.py index d2e5c8d..f957d13 100644 --- a/src/gradient_labs/_conversation_assign.py +++ b/src/gradient_labs/_conversation_assign.py @@ -31,7 +31,7 @@ class AssignmentParams: def assign_conversation( *, client: HttpClient, conversation_id: str, params: AssignmentParams ) -> None: - """run assigns a conversation to a participant.""" + """assigns a conversation to a participant.""" body = {"assignee_type": params.participant_type.value} if params.assignee_id: body["assignee_id"] = params.assignee_id diff --git a/src/gradient_labs/_conversation_resume.py b/src/gradient_labs/_conversation_resume.py new file mode 100644 index 0000000..9a1b8c1 --- /dev/null +++ b/src/gradient_labs/_conversation_resume.py @@ -0,0 +1,44 @@ +from typing import Optional +from datetime import datetime + +from dataclasses import dataclass +from dataclasses_json import dataclass_json + +from ._http_client import HttpClient +from .conversation import ParticipantType + + +@dataclass_json +@dataclass(frozen=True) +class ResumeParams: + # assignee_type identifies the type of participant that this conversation is + # being assigned to. Set this to ParticipantTypeAIAgent to assign the conversation + # to the Gradient Labs AI agent. + assignee_type: ParticipantType + + # assignee_id optionally identifies the specific user that the conversation + # is being assigned to. + assignee_id: Optional[str] = None + + # Timestamp optionally defines the time when the conversation was assigned. + # If not given, this will default to the current time. + timestamp: Optional[datetime] = None + + # reason optionally allows you to describe why this assignment is happening. + reason: Optional[str] = None + + +def resume_conversation( + *, client: HttpClient, conversation_id: str, params: ResumeParams +) -> None: + """resume_conversation re-opens a conversation that was previously finished.""" + body = {"assignee_type": params.participant_type.value} + if params.assignee_id: + body["assignee_id"] = params.assignee_id + if params.timestamp: + body["timestamp"] = HttpClient.localize(params.timestamp) + + _ = client.put( + path=f"conversations/{conversation_id}/resume", + body=params.to_dict(), + ) diff --git a/src/gradient_labs/client.py b/src/gradient_labs/client.py index 3312b72..a85fb04 100644 --- a/src/gradient_labs/client.py +++ b/src/gradient_labs/client.py @@ -13,6 +13,7 @@ from ._conversation_event import add_conversation_event, EventParams from ._conversation_finish import finish_conversation, FinishParams from ._conversation_rate import rate_conversation, RatingParams +from ._conversation_resume import resume_conversation, ResumeParams from ._conversation_read import read_conversation, ReadParams from ._conversation_start import start_conversation, StartConversationParams @@ -158,6 +159,14 @@ def rate_conversation(self, *, conversation_id: str, params: RatingParams) -> No params=params, ) + def resume_conversation(self, *, conversation_id: str, params: ResumeParams) -> None: + """resume_conversation re-opens a conversation that was previously finished.""" + resume_conversation( + client=self.http_client, + conversation_id=conversation_id, + params=params, + ) + def read_conversation( self, *, conversation_id: str, params: ReadParams ) -> Conversation: