Skip to content

Commit 1deffc2

Browse files
authored
feat: add callback for session end in Conversation class (elevenlabs#578)
* Added `callback_end_session` parameter to the Conversation class to allow users to define a callback function that will be executed when the session ends. * Updated the `__init__` method and `end_session` method to handle the new callback. This enhancement provides more flexibility for managing session termination events.
1 parent b591b7f commit 1deffc2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/elevenlabs/conversational_ai/conversation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class Conversation:
240240
callback_agent_response_correction: Optional[Callable[[str, str], None]]
241241
callback_user_transcript: Optional[Callable[[str], None]]
242242
callback_latency_measurement: Optional[Callable[[int], None]]
243+
callback_end_session: Optional[Callable]
243244

244245
_thread: Optional[threading.Thread]
245246
_should_stop: threading.Event
@@ -261,6 +262,7 @@ def __init__(
261262
callback_agent_response_correction: Optional[Callable[[str, str], None]] = None,
262263
callback_user_transcript: Optional[Callable[[str], None]] = None,
263264
callback_latency_measurement: Optional[Callable[[int], None]] = None,
265+
callback_end_session: Optional[Callable] = None,
264266
):
265267
"""Conversational AI session.
266268
@@ -292,6 +294,7 @@ def __init__(
292294
self.callback_agent_response_correction = callback_agent_response_correction
293295
self.callback_user_transcript = callback_user_transcript
294296
self.callback_latency_measurement = callback_latency_measurement
297+
self.callback_end_session = callback_end_session
295298

296299
self.client_tools.start()
297300

@@ -317,6 +320,9 @@ def end_session(self):
317320
self._ws = None
318321
self._should_stop.set()
319322

323+
if self.callback_end_session:
324+
self.callback_end_session()
325+
320326
def wait_for_session_end(self) -> Optional[str]:
321327
"""Waits for the conversation session to end.
322328

0 commit comments

Comments
 (0)