class CreateSIPParticipantRequest(_message.Message...
# ask-ai
c
class CreateSIPParticipantRequest(_message.Message): slots = ("sip_trunk_id", "trunk", "sip_call_to", "sip_number", "room_name", "participant_identity", "participant_name", "participant_metadata", "participant_attributes", "dtmf", "play_ringtone", "play_dialtone", "hide_phone_number", "headers", "include_headers", "ringing_timeout", "max_call_duration", "krisp_enabled", "media_encryption", "wait_until_answered") these fields exist on creating a sip participant. I want to include custom fields like "use_case" and "language". How to do it?
t
Thanks for reaching out, ZaidKaraymeh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! You can easily add custom fields like
use_case
and
language
when creating a SIP participant by using the
participant_attributes
field. Let me show you how: For Outbound SIP Participants:
Copy code
{
  "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:
Copy code
{
  "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 Docs
c
how to get sip participant phone number?
t
Hey there! If you want to grab the phone number of a SIP participant, you can easily get it from the
sip.phoneNumber
attribute in their attributes. Here’s a quick look at how you can do that: Python Example:
Copy code
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:
Copy code
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.py
c
is Kirsp enabled for self hosted livekit?
t
Just a heads-up: Krisp noise cancellation isn’t available for self-hosted LiveKit deployments. This handy feature is only supported on LiveKit Cloud and can’t be turned on for self-hosted servers. If you’re looking for advanced noise cancellation with a self-hosted setup, you might want to check out other audio processing options or think about using LiveKit Cloud for this particular feature. We’re here to help if you have any questions! Sources: Knowledge Management System | livekit/livekit_composite | DeepWiki | README.md | livekit-protocol/livekit/protocol/sip.pyi | livekit-api/src/services/sip.rs | SIP APIs | LiveKit Docs
c
{ "attributes": { "use_case": "customer_support", "language": "en-US" }, "rule": { "dispatchRuleIndividual": { "roomPrefix": "call-" } }, "name": "My dispatch rule" } write python code to make this dispatch and make it for agent_name also
t
Here's a friendly Python example to help you create a SIP dispatch rule with attributes and an agent name:
Copy code
from 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