saearch web cuase wait unitl asnered is full unrel...
# ask-ai
p
saearch web cuase wait unitl asnered is full unrelaiable dont chenge code just deep reasearch
t
Thanks for reaching out, Minas. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for reaching out! I want to make sure I understand your situation fully so I can help you better. Could you please share a bit more about the issue you're facing or the kind of assistance you need? For instance, are you having trouble with a particular feature or function? I'm here to help!
p
waituntilanswered for phoen calls sdoesnt really work
t
I'm glad you asked about the wait-until-answered feature in LiveKit! This feature is designed to make sure the API call to create a SIP participant waits patiently until the outbound call is answered by the recipient before sending back a response. You can control this behavior using the
wait_until_answered
parameter in your API request. When you set this parameter to
true
, the system will keep the connection open and only respond once the call is successfully answered. However, if the call isn’t answered within the set timeout, the request will unfortunately fail, and the participant won’t join the room. If you’re running into any issues with this, I’d love to help! Could you share a bit more about what’s happening? For instance, is the call not waiting as you expected, or are you seeing timeout errors? Your details will help me guide you better. Sources: Make outbound calls | LiveKit docs | Making outbound calls | LiveKit docs | agent.py | protobufs/rpc/sip.proto
p
whats the timeout? do i have nay bug ? import { NextResponse } from 'next/server'; // Note: Install livekit-server-sdk package: pnpm add livekit-server-sdk import { SipClient } from 'livekit-server-sdk'; _// Support both standard and humanlike_livekit prefixed environment variables_ const LIVEKIT_URL = process.env.HUMANLIKE_LIVEKIT_URL || process.env.HUMANLIKE_LIVEKIT_URL; const LIVEKIT_API_KEY = process.env.HUMANLIKE_LIVEKIT_API_KEY || process.env.HUMANLIKE_LIVEKIT_API_KEY; const LIVEKIT_API_SECRET = process.env.HUMANLIKE_LIVEKIT_API_SECRET || process.env.HUMANLIKE_LIVEKIT_API_SECRET; // SIP Configuration const SIP_ADDRESS = process.env.SIP_ADDRESS || 'sip.telnyx.com'; // Hardcoded SIP credentials const SIP_USERNAME = 'livekituser2025'; const SIP_PASSWORD = 'SecurePass123LK2025'; // SIP Trunk ID to use const SIP_TRUNK_ID = 'ST_TtPALWZ45DVd'; // Default "from" number: +1-650-900-8341 (normalized to E.164 format) const DEFAULT_FROM_NUMBER = '+16509008341'; const SIP_TRUNK_NUMBERS = (process.env.SIP_TRUNK_NUMBERS || process.env.HUMANLIKE_LIVEKIT_SIP_TRUNK_NUMBERS || DEFAULT_FROM_NUMBER).split(',').map(n => n.trim()); export async function *POST*(_request_: Request) { console.log('📞 Phone call API endpoint called'); if (!LIVEKIT_URL || !LIVEKIT_API_KEY || !LIVEKIT_API_SECRET) { console.error('❌ LiveKit environment variables not configured'); return NextResponse.json( { error: 'LiveKit environment variables are not fully configured. Please set LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET.' }, { status: 500 } ); } try { const body = await request.json(); const phoneNumber = body.phoneNumber?.trim(); console.log('📞📞📞 PHONE NUMBER RECEIVED 📞📞📞'); console.log('Raw phone number from request:', body.phoneNumber); console.log('Trimmed phone number:', phoneNumber); console.log('Phone number type:', typeof phoneNumber); console.log('Phone number length:', phoneNumber?.length); if (!phoneNumber) { console.error('❌ Phone number is missing or empty'); return NextResponse.json( { error: 'phoneNumber is required' }, { status: 400 } ); } // Validate phone number format (E.164 format: +[country code][number]) const phoneRegex = /^\+[1-9]\d{1,14}$/; const isValidFormat = phoneRegex.test(phoneNumber); console.log('📞 Making phone call to:', phoneNumber); console.log('📞 Full phone number details:', { original: body.phoneNumber, trimmed: phoneNumber, isValid: phoneNumber && phoneNumber.length > 0, isValidFormat, phoneNumberLength: phoneNumber.length, startsWithPlus: phoneNumber.startsWith('+') }); if (!isValidFormat) { console.error('❌ Invalid phone number format:', phoneNumber); console.error(' Expected format: +[country code][number] (E.164 format)'); console.error(' Example: +306972804021 or +16509008341'); return NextResponse.json( { error: 'Invalid phone number format. Please use E.164 format (e.g., +306972804021)', received: phoneNumber, expectedFormat: '+[country code][number]' }, { status: 400 } ); } console.log('📋 SIP Configuration:', { address: SIP_ADDRESS, hasUsername: !!SIP_USERNAME, hasPassword: !!SIP_PASSWORD, trunkId: SIP_TRUNK_ID, trunkNumbers: SIP_TRUNK_NUMBERS, fromNumber: DEFAULT_FROM_NUMBER, livekitUrl: LIVEKIT_URL?.substring(0, 20) + '...', hasApiKey: !!LIVEKIT_API_KEY, hasApiSecret: !!LIVEKIT_API_SECRET }); // Initialize SIP client const sipClient = new SipClient( LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET ); // Trunk options - transport is required for outbound trunks // Using UDP as default transport (common for SIP) // SIPTransport enum values: 0 = UDP, 1 = TCP, 2 = TLS const trunkOptions = { transport: 0 as any, // SIPTransport.UDP = 0 authUsername: SIP_USERNAME, authPassword: SIP_PASSWORD }; // Use existing SIP trunk ID or create new one let trunkId = SIP_TRUNK_ID; console.log('🔧 Using SIP trunk ID:', trunkId); // If trunk doesn't exist, create it try { // Try to get existing trunk first (optional - you might want to skip this) // const trunk = await sipClient.getSipTrunk(trunkId); _// console.log('_✅ Using existing SIP trunk:', trunkId); } catch (error) { // If trunk doesn't exist, create it console.log('🔧 Creating new SIP outbound trunk...'); const trunk = await sipClient.createSipOutboundTrunk( 'HumanlikeAI Trunk', SIP_ADDRESS, SIP_TRUNK_NUMBERS, trunkOptions ); trunkId = trunk.sipTrunkId; console.log('✅ SIP trunk created:', { sipTrunkId: trunk.sipTrunkId, address: SIP_ADDRESS, numbers: SIP_TRUNK_NUMBERS, fromNumber: DEFAULT_FROM_NUMBER }); } console.log('✅ Using SIP trunk:', { sipTrunkId: trunkId, address: SIP_ADDRESS, numbers: SIP_TRUNK_NUMBERS, fromNumber: DEFAULT_FROM_NUMBER }); // Create room name (generate unique room name or use provided one) const roomName = body.roomName || `sip-room-${Date.now()}-${Math.random().toString(36).substring(7)}`; const participantIdentity = body.participantIdentity || 'sip-test'; const participantName = body.participantName || 'Test Caller'; console.log('📞 Creating SIP participant to make call...'); console.log('📞 Call details:', { sipTrunkId: trunkId, phoneNumber, roomName, participantIdentity, participantName }); // Create SIP participant (this actually makes the phone call) const fromNumber = body.sipNumber || DEFAULT_FROM_NUMBER; const participantOptions = { fromNumber, // The "from" number (caller ID) participantIdentity, participantName, participantAttributes: body.participantAttributes || {}, playRingtone: body.playRingtone ?? true, hidePhoneNumber: body.hidePhoneNumber ?? false, krispEnabled: body.krispEnabled ?? false, waitUntilAnswered: true, playDialtone: true }; console.log('📞 SIP Participant Options:', JSON.stringify(participantOptions, null, 2)); const participant = await sipClient.createSipParticipant( trunkId, phoneNumber, // Number to dial roomName, participantOptions ); console.log('✅✅✅ SIP PARTICIPANT CREATED - CALL INITIATED ✅✅✅'); console.log('Participant Info:', JSON.stringify(participant, null, 2)); console.log('Call Details:', { callTo: phoneNumber, callFrom: fromNumber, trunkId: trunkId, roomName: roomName }); return NextResponse.json({ success: true, message: 'SIP call initiated successfully', participant: { participantId: participant.participantId, participantIdentity: participant.participantIdentity, roomName: participant.roomName }, call: { to: phoneNumber, from: fromNumber, trunkId: trunkId, roomName: roomName }, note:
Call initiated from ${fromNumber} to ${phoneNumber}
}); } catch (error) { console.error('❌ Error creating SIP trunk:', error); return NextResponse.json( { error: 'Failed to create SIP trunk', details: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ); } } // GET endpoint for testing export async function *GET*() { return NextResponse.json({ status: 'ok', message: 'Phone call API endpoint is ready', timestamp: new Date().toISOString(), hasSipConfig: { hasAddress: !!SIP_ADDRESS, hasUsername: !!SIP_USERNAME, hasPassword: !!SIP_PASSWORD, hasNumbers: SIP_TRUNK_NUMBERS.length > 0 }, sipConfig: { address: SIP_ADDRESS, numbers: SIP_TRUNK_NUMBERS, // Don't expose passwords hasAuth: !!SIP_USERNAME && !!SIP_PASSWORD } }); }
t
I’m glad you asked about the wait-until-answered feature in LiveKit SIP calls! By default, it waits for 60 seconds for the call to be answered before timing out, unless you’ve set a custom timeout. If you think something might be off in your setup, here are a few friendly tips to help you troubleshoot: • Double-check that the
waitUntilAnswered
parameter is set to
true
in your API call. • Make sure your SIP trunk and credentials are correctly configured and active. • Take a look at any errors or logs during the call initiation—they can often point to what’s going on. If you’re still running into trouble, I’d love to help! Could you share a bit more about what you’re seeing that doesn’t seem right? Sources: packages/livekit-server-sdk/src/SipClient.ts | livekit-protocol/livekit/protocol/sip.pyi | SIP APIs | LiveKit docs
p
✅✅✅ SIP PARTICIPANT CREATED - CALL INITIATED ✅✅✅ Participant Info: { "participantId": "PA_Pk6yGmXvDTFS", "participantIdentity": "sip-test", "roomName": "sip-room-1763417978508-mku79g", "sipCallId": "SCL_n2TUz3SsMR5J" } Call Details: { callTo: '+306972804021', callFrom: '+16509008341', trunkId: 'ST_TtPALWZ45DVd', roomName: 'sip-room-1763417978508-mku79g' } POST /api/phonecall 200 in 4427ms?
e-9cdee6895de2', name: 'Univation' } ] GET /chat-widget-frame?companyId=8ded0e95-f9a5-49f2-b974-b690d197141b 200 in 69ms 📞 Phone call API endpoint called 📞📞📞 PHONE NUMBER RECEIVED 📞📞📞 Raw phone number from request: +306972804021 Trimmed phone number: +306972804021 Phone number type: string Phone number length: 13 📞 Making phone call to: +306972804021 📞 Full phone number details: { original: '+306972804021', trimmed: '+306972804021', isValid: true, isValidFormat: true, phoneNumberLength: 13, startsWithPlus: true } 📋 SIP Configuration: { address: 'sip.telnyx.com', hasUsername: true, hasPassword: true, trunkId: 'ST_TtPALWZ45DVd', trunkNumbers: [ '+16509008341' ], fromNumber: '+16509008341', livekitUrl: 'wss://humanlike-phon...', hasApiKey: true, hasApiSecret: true } 🔧 Using SIP trunk ID: ST_TtPALWZ45DVd ✅ Using SIP trunk: { sipTrunkId: 'ST_TtPALWZ45DVd', address: 'sip.telnyx.com', numbers: [ '+16509008341' ], fromNumber: '+16509008341' } 📞 Creating SIP participant to make call... 📞 Call details: { sipTrunkId: 'ST_TtPALWZ45DVd', phoneNumber: '+306972804021', roomName: 'sip-room-1763417978508-mku79g', participantIdentity: 'sip-test', participantName: 'Test Caller' } 📞 SIP Participant Options: { "fromNumber": "+16509008341", "participantIdentity": "sip-test", "participantName": "Test Caller", "participantAttributes": {}, "playRingtone": true, "hidePhoneNumber": false, "krispEnabled": false, "waitUntilAnswered": true } ✅✅✅ SIP PARTICIPANT CREATED - CALL INITIATED ✅✅✅ Participant Info: { "participantId": "PA_Pk6yGmXvDTFS", "participantIdentity": "sip-test", "roomName": "sip-room-1763417978508-mku79g", "sipCallId": "SCL_n2TUz3SsMR5J" } Call Details: { callTo: '+306972804021', callFrom: '+16509008341', trunkId: 'ST_TtPALWZ45DVd', roomName: 'sip-room-1763417978508-mku79g' } POST /api/phonecall 200 in 4427ms
t
Great news! It seems like the SIP participant was successfully created and the call got started smoothly. The response shows that the call setup finished in 4427ms, which is right on track for this kind of operation. If you’re still having any trouble, please feel free to share a bit more about what’s going on. Are you noticing the call isn’t connecting like you hoped, or is there something off with the timeout behavior? I’m here to help you get this sorted out!
p
what are participant_attributes ?
t
Hi there! When it comes to LiveKit SIP calls, participant_attributes are really handy key-value pairs (strings) that you can attach to a SIP participant as soon as they join a room. Think of these attributes as your way to add custom metadata that helps tailor workflows, identify participants, or share important info throughout the call. There are two types of attributes to keep in mind: • System-defined SIP attributes: These are automatically added by LiveKit for you, like
sip.callID
,
sip.callStatus
, and
sip.phoneNumber
. • User-defined custom attributes: These you can set yourself in the
participant_attributes
field of your API request, map from SIP headers, or define through dispatch rules for inbound calls. You can easily access or update these attributes using LiveKit server SDKs or APIs. They’re super useful for creating dynamic telephony applications, whether you’re routing calls or customizing AI behavior. If you have any questions or want to explore this further, I’m here to help! Sources: SIP participant | LiveKit docs | Participant attributes and metadata | LiveKit docs | livekit-protocol/src/livekit.rs | SIP APIs | LiveKit docs | protobufs/livekit_sip.proto