-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hello,
I am attempting to handle call transfers using LiveKit in a voice assistant. The assistant listens for user responses (yes
or no
) and initiates a transfer to the billing department when the response is affirmative. Despite following the documentation and implementing the SIP transfer process, the call transfer does not happen.
Previously, I was able to handle call transfers successfully using DTMF handling, where the assistant listens for keypad inputs (e.g., pressing a specific number) and responds accordingly. However, the same process does not seem to work with voice-triggered responses.
Expected Behavior
The call should be transferred to the billing department's phone number provided in the .env.local
file as BILLING_PHONE_NUMBER
.
Observed Behavior
The assistant verbally confirms the transfer, but the actual SIP transfer does not take place. The call remains in the current room, and no error logs indicate why the transfer failed.
Code Snippets
1. Handling Call Transfer
Below is the code snippet for initiating the SIP call transfer:
async def handle_transfer(room_name: str, participant_identity: str, assistant: VoiceAssistant) -> None:
try:
transfer_number = os.getenv('BILLING_PHONE_NUMBER')
if not transfer_number:
raise ValueError("Billing phone number not configured")
if not transfer_number.startswith('+'):
transfer_number = f"+{transfer_number}"
await assistant.say("Transferring you to our billing department. Please hold.", allow_interruptions=False)
livekit_api = api.LiveKitAPI(
url=os.getenv('LIVEKIT_URL'),
api_key=os.getenv('LIVEKIT_API_KEY'),
api_secret=os.getenv('LIVEKIT_API_SECRET')
)
transfer_uri = f"tel:{transfer_number}"
transfer_request = proto_sip.TransferSIPParticipantRequest(
room_name=room_name,
participant_identity=participant_identity,
transfer_to=transfer_uri,
play_dialtone=False
)
logger.info(f"Initiating transfer for participant {participant_identity} to {transfer_uri}")
await livekit_api.sip.transfer_sip_participant(transfer_request)
await asyncio.sleep(2)
await assistant.cleanup()
logger.info("Transfer completed, exiting process")
os._exit(0)
except Exception as e:
logger.error(f"Transfer failed: {e}", exc_info=True)
await assistant.say("I apologize, but I couldn't transfer your call. Please try again later.", allow_interruptions=True)
2. Handling yes/no
Responses
Below is the implementation for handling user responses and deciding whether to transfer the call:
@assistant.on_message
async def handle_message(message: str):
message = message.lower().strip()
if message in ["yes", "yeah", "sure", "okay", "correct", "yep"]:
participants = list(ctx.room.participants.values())
if not participants:
logger.error("No participants found in room")
await assistant.say("I'm sorry, but I cannot process the transfer at this moment.", allow_interruptions=True)
return
participant = participants[0]
logger.info(f"Attempting transfer for participant: {participant.identity}")
await handle_transfer(ctx.room.name, participant.identity, assistant)
elif message in ["no", "nope", "not now", "nah"]:
await assistant.say("Alright, is there something else I can help you with?", allow_interruptions=True)
else:
await assistant.say("Would you like me to transfer you to our billing department? Please say 'yes' or 'no'.", allow_interruptions=True)
What I Tried
- Attempted debugging the
transfer_sip_participant
call, but found no relevant error logs.
Questions
- Is the SIP transfer feature supported for this use case in LiveKit?
- Are there additional configurations or permissions required for SIP transfers to work?
- Could there be a potential issue with the LiveKit SDK or API?
- Why does the transfer work as expected when using DTMF handling (listening for keypad inputs) but fails when using
yes/no
voice responses? Are there additional steps or considerations required for voice-based triggers?
Environment
- LiveKit SDK Version: (Please specify)
- Python Version: (e.g., 3.10)
- OS: (e.g., Ubuntu 22.04)
Any insights or guidance would be greatly appreciated! Let me know if you need additional logs or context.