This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.
I want to transfer some users to a human agent immediately without going through the LiveKit agent. I’m getting this error:
TwirpError(code=failed_precondition, message=can't transfer non established call)
I’m calling transfer_sip_participant after ctx.connect and ctx.wait_for_participant. How do I wait for the call to be “established”?
The SIP call needs to be answered before you can transfer it. The sip.callStatus attribute needs to be active, not dialing or ringing.
To answer the call, you need to publish an audio track:
async def entrypoint(ctx: JobContext):
await ctx.connect()
user_participant = await ctx.wait_for_participant()
# Answer the call by publishing a track
source = rtc.AudioSource(24000, 1)
track = rtc.LocalAudioTrack.create_audio_track("audio", source)
await ctx.room.local_participant.publish_track(track)
# Wait for call status to become active
while user_participant.attributes.get('sip.callStatus') != 'active':
await asyncio.sleep(0.1)
# Now transfer
await livekit_api.sip.transfer_sip_participant(transfer_request)
See the SIP lifecycle example: