From 53887b7c98de0d6da67018d3fe34656d27b1bdcc Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Sun, 27 Apr 2025 14:04:12 -0400 Subject: [PATCH] Display phone number in WebRTC call --- .../phone-chatbot-daily-twilio-sip/server.py | 6 ++++-- .../utils/daily_helpers.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/phone-chatbot-daily-twilio-sip/server.py b/examples/phone-chatbot-daily-twilio-sip/server.py index 5a89e742c..ddbc188ea 100644 --- a/examples/phone-chatbot-daily-twilio-sip/server.py +++ b/examples/phone-chatbot-daily-twilio-sip/server.py @@ -45,11 +45,13 @@ async def handle_call(request: Request): if not call_sid: raise HTTPException(status_code=400, detail="Missing CallSid in request") - print(f"Processing call with ID: {call_sid}") + # Extract the caller's phone number + caller_phone = str(data.get("From", "unknown-caller")) + print(f"Processing call with ID: {call_sid} from {caller_phone}") # Create a Daily room with SIP capabilities try: - room_details = await create_sip_room(request.app.session) + room_details = await create_sip_room(request.app.session, caller_phone) except Exception as e: print(f"Error creating Daily room: {e}") raise HTTPException(status_code=500, detail=f"Failed to create Daily room: {str(e)}") diff --git a/examples/phone-chatbot-daily-twilio-sip/utils/daily_helpers.py b/examples/phone-chatbot-daily-twilio-sip/utils/daily_helpers.py index 46412aedf..2c42efb9d 100644 --- a/examples/phone-chatbot-daily-twilio-sip/utils/daily_helpers.py +++ b/examples/phone-chatbot-daily-twilio-sip/utils/daily_helpers.py @@ -29,13 +29,23 @@ async def get_daily_helper(session: Optional[aiohttp.ClientSession] = None) -> D ) -async def create_sip_room(session: Optional[aiohttp.ClientSession] = None) -> Dict[str, str]: - """Create a Daily room with SIP capabilities for phone calls.""" +async def create_sip_room( + session: Optional[aiohttp.ClientSession] = None, caller_phone: str = "unknown-caller" +) -> Dict[str, str]: + """Create a Daily room with SIP capabilities for phone calls. + + Args: + session: Optional aiohttp session to use for API calls + caller_phone: The phone number of the caller to use in display name + + Returns: + Dictionary with room URL, token, and SIP endpoint + """ daily_helper = await get_daily_helper(session) # Configure SIP parameters sip_params = DailyRoomSipParams( - display_name="phone-user", + display_name=caller_phone, video=False, sip_mode="dial-in", num_endpoints=1,