Inside agent session, how do I know if the call is...
# ask-ai
f
Inside agent session, how do I know if the call is "inbound" or "outbound"?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you figure out how to determine if a call is "inbound" or "outbound" during an agent session. Here are some friendly tips you can use: 1. Take a look at the
call_direction
field:
This is part of the SIP participant's data and tells you the call direction. You'll see values like: ◦ `SCD_INBOUND`: This means it's an inbound call ◦ `SCD_OUTBOUND`: This means it's an outbound call 1. Check out the
sip.ruleID
attribute:
If you find this attribute, it usually means the call is inbound (triggered by a dispatch rule). If it's not there, the call is outbound (started manually). 2. Keep an eye on `sip.callStatus`: The status gives you helpful hints: ◦ `ringing`: Usually means an inbound call ◦ `dialing`: Typically indicates an outbound call You can easily implement these checks programmatically using LiveKit SDKs and APIs. If you’d like, I’m here to help guide you through the implementation or answer any questions you have! Sources: livekit/attrs.go | SIP participant | LiveKit Docs | telephony/sip_lifecycle.py | pkg/sip/inbound.go
f
provide python example
t
Hi there! Here's a friendly Python example to help you determine if a call is inbound or outbound during an agent session:
Copy code
def on_participant_connected_handler(participant):
    if participant.kind == "PARTICIPANT_KIND_SIP":
        # Check the sip.ruleID attribute
        rule_id = participant.attributes.get("sip.ruleID")
        if rule_id:
            print("Call is INBOUND", "Rule ID:", rule_id)
        else:
            print("Call is OUTBOUND")

        # Optionally, monitor sip.callStatus for additional context
        call_status = participant.attributes.get("sip.callStatus")
        if call_status == "ringing":
            print("Inbound call is ringing")
        elif call_status == "dialing":
            print("Outbound call is dialing")
This example gently checks the
sip.ruleID
attribute to help identify the call direction, and you can also keep an eye on the
sip.callStatus
for a bit more context. If you have any questions or would like me to walk you through more examples, just let me know—I’m here to help!