how do i get the sip number on which the customer ...
# ask-ai
l
how do i get the sip number on which the customer is calling on?
t
Thanks for reaching out, Istiaque. 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 retrieve the SIP number on which a customer is calling in LiveKit! You can find this information using the
sip.phoneNumber
attribute of the SIP participant. This attribute holds the caller's phone number for inbound calls and the dialed number for outbound calls. Here’s a simple way to access it: 1. When a participant joins the room, check their attributes. For example, in Python:
Copy code
async def async_on_participant_connected(participant):
    if participant.kind == 'PARTICIPANT_KIND_SIP':
        phone_number = participant.attributes.get('sip.phoneNumber', 'Unknown')
        print(f"Caller's phone number: {phone_number}")
1. Make sure the
hide_phone_number
setting is set to
false
in the SIP dispatch rule or when creating the SIP participant. For example:
Copy code
create_request = api.CreateSIPParticipantRequest(
    sip_trunk_id=sip_trunk_id,
    sip_call_to=phone_number,
    room_name=room_name,
    participant_identity=identity,
    hide_phone_number=False
)
Also, please double-check that your SIP trunk and dispatch rules are set up to expose the phone number. If you run into any issues or have more questions, feel free to reach out—I’m here to help! Sources: Create and configure a Plivo SIP trunk | LiveKit Docs | SIP participant | LiveKit Docs | telephony/sip_lifecycle.py | protobufs/livekit_sip.proto | Preserving Caller ID During SIP Transfers in LiveKit Agents
l
use nodejs
t
I'd be happy to help you retrieve the SIP number using Node.js in LiveKit! You can access the
sip.phoneNumber
attribute from the participant's attributes when the participant is of kind
SIP
. Here's a simple example to guide you:
Copy code
import { RoomServiceClient } from 'livekit-server-sdk';

const roomService = new RoomServiceClient(
  process.env.LIVEKIT_URL!,
  process.env.LIVEKIT_API_KEY!,
  process.env.LIVEKIT_API_SECRET!
);

// List participants in a room
const participants = await roomService.listParticipants('your-room-name');

for (const participant of participants) {
  if (participant.kind === 'SIP') {
    const phoneNumber = participant.attributes?.['sip.phoneNumber'];
    console.log('Caller phone number:', phoneNumber);
  }
}
Just a quick tip: please make sure the
HidePhoneNumber
option isn’t enabled in your dispatch rule, as that would hide the
sip.phoneNumber
attribute. If you have any questions or need more help, feel free to reach out—I’m here for you! Sources: SIP participant | LiveKit Docs | src/setup-livekit.ts
l
export default defineAgent({ prewarm: async (proc: JobProcess) => { proc.userData.vad = await silero.VAD.load(); }, entry: async (ctx: JobContext) => { // const agentPhoneNumber = "+12348134415"; const vad = ctx.proc.userData.vad! as silero.VAD; const assistant = new voice.Agent({ instructions: "You are a helpful voice assistant and your name is sarah", }); const session = new voice.AgentSession({ vad, stt: "assemblyai/universal-streaming:en", llm: "openai/gpt-4.1-mini", tts: "cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc", turnDetection: new livekit.turnDetector.MultilingualModel(), }); await session.start({ agent: assistant, room: ctx.room, inputOptions: { noiseCancellation: BackgroundVoiceCancellation(), }, }); const getParticipant = await client.getParticipant( ctx.room.name!, "agent-AJ_RGqPsVjbDiaU" ); const participants = await client.listParticipants(ctx.room.name!); const agentPhoneNumber = participants[1]?.attributes["sipTrunkPhoneNumber"]; console.log("agentPhoneNumber", participants); console.log("getParticipant", getParticipant); await ctx.connect(); const handle = session.generateReply({ instructions: "Say hello and welcome to the cafe.", }); }, }); look at this code const assistant = new voice.Agent({ instructions: "You are a helpful voice assistant and your name is sarah", }); can i update the voice.Agent after a session.start ?
t
Absolutely! You can update the
voice.Agent
even after
session.start
in LiveKit. It’s quite straightforward—you just use the
updateAgent
method from the
AgentSession
class to swap out the current agent for a new one. Here’s a little example to help you visualize it:
Copy code
session.updateAgent(new voice.Agent({
  instructions: "You are a new helpful assistant."
}));
This approach makes sure everything transitions smoothly by creating a new activity for the updated agent, gently draining the current activity, and reconnecting the audio streams—all without interrupting your session. If you’d like, I’m here to help with more examples or any other questions you might have! Sources: agents/src/voice/agent_activity.ts | Workflows | LiveKit Docs | basics/say_in_voice.py | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | agent/main.py