|
| 1 | +# Handling PSTN/SIP Dial-in on Pipecat Cloud |
| 2 | + |
| 3 | +This repository contains two server implementations for handling |
| 4 | +the pinless dial-in workflow in Pipecat Cloud. This is the companion to the |
| 5 | +Pipecat Cloud [pstn_sip starter image](https://github.com/daily-co/pipecat-cloud-images/tree/main/pipecat-starters/pstn_sip). |
| 6 | +In addition you can use `/api/dial` to trigger dial-out, and |
| 7 | +eventually, call-transfers. |
| 8 | + |
| 9 | +1. [FastAPI Server](fastapi-webhook-server/README.md) - |
| 10 | + A FastAPI implementation that handles PSTN (Public Switched Telephone |
| 11 | + Network) and SIP (Session Initiation Protocol) calls using the Daily API. |
| 12 | + |
| 13 | +2. [Next.js Serverless](nextjs-webhook-server/README.md) - |
| 14 | + A Next.js API implementation designed for deployment on Vercel's |
| 15 | + serverless platform. |
| 16 | + |
| 17 | +Both implementations provide: |
| 18 | + |
| 19 | +- HMAC signature validation for pinless webhook |
| 20 | +- Structured logging |
| 21 | +- Support for dial-in and dial-out settings |
| 22 | +- Voicemail detection and call transfer functionality (coming soon) |
| 23 | +- Test request handling |
| 24 | + |
| 25 | +## Choosing an Implementation |
| 26 | + |
| 27 | +- Use the **FastAPI Server** if you: |
| 28 | + |
| 29 | + - Need a standalone server |
| 30 | + - Prefer Python and FastAPI |
| 31 | + - Want to deploy to traditional hosting platforms |
| 32 | + |
| 33 | +- Use the **Next.js Serverless** implementation if you: |
| 34 | + - Want serverless deployment |
| 35 | + - Prefer JavaScript/TypeScript |
| 36 | + - Already use Next.js and Vercel for other projects |
| 37 | + - Need quick scaling and zero maintenance |
| 38 | + |
| 39 | +## Prerequisites |
| 40 | + |
| 41 | +### Environment Variables |
| 42 | + |
| 43 | +Both implementations require similar environment variables: |
| 44 | + |
| 45 | +- `PIPECAT_CLOUD_API_KEY`: Pipecat Cloud API Key, begins with pk\_\* |
| 46 | +- `AGENT_NAME`: Your Daily agent name |
| 47 | +- `PINLESS_HMAC_SECRET`: Your HMAC secret for request verification |
| 48 | +- `LOG_LEVEL`: (Optional) Logging level (defaults to 'info') |
| 49 | + |
| 50 | +See the individual README files in each implementation directory for |
| 51 | +specific setup instructions. |
| 52 | + |
| 53 | +### Phone number setup |
| 54 | + |
| 55 | +You can buy a phone number through the Pipecat Cloud Dashboard: |
| 56 | + |
| 57 | +1. Go to `Settings` > `Telephony` |
| 58 | +2. Follow the UI to purchase a phone number |
| 59 | +3. Configure the webhook URL to receive incoming calls (e.g. `https://my-webhook-url.com/api/dial`) |
| 60 | + |
| 61 | +Or purchase the number using Daily's |
| 62 | +[PhoneNumbers API](https://docs.daily.co/reference/rest-api/phone-numbers). |
| 63 | + |
| 64 | +```bash |
| 65 | +curl --request POST \ |
| 66 | +--url https://api.daily.co/v1/domain-dialin-config \ |
| 67 | +--header 'Authorization: Bearer $TOKEN' \ |
| 68 | +--header 'Content-Type: application/json' \ |
| 69 | +--data-raw '{ |
| 70 | + "type": "pinless_dialin", |
| 71 | + "name_prefix": "Customer1", |
| 72 | + "phone_number": "+1PURCHASED_NUM", |
| 73 | + "room_creation_api": "https://example.com/api/dial", |
| 74 | + "hold_music_url": "https://example.com/static/ringtone.mp3", |
| 75 | + "timeout_config": { |
| 76 | + "message": "No agent is available right now" |
| 77 | + } |
| 78 | +}' |
| 79 | +``` |
| 80 | + |
| 81 | +The API will return a static SIP URI (`sip_uri`) that can be called |
| 82 | +from other SIP services. |
| 83 | + |
| 84 | +### `room_creation_api` |
| 85 | + |
| 86 | +To make and receive calls currently you have to host a server that |
| 87 | +handles incoming calls. In the coming weeks, incoming calls will be |
| 88 | +directly handled within Daily and we will expose an endpoint similar |
| 89 | +to `{service}/start` that will manage this for you. |
| 90 | + |
| 91 | +In the meantime, the server described below serves as the webhook |
| 92 | +handler for the `room_creation_api`. Configure your pinless phone |
| 93 | +number or SIP interconnect to the `ngrok` tunnel or |
| 94 | +the actual server URL, append `/api/dial` to the webhook URL. |
| 95 | + |
| 96 | +## Example curl commands |
| 97 | + |
| 98 | +Note: Replace `http://localhost:3000` with your actual server URL and |
| 99 | +phone numbers with valid values for your use case. |
| 100 | + |
| 101 | +### Dialin Request |
| 102 | + |
| 103 | +The server will receive a request when a call is received from Daily. |
| 104 | + |
| 105 | +### Dialout Request |
| 106 | + |
| 107 | +Dial a number, will use any purchased number |
| 108 | + |
| 109 | +```bash |
| 110 | +curl -X POST http://localhost:3000/api/dial \ |
| 111 | + -H "Content-Type: application/json" \ |
| 112 | + -d '{ |
| 113 | + "dialout_settings": [ |
| 114 | + { |
| 115 | + "phoneNumber": "+1234567890", |
| 116 | + } |
| 117 | + ] |
| 118 | + }' |
| 119 | +``` |
| 120 | + |
| 121 | +Dial a number with callerId, which is the UUID of a purchased number. |
| 122 | + |
| 123 | +```bash |
| 124 | +curl -X POST http://localhost:3000/api/dial \ |
| 125 | + -H "Content-Type: application/json" \ |
| 126 | + -d '{ |
| 127 | + "dialout_settings": [ |
| 128 | + { |
| 129 | + "phoneNumber": "+1234567890", |
| 130 | + "callerId": "purchased_phone_uuid" |
| 131 | + } |
| 132 | + ] |
| 133 | + }' |
| 134 | +``` |
| 135 | + |
| 136 | +Dial a number |
| 137 | + |
| 138 | +```bash |
| 139 | +curl -X POST http://localhost:3000/api/dial \ |
| 140 | + -H "Content-Type: application/json" \ |
| 141 | + -d '{ |
| 142 | + "dialout_settings": [ |
| 143 | + { |
| 144 | + "phoneNumber": "+1234567890", |
| 145 | + "callerId": "purchased_phone_uuid" |
| 146 | + } |
| 147 | + ] |
| 148 | + }' |
| 149 | +``` |
| 150 | + |
| 151 | +### Advanced Request with Voicemail Detection |
| 152 | + |
| 153 | +```bash |
| 154 | +curl -X POST http://localhost:3000/api/dial \ |
| 155 | + -H "Content-Type: application/json" \ |
| 156 | + -d '{ |
| 157 | + "To": "+1234567890", |
| 158 | + "From": "+1987654321", |
| 159 | + "callId": "call-uuid-123", |
| 160 | + "callDomain": "domain-uuid-456", |
| 161 | + "dialout_settings": [ |
| 162 | + { |
| 163 | + "phoneNumber": "+1234567890", |
| 164 | + "callerId": "purchased_phone_uuid" |
| 165 | + } |
| 166 | + ], |
| 167 | + "voicemail_detection": { |
| 168 | + "testInPrebuilt": true |
| 169 | + }, |
| 170 | + "call_transfer": { |
| 171 | + "mode": "dialout", |
| 172 | + "speakSummary": true, |
| 173 | + "storeSummary": true, |
| 174 | + "operatorNumber": "+1234567890", |
| 175 | + "testInPrebuilt": true |
| 176 | + } |
| 177 | + }' |
| 178 | +``` |
0 commit comments