In the entrypoint for a nodejs agent, I'm looking ...
# ask-ai
r
In the entrypoint for a nodejs agent, I'm looking to use a SIP header to influence the configuration of the agent. How do I grab the sip participant and the sip headers from their connection to the room?
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you access SIP participant details and SIP headers in a Node.js agent for LiveKit. Here's a step-by-step guide to make it easier for you: 1. Identify SIP Participants: You can recognize SIP participants by checking their
kind
field, which should be set to
Participant.Kind.SIP
. For example:
Copy code
if (participant.kind === ParticipantKind.SIP) {
  console.log('This is a SIP participant');
}
2. Access SIP Participant Attributes: The SIP-specific details are stored within the
attributes
field of the participant object. This includes things like
sip.callID
,
sip.phoneNumber
, and
sip.callStatus
. 3. Access SIP Headers: When creating a SIP participant or setting up a trunk, you can use the
headersToAttributes
or
includeHeaders
options. For example: `const opts = { headersToAttributes: { 'X-Call-Source': 'sip.callSource', 'X-Region': 'sip.region' }, includeHeaders: SIPHeaderOptions.SIP_HEADER_OPTIONS_ALL };`These headers will then appear as attributes, such as
sip.h.X-Call-Source
. 4. Practical Usage: Here's how you can retrieve these attributes in your agent: `if (participant.kind === ParticipantKind.SIP) { const phoneNumber = participant.attributes['sip.phoneNumber']; const callStatus = participant.attributes['sip.callStatus']; const customHeader = participant.attributes['sip.h.X-Custom-Header']; console.log(
Call from ${phoneNumber}, status: ${callStatus}, header: ${customHeader}
); }` Just make sure your SIP trunk is set up with the
headersToAttributes
or
includeHeaders
options you want. If you have any questions or need a hand with anything else, please don’t hesitate to ask—I’m here to help! Sources: Rooms, participants, and tracks | LiveKit docs | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | SIP participant | LiveKit docs | packages/livekit-server-sdk/src/SipClient.ts | rpc/sip.pb.go