how to inject room metadata from sip headers for a...
# ask-ai
r
how to inject room metadata from sip headers for a inbound SIP call having individual dispatch rule?
t
Thanks for reaching out, Saurabh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about injecting room metadata from SIP headers for an inbound SIP call that uses an individual dispatch rule. You can capture headers on the trunk, map them to the SIP participant’s attributes, then promote those attributes to room metadata once the agent (or server logic) joins the room. Below are the concise steps and example snippets to do that. 1) Map SIP headers to participant attributes on the inbound trunk • Configure the trunk’s
headers_to_attributes
so incoming SIP headers are stored as participant attributes. Example JSON:
Copy code
{
  "trunk": {
    "name": "Inbound Trunk",
    "numbers": [
      "+1234567890"
    ],
    "headers_to_attributes": {
      "X-Custom-Header": "custom.value",
      "X-User-ID": "user.id"
    }
  }
}
• This maps
X-Custom-Header
→
custom.value
and
X-User-ID
→
user.id
. 2) Use an individual dispatch rule to create a new room per call • Use an individual dispatch rule (room-per-call). Example:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "call-"
      }
    }
  }
}
• Create the dispatch rule via CLI (example):
lk sip dispatch create dispatch-rule.json
3) Promote participant attributes into room metadata after the agent joins • Once the SIP participant is in the room, have the agent or server-side agent logic read the SIP participant’s attributes and update the room metadata. Example (Python-like pseudocode):
Copy code
@server.rtc_session()
async def my_agent(ctx: JobContext):
    await ctx.connect()

    # Find SIP participant
    sip_participant = None
    for participant in ctx.room.participants.values():
        if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
            sip_participant = participant
            break

    if sip_participant:
        attrs = sip_participant.attributes
        user_id = attrs.get("user.id")
        custom_value = attrs.get("custom.value")

        # Update room metadata
        await ctx.room.update_metadata(
            json.dumps({
                "user_id": user_id,
                "custom_value": custom_value
            })
        )
• This makes the SIP-header-derived data available at the room level for dashboards, routing, or UI display. Notes and tips • Ensure the header names you map match exactly what the SIP provider sends. • Keep attribute names consistent so your agent logic reliably reads them. • If multiple headers map to many attributes, consider grouping into a single JSON field in room metadata for easier parsing downstream. If you’d like, tell me: • Which SIP headers you want to capture (names and example values), and • Which fields you want in room metadata (keys and formats), and I’ll produce the exact trunk JSON and the precise agent code snippet tailored to your environment. Sources: How to do call transfers with Five9 | LiveKit | Agents telephony integration | LiveKit Documentation