I am making an outbound call using spi truck, how ...
# ask-ai
m
I am making an outbound call using spi truck, how to know when user disconnects
t
Thanks for reaching out, Rubaiyet. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To detect when a user disconnects during an outbound call using a SIP trunk, you can monitor the
sip.callStatus
attribute of the participant. Here is an example of how you can implement this:
Copy code
start_time = perf_counter()
while perf_counter() - start_time < 30:
    call_status = participant.attributes.get("sip.callStatus")
    if call_status == "active":
        <http://logger.info|logger.info>("User has picked up")
        return
    elif call_status == "automation":
        # Handle DTMF dialing if applicable
        pass
    elif call_status == "hangup":
        <http://logger.info|logger.info>("User hung up, exiting job")
        break
    await asyncio.sleep(0.1)
<http://logger.info|logger.info>("Session timed out, exiting job")
ctx.shutdown()
When the user disconnects, the
sip.callStatus
attribute will change to "hangup", allowing you to detect the disconnection and take appropriate action. Sources: Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs