Skip to content

Call Transfer Functionality Not Working #1

@shwetd19

Description

@shwetd19

Description

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.

Steps to Reproduce

  1. Run the voice assistant script provided below.
  2. Simulate a participant joining the LiveKit room.
  3. Respond with yes when prompted for call transfer to the billing department.

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

  • Verified the .env.local configurations for LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET, and BILLING_PHONE_NUMBER.
  • Ensured the transfer number is formatted with a + prefix.
  • Attempted debugging the transfer_sip_participant call, but found no relevant error logs.

Questions

  1. Is the SIP transfer feature supported for this use case in LiveKit?
  2. Are there additional configurations or permissions required for SIP transfers to work?
  3. Could there be a potential issue with the LiveKit SDK or API?

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions