I'm trying to send a SIP Transfer request in my `e...
# ask-ai
t
I'm trying to send a SIP Transfer request in my
entrypoint
depending on whether my client wants the bot enabled or not on certain days (for instance holidays). However, the SIP Transfer request fails with the following error (I'm using Twilio for SIP Trunking):
Copy code
livekit.api.twirp_client.TwirpError: TwirpError(code=failed_precondition, message=twirp error unknown: can't transfer non established call, status=412) {"pid": 78355, "job_id": "AJ_pqcPLmKkUENm"}
From what I understand, it means that the participants are not fully connected to the room. But I didn't find any ways to actually wait for participant to be connected in `entrypoint()`: •
ctx.room.on("participant_connected")
doesn't seem to be triggered for SIP Participants •
ctx.wait_for_participant()
doesn't return any attribute related to the participant connection status. Possibly
sip.callStatus
, however this attribute is not awaitable. I would have to call the function until call is complete, which is less than ideal. The only way I found for this to work is to do the transfer request within
Agent
classes, possibly on
Agent.on_enter()
but I would really prefer to do it upper in the stack. Did I miss anything?
t
Thanks for reaching out, Pierrick. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error is happening because the SIP participant isn’t fully connected to the room before the transfer request is made. To help you get this sorted, it’s important to make sure the participant’s connection status is confirmed before starting the transfer. Here are some friendly steps you can try: 1. First, check the participant’s connection status using the
sip.callStatus
attribute. It should show as "active" before you go ahead with the transfer. 2. Next, use the
ctx.transfer_sip_participant()
method or the
livekit_api.sip.transfer_sip_participant()
API call to start the transfer. Just double-check that the target destination is a valid SIP URI or a telephone number with the
tel:
prefix. 3. Keep an eye on the transfer operation’s completion. There’s a default 30-second timeout for the transfer request to handle the asynchronous nature of SIP REFER operations, so it might take a moment. If you want to manage this in the
entrypoint
, you might consider adding a way to poll or wait until the
sip.callStatus
becomes "active" before initiating the transfer. Or, like you mentioned, handling the transfer in the
Agent.on_enter()
method could be a smoother approach since it gives you better control over the participant’s state. Please feel free to reach out if you’d like me to walk you through any of these steps or if you have any other questions—I’m here to help! Sources: sipclient.go | SIP troubleshooting guide | LiveKit Docs | test/integration/sip_test.go | examples/voice_agents/error_callback.py | README.md
t
I'd like to add this forward check just after
session.start()
, but whatever I do, nothing works... Is there any event to listen to so I can transfer the call before the agent starts talking. But without adding this check within an
Agent
class method
t
Thanks for sharing your question! To help you in the best way possible, could you please share a bit more about why you'd prefer not to use methods within the
Agent
class for this check? Are you hoping to handle everything directly within the
entrypoint
using a specific event or mechanism? Knowing more about your needs will really help me offer the most helpful and personalized guidance.
t
Yes, I want to make the transfer request in
entrypoint
. For now the mitigation I found is to do a
sleep(3)
but that might not always work
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!