colossal-lock-10836
08/22/2025, 11:22 AMtall-airline-16756
08/22/2025, 11:22 AMtall-airline-16756
08/22/2025, 11:23 AMuse_case and language when creating a SIP participant by using the participant_attributes field. Let me show you how:
For Outbound SIP Participants:
{
"sip_trunk_id": "your-trunk-id",
"sip_call_to": "+1234567890",
"room_name": "your-room",
"participant_attributes": {
"use_case": "customer_support",
"language": "en-US"
}
}
For Inbound SIP Participants: You can add custom attributes through SIP dispatch rules. These attributes will automatically apply to all SIP participants created by that dispatch rule:
{
"attributes": {
"use_case": "customer_support",
"language": "en-US"
},
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
},
"name": "My dispatch rule"
}
Another Option: You can also use SIP headers to include custom attributes. Just configure your trunk with headers_to_attributes and set up key/value mappings for any X-* SIP headers.
All these custom attributes will be available in the participant's attributes field, making it super handy for your workflows or integrations.
Sources: SIP participant | LiveKit Docscolossal-lock-10836
08/22/2025, 11:37 AMtall-airline-16756
08/22/2025, 11:38 AMsip.phoneNumber attribute in their attributes. Here’s a quick look at how you can do that:
Python Example:
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
phone_number = participant.attributes.get('sip.phoneNumber', 'Unknown')
print(f"SIP Phone Number: {phone_number}")
Node.js Example:
if (participant.kind == ParticipantKind.SIP) {
const phoneNumber = participant.attributes['sip.phoneNumber'];
console.log('SIP Phone Number:', phoneNumber);
}
A couple of things to keep in mind:
• For inbound trunks, sip.phoneNumber is the number the call is coming from. For outbound SIP, it’s the number the SIP participant dialed.
• If HidePhoneNumber is set in the dispatch rule, this attribute won’t be available.
You can check out this attribute as soon as the SIP participant joins the room—either right when they connect using event handlers like participant_connected or by looping through the participants already in the room.
Sources: SIP participant | LiveKit Docs | complex-agents/ivr-agent/flask_livekit/extension.pycolossal-lock-10836
08/22/2025, 1:00 PMtall-airline-16756
08/22/2025, 1:00 PMcolossal-lock-10836
08/22/2025, 1:06 PMtall-airline-16756
08/22/2025, 1:08 PMfrom livekit.api import LiveKitAPI
from livekit.protocol.sip import (
CreateSIPDispatchRuleRequest,
SIPDispatchRuleInfo,
SIPDispatchRule,
SIPDispatchRuleIndividual
)
from livekit.protocol.room import RoomConfiguration, RoomAgentDispatch
async def create_dispatch_rule_with_attributes_and_agent():
# Initialize LiveKit API client
lk_api = LiveKitAPI(
url="your_livekit_url",
api_key="your_api_key",
api_secret="your_api_secret"
)
# Define custom attributes for SIP participants
attributes = {
"use_case": "customer_support",
"language": "en-US"
}
# Configure room with agent dispatch
room_config = RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="agent_name",
metadata="job dispatch metadata"
)
]
)
# Create the dispatch rule info
dispatch_rule_info = SIPDispatchRuleInfo(
name="My dispatch rule with attributes and agent",
rule=SIPDispatchRule(
dispatch_rule_individual=SIPDispatchRuleIndividual(
room_prefix="call-"
)
),
attributes=attributes,
room_config=room_config
)
# Create the request
request = CreateSIPDispatchRuleRequest(
dispatch_rule=dispatch_rule_info
)
# Create the dispatch rule
created_rule = await lk_api.sip.create_sip_dispatch_rule(request)
print(f"Created dispatch rule: {created_rule.sip_dispatch_rule_id}")
await lk_api.aclose()
return created_rule
This snippet sets up a LiveKit API client, adds some handy custom attributes, configures agent dispatch, and then creates a SIP dispatch rule with your specified attributes and agent name.
If you have any questions or want to dive deeper, just let me know—I’m here to help!
Sources: livekit-protocol/livekit/protocol/sip.pyi | SIP dispatch rule | LiveKit Docs | SIP dispatch rule | LiveKit Docs | Accepting incoming calls | LiveKit Docs | Dispatching agents | LiveKit Docs