Documentation | Guava

on_session_end()

Register a handler that fires when a call session ends. Use this to save call data, trigger post-call workflows, or log outcomes.

The BotSessionEnded event carries a termination_reason field that tells you why the session ended:

Value Meaning
"user-hangup" The caller hung up.
"bot-hangup" The agent ended the call (e.g. via call.hangup()).
"bot-failure" The session ended due to an internal error.
"bot-transfer" The call was transferred to another destination.
"voicemail" The outbound call reached voicemail.

Signature

@agent.on_session_end

def on_session_end(call: guava.Call, event: BotSessionEnded) -> None:
    ...
Parameter Type Default Description
call Call — The call object. Note: the call is already ended — do not issue commands on it.
event BotSessionEnded — Contains termination_reason — one of "user-hangup", "bot-hangup", "bot-failure", "bot-transfer", "voicemail".

Return value: None

Example

import logging
from guava.events import BotSessionEnded

logger = logging.getLogger(__name__)

@agent.on_session_end
def on_session_end(call: guava.Call, event: BotSessionEnded):
    logger.info("session ended: reason=%s", event.termination_reason)
    if event.termination_reason == "user-hangup":
        # caller hung up — save any collected data
        ...
    elif event.termination_reason == "bot-transfer":
        # call was transferred to a human agent
        ...