how can i disconnect an sip call after a fixed max...
# ask-ai
k
how can i disconnect an sip call after a fixed max call duration. how can i provide max call duration to agent?
t
Thanks for reaching out, Saurav. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To disconnect an SIP call after a fixed maximum call duration and provide that duration to an agent, follow these steps: 1. Set Max Call Duration: Use the
max_call_duration
field in the SIP call request. This field is part of the
CreateSIPParticipantRequest
and allows you to specify the duration in seconds or using the protobuf
Duration
type. 2. Automatic Disconnection: LiveKit will automatically disconnect the call once the specified
max_call_duration
is reached. 3. Provide Max Call Duration to the Agent: Use the
headers_to_attributes
mapping to pass the max call duration as a custom attribute in the SIP participant request. For example, you can map a custom header like
X-Max-Call-Duration
to an attribute accessible by the agent. Here’s an example of how the
CreateSIPParticipantRequest
might look:
Copy code
message CreateSIPParticipantRequest {
  // ...
  map<string, string> headers = 16;
  map<string, string> headers_to_attributes = 17;
  google.protobuf.Duration max_call_duration = 12;
  // ...
}
Let me know if you need further assistance or specific examples! Sources: pkg/sip/participant.go | rpc/sip.pb.go
k
i only creating dispatch rule and sip trunk but not a sip participant. my code -
Copy code
lk_api = livekit_api.LiveKitAPI()
    # create a Dispatch Rule on livekit for the phone number
    agent_name = settings.AGENT_WORKER_AGENT_NAME

    dispatch_rule = livekit_api.SIPDispatchRule(
        dispatch_rule_individual=livekit_api.SIPDispatchRuleIndividual(
            room_prefix="assistant-",
        )
    )
    dispatch_rule_name = f"Inbound Agent Calling Dispatch Rule for {phone_num}"
    agent_to_dispatch = livekit_api.RoomAgentDispatch(
        agent_name=agent_name,
        metadata=str(assistant_id),
    )
    room_config = livekit_api.RoomConfiguration(agents=[agent_to_dispatch])
    sip_dispatch_rule_info = livekit_api.SIPDispatchRuleInfo(
        rule=dispatch_rule,
        room_config=room_config,
        name=dispatch_rule_name,
        trunk_ids=[sip_trunk_id],
    )
    dispatch_rule_request = livekit_api.CreateSIPDispatchRuleRequest(dispatch_rule=sip_dispatch_rule_info)
t
Hey there! If you want to set a maximum call duration when using SIP dispatch rules and trunks, here’s a simple way to do it: 1. Set Max Call Duration on SIP Trunks: When you create SIP inbound trunks, just fill in the
max_call_duration
field. This makes sure all calls going through that trunk stick to the time limit you set. 2. Dispatch Rule Evaluation: While SIP dispatch rules don’t have a
max_call_duration
field themselves, they can actually inherit this limit from the trunk they’re linked to. So, by connecting dispatch rules with trunks that have a
max_call_duration
, you’re in control of call lengths. 3. Global Maximum: Just a heads up, LiveKit has a hard cap of 24 hours for call duration — that one can’t be changed. In your code, just make sure the trunk tied to your dispatch rule has the
max_call_duration
set, and you’re good to go! Calls routed through that dispatch rule will follow the duration limit automatically. If you want me to walk you through it more or share some examples, just let me know—I’m here to help! Sources: rpc/io.pb.go | livekit-protocol/src/livekit.rs | packages/livekit-server-sdk/src/SipClient.ts | lib/livekit/sip_service_client.rb | pkg/sip/participant.go
k
but using this max_call_duration params in trunk means the call will be disconnected without any warning from agent. agent should tell atleast 10 seconds before that it's past the max call duration and he have to disconnect the calll now
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!