how can I pass phone number to tool in Livekit ver...
# ask-ai
c
how can I pass phone number to tool in Livekit version 1
t
Thanks for reaching out, NAJAM. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please provide more details about your use case? For example: • What specific tool or feature in LiveKit are you trying to pass the phone number to? • Are you working with a specific API or SDK? • What is the intended functionality or outcome you are trying to achieve? This information will help me assist you better.
c
like transfer call tool in python
t
To transfer a call using LiveKit in Python, we've got you covered! 🤝 Let me walk you through a super handy way to use the
transfer_sip_participant
API that'll make call transfers a breeze.
Copy code
@function_tool()
async def transfer_call(self, participant_identity: str, transfer_to: str) -> None:
    """
    Transfer the SIP call to another number.

    Args:
    participant_identity (str): The identity of the participant.
    transfer_to (str): The phone number to transfer the call to.
    """
    try:
        userdata = self.session.userdata
        if not userdata.livekit_api:
            livekit_url = os.getenv('LIVEKIT_URL')
            api_key = os.getenv('LIVEKIT_API_KEY')
            api_secret = os.getenv('LIVEKIT_API_SECRET')
            userdata.livekit_api = api.LiveKitAPI(
                url=livekit_url,
                api_key=api_key,
                api_secret=api_secret
            )

        transfer_request = proto_sip.TransferSIPParticipantRequest(
            participant_identity=participant_identity,
            room_name=userdata.ctx.room.name,
            transfer_to=transfer_to,
            play_dialtone=True
        )

        await userdata.livekit_api.sip.transfer_sip_participant(transfer_request)
    except Exception as e:
        logger.error(f"Failed to transfer call: {e}", exc_info=True)
        await self.session.generate_reply(user_input="I'm sorry, I couldn't transfer your call. Is there something else I can help with?")
And hey, we can even get more specific! Check out how you can create department-specific transfer methods. For instance, transferring to billing is super simple:
Copy code
@function_tool()
async def transfer_to_billing(self, context: RunContext_T) -> str:
    """Transfer the call to the billing department."""
    room = context.userdata.ctx.room
    identity = room.local_participant.identity
    transfer_number = f"tel:{os.getenv('BILLING_PHONE_NUMBER')}"
    dept_name = "Billing"
    context.userdata.selected_department = dept_name
    await self._handle_transfer(identity, transfer_number, dept_name)
    return f"Transferring to {dept_name} department."
Quick heads up – there are a few things you'll want to keep in mind: • You must enable SIP REFER on your SIP trunk provider to use this functionality. • For Twilio, you'll also need to enable "Enable PSTN Transfer". • The transfer can be to a phone number (format:
tel:+15105550123
) or a SIP destination (format:
sip:user@host
). Need more help? I'm right here! Just give me a shout, and we'll figure it out together. 😊 Sources: Company directory phone assistant | LiveKit Docs | Agents telephony integration | LiveKit Docs | GitHub::livekit::agents | livekit-agents/livekit/agents/job.py