shy-raincoat-67106
08/18/2025, 11:41 AM@function_tool()
async def transfer_call(self, ctx: RunContext, transfer_to: str):
"""Transfer the call to a human agent
Args:
transfer_to: A phone number to transfer the call to in the format "+1234567890"
"""
# Disabled because it was causing duplicated messages
# # let the message play fully before transferring
# await ctx.session.generate_reply(
# instructions="Inform the user that you're transferring them to a different agent."
# )
job_ctx = get_job_context()
# grab the first remote participant
participant = next(iter(job_ctx.room.remote_participants.values()))
<http://logger.info|logger.info>(":speech_balloon:[Assistant::TransferCall] participant: %s", participant)
try:
transferRequest = api.TransferSIPParticipantRequest(
room_name=job_ctx.room.name,
play_dialtone=True,
participant_identity=participant.identity,
# to use a sip destination, use `sip:user@host` format
transfer_to=f"tel:{transfer_to}",
)
<http://logger.info|logger.info>(":speech_balloon:[Assistant::TransferCall] transferRequest: %s", transferRequest)
await job_ctx.api.sip.transfer_sip_participant(
transferRequest
)
except Exception as e:
print(f"error transferring call: {e}")
# give the LLM that context
return "could not transfer call"
Code works locally but doesn't work in prod. Call tranfer doesn't happen and the call gets cut.tall-airline-16756
08/18/2025, 11:41 AMtall-airline-16756
08/18/2025, 11:42 AMshy-raincoat-67106
08/18/2025, 11:43 AMtall-airline-16756
08/18/2025, 11:43 AMTransferSIPParticipant
API to make it happen. This handy method lets you transfer an existing call directly—no need to create a new room with two participants.
To make sure everything goes smoothly, double-check that your SIP trunk is set up to allow call transfers. For example, if you’re using Twilio, you’ll want to enable call transfers in your SIP trunk settings. With the TransferSIPParticipant
API, you can easily specify details like the participant identity, room name, and where you want to transfer the call.
If you’d like a hand setting this up or run into any issues, just let me know—I’m here to help!