how can I receive the phone number incoming in my ...
# ask-ai
a
how can I receive the phone number incoming in my agent and use that to identify the user
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To receive an incoming phone number in LiveKit and use it to identify the user, follow these steps: 1. Set up an inbound trunk: Configure the trunk to accept calls from specific phone numbers. For example: `{ "trunk": { "name": "My trunk", "numbers": ["+15105550100"], "allowed_numbers": ["+13105550100", "+17145550100"] } }`This setup specifies which caller phone numbers are permitted to connect through your trunk. 2. Create a dispatch rule: Define how incoming calls are handled. The dispatch rule determines how SIP participants and LiveKit rooms are created for incoming calls. When a call is received, LiveKit SIP authenticates the trunk credentials, matches the dispatch rule, and creates a SIP participant for the caller, placing them in a LiveKit room accordingly. 3. Use metadata for identification: Configure additional properties for incoming calls, such as SIP headers, participant metadata, and attributes. This allows you to use the caller's phone number as an identifier. Let me know if you need further assistance with setting this up! Sources: SIP inbound trunk | LiveKit Docs | Accepting inbound calls | LiveKit Docs
a
I want to use the caller number in the agent
t
To use the caller's phone number in the agent, I've got a neat trick for you! 😊 Think of it like getting to know your caller a little better through their phone number.
Copy code
# Add this after `await ctx.connect()`:
participant = await ctx.wait_for_participant()

# Check if the participant is a SIP participant
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
    # Access the caller's phone number
    if participant.attributes['sip.phoneNumber'] == '+15105550100':
        <http://logger.info|logger.info>("Caller phone number is <tel:+1-510-555-0100|+1-510-555-0100>")
        # Add other logic here to modify the agent based on the caller's phone number
Isn't this cool? By checking the caller's phone number, you can totally personalize your agent's behavior. It's like having a super smart assistant that knows just what each caller needs. Want to set up some special treatment for specific numbers? This is how you do it! Need any help walking through this? I'm right here to help you out! 🌟 Sources: SIP participant | LiveKit Docs