From 3b91aa013a96bdc586424dcf20ded7cc0fbab580 Mon Sep 17 00:00:00 2001 From: Varun Singh <382354+vr000m@users.noreply.github.com> Date: Tue, 13 May 2025 16:00:05 -0700 Subject: [PATCH] added handling for sipHeaders --- .../pipecat-cloud-daily-pstn-server/README.md | 20 ++++++++++++++++++- .../fastapi-webhook-server/server.py | 14 +++++++++++++ .../nextjs-webhook-server/pages/api/dial.js | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/examples/deployment/pipecat-cloud-daily-pstn-server/README.md b/examples/deployment/pipecat-cloud-daily-pstn-server/README.md index 075b69399..11fcca85d 100644 --- a/examples/deployment/pipecat-cloud-daily-pstn-server/README.md +++ b/examples/deployment/pipecat-cloud-daily-pstn-server/README.md @@ -100,7 +100,24 @@ phone numbers with valid values for your use case. ### Dialin Request -The server will receive a request when a call is received from Daily. +The server will receive a request when a call is received from Daily. +The payload that the webhook received is as follows: +```json +{ + // for dial-in from webhook + "To": "+14152251493", + "From": "+14158483432", + "callId": "string-contains-uuid", + "callDomain": "string-contains-uuid", + "sipHeaders": { + // these are fields that can be sent to the sip-interconnect + // for example from twilio to daily + "X-My-Custom-Header": "value", + "x-caller": "+1234567890", + "x-called": "+1987654321", + }, +} +``` ### Dialout Request @@ -158,6 +175,7 @@ curl -X POST http://localhost:3000/api/dial \ "From": "+1987654321", "callId": "call-uuid-123", "callDomain": "domain-uuid-456", + "sipHeader": {}, "dialout_settings": [ { "phoneNumber": "+1234567890", diff --git a/examples/deployment/pipecat-cloud-daily-pstn-server/fastapi-webhook-server/server.py b/examples/deployment/pipecat-cloud-daily-pstn-server/fastapi-webhook-server/server.py index 26dd59283..bf4e22cd1 100644 --- a/examples/deployment/pipecat-cloud-daily-pstn-server/fastapi-webhook-server/server.py +++ b/examples/deployment/pipecat-cloud-daily-pstn-server/fastapi-webhook-server/server.py @@ -39,6 +39,11 @@ class RoomRequest(BaseModel): None, description="A flag to perform voicemail or answeing-machine detection" ) call_transfer: Optional[Dict[str, Any]] = Field(None, description="to initiate a call transfer") + sipHeaders: Optional[Dict[str, Any]] = Field( + None, + alias="sip_headers", + description="Custom SIP headers received from the external SIP provider", + ) class Config: populate_by_name = True @@ -57,6 +62,14 @@ class RoomRequest(BaseModel): "callDomain": "string-contains-uuid" These need to be remapped to dialin_settings + In addition, we may receive in the body that can be + sent to the bot as a custom field, sip_headers + "sipHeaders": { + "X-My-Custom-Header": "value", + "x-caller": "+14158483432", + "x-called": "+14152251493", + }, + "dialout_settings": [ {"phoneNumber": "+14158483432", "callerId": "+14152251493"}, {"sipUri": "sip:username@sip.hostname"} @@ -157,6 +170,7 @@ async def dial(request: RoomRequest, raw_request: Request): "dialout_settings": request.dialout_settings, "voicemail_detection": request.voicemail_detection, "call_transfer": request.call_transfer, + "sip_headers": request.sipHeaders, # passing the SIP headers to the bot }, } diff --git a/examples/deployment/pipecat-cloud-daily-pstn-server/nextjs-webhook-server/pages/api/dial.js b/examples/deployment/pipecat-cloud-daily-pstn-server/nextjs-webhook-server/pages/api/dial.js index a1905bd06..42bb21467 100644 --- a/examples/deployment/pipecat-cloud-daily-pstn-server/nextjs-webhook-server/pages/api/dial.js +++ b/examples/deployment/pipecat-cloud-daily-pstn-server/nextjs-webhook-server/pages/api/dial.js @@ -65,6 +65,7 @@ export default async function handler(req, res) { From, callId, callDomain, + sipHeaders, dialout_settings, voicemail_detection, call_transfer @@ -117,6 +118,7 @@ export default async function handler(req, res) { dialout_settings, voicemail_detection, call_transfer, + sip_headers: sipHeaders, }, };