README updates

This commit is contained in:
Mark Backman
2025-04-07 10:24:46 -04:00
parent 2229730169
commit fc4c1e4110
3 changed files with 97 additions and 56 deletions

View File

@@ -1,29 +1,31 @@
# Handling PSTN/SIP Dial-in on Pipecat cloud # Handling PSTN/SIP Dial-in on Pipecat Cloud
This repository contains two server implementations for handling This repository contains two server implementations for handling
the pinless dialin workflow in pipecat cloud. This is the companion to the the pinless dial-in workflow in Pipecat Cloud. This is the companion to the
Pipecat Cloud [pstn_sip starter image](https://github.com/daily-co/pipecat-cloud-images/tree/main/pipecat-starters/pstn_sip). Pipecat Cloud [pstn_sip starter image](https://github.com/daily-co/pipecat-cloud-images/tree/main/pipecat-starters/pstn_sip).
In addition you can use `/api/dial` to trigger dial-out, and In addition you can use `/api/dial` to trigger dial-out, and
eventually, call-transfers. eventually, call-transfers.
1. [FastAPI Server](simple-python/README.md) - 1. [FastAPI Server](simple-python/README.md) -
A FastAPI implementation that handles PSTN (Public Switched Telephone A FastAPI implementation that handles PSTN (Public Switched Telephone
Network) and SIP (Session Initiation Protocol) calls using the Daily API. Network) and SIP (Session Initiation Protocol) calls using the Daily API.
2. [Vercel Serverless](vercel/README.md) - 2. [Vercel Serverless](vercel/README.md) -
A Next.js API implementation designed for deployment on Vercel's A Next.js API implementation designed for deployment on Vercel's
serverless platform. serverless platform.
Both implementations provide: Both implementations provide:
- HMAC signature validation for pinless webhook
- HMAC signature validation for pinless webhook
- Structured logging - Structured logging
- Support for dialin and dialout settings - Support for dial-in and dial-out settings
- Voicemail detection and call transfer functionality (coming soon) - Voicemail detection and call transfer functionality (coming soon)
- Test request handling - Test request handling
## Choosing an Implementation ## Choosing an Implementation
- Use the **Simple Python Server** if you: - Use the **Simple Python Server** if you:
- Need a standalone server - Need a standalone server
- Prefer Python and FastAPI - Prefer Python and FastAPI
- Want to deploy to traditional hosting platforms - Want to deploy to traditional hosting platforms
@@ -39,22 +41,24 @@ Both implementations provide:
### Environment Variables ### Environment Variables
Both implementations require similar environment variables: Both implementations require similar environment variables:
- `PIPECAT_CLOUD_API_KEY`: Pipecat Cloud API Key, begins with pk_*
- `PIPECAT_CLOUD_API_KEY`: Pipecat Cloud API Key, begins with pk\_\*
- `AGENT_NAME`: Your Daily agent name - `AGENT_NAME`: Your Daily agent name
- `PINLESS_HMAC_SECRET`: Your HMAC secret for request verification - `PINLESS_HMAC_SECRET`: Your HMAC secret for request verification
- `LOG_LEVEL`: (Optional) Logging level (defaults to 'info') - `LOG_LEVEL`: (Optional) Logging level (defaults to 'info')
See the individual README files in each implementation directory for See the individual README files in each implementation directory for
specific setup instructions. specific setup instructions.
### Phone number setup ### Phone number setup
You can buy a phone number through the Pipecat Cloud Dashboard: You can buy a phone number through the Pipecat Cloud Dashboard:
1. Go to `Settings` > `Telephony` 1. Go to `Settings` > `Telephony`
2. Follow the UI to purchase a phone number 2. Follow the UI to purchase a phone number
3. Configure the webhook URL to receive incoming calls (e.g. `https://my-webhook-url.com/api/dial`) 3. Configure the webhook URL to receive incoming calls (e.g. `https://my-webhook-url.com/api/dial`)
Or purchase the number using Daily's Or purchase the number using Daily's
[PhoneNumbers API](https://docs.daily.co/reference/rest-api/phone-numbers). [PhoneNumbers API](https://docs.daily.co/reference/rest-api/phone-numbers).
```bash ```bash
@@ -74,24 +78,24 @@ curl --request POST \
}' }'
``` ```
The API will return a static SIP URI (`sip_uri`) that can be called The API will return a static SIP URI (`sip_uri`) that can be called
from other SIP services. from other SIP services.
### `room_creation_api` ### `room_creation_api`
To make and receive calls currently you have to host a server that To make and receive calls currently you have to host a server that
handles incoming calls. In the coming weeks, incoming calls will be handles incoming calls. In the coming weeks, incoming calls will be
directly handled within Daily and we will expose an endpoint similar directly handled within Daily and we will expose an endpoint similar
to `{service}/start` that will manage this for you. to `{service}/start` that will manage this for you.
In the meantime, the server described below serves as the webhook In the meantime, the server described below serves as the webhook
handler for the `room_creation_api`. Configure your pinless phone handler for the `room_creation_api`. Configure your pinless phone
number or SIP interconnect to the `ngrok` tunnel or number or SIP interconnect to the `ngrok` tunnel or
the actual server URL, append `/api/dial` to the webhook URL. the actual server URL, append `/api/dial` to the webhook URL.
## Examples curl commands ## Example curl commands
Note: Replace `http://localhost:3000` with your actual server URL and Note: Replace `http://localhost:3000` with your actual server URL and
phone numbers with valid values for your use case. phone numbers with valid values for your use case.
### Dialin Request ### Dialin Request
@@ -114,7 +118,7 @@ curl -X POST http://localhost:3000/api/dial \
}' }'
``` ```
Dial a number with callerId, which is the UUID of a purchased number. Dial a number with callerId, which is the UUID of a purchased number.
```bash ```bash
curl -X POST http://localhost:3000/api/dial \ curl -X POST http://localhost:3000/api/dial \
@@ -145,6 +149,7 @@ curl -X POST http://localhost:3000/api/dial \
``` ```
### Advanced Request with Voicemail Detection ### Advanced Request with Voicemail Detection
```bash ```bash
curl -X POST http://localhost:3000/api/dial \ curl -X POST http://localhost:3000/api/dial \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@@ -171,7 +176,3 @@ curl -X POST http://localhost:3000/api/dial \
} }
}' }'
``` ```

View File

@@ -5,34 +5,49 @@ A FastAPI server that handles PSTN (Public Switched Telephone Network) and SIP (
## Setup ## Setup
1. Clone the repository 1. Clone the repository
2. Install dependencies: 2. Install dependencies:
```bash ```bash
pip install -r requirements.txt pip install -r requirements.txt
``` ```
3. Copy `env.example` to `.env`: 3. Copy `env.example` to `.env`:
```bash ```bash
cp .env.example .env cp env.example .env
``` ```
4. Update `.env` with your credentials: 4. Update `.env` with your credentials:
- `AGENT_NAME`: Your Daily agent name - `AGENT_NAME`: Your Daily agent name
- `PIPECAT_CLOUD_API_KEY`: Your Daily API key - `PIPECAT_CLOUD_API_KEY`: Your Daily API key
- `PINLESS_HMAC_SECRET`: Your HMAC secret for request verification - `PINLESS_HMAC_SECRET`: Your HMAC secret for request verification
## Running the Server ## Running the Server
3. Copy `env.example` to `.env`:
Start the server with: Start the server:
```bash ```bash
python server.py python server.py
``` ```
The server will run on `http://localhost:3000` and you can expose it via ngrok for testing: The server will run on `http://localhost:3000` and you can expose it via ngrok for testing:
```bash
`ngrok http 3000` `ngrok http 3000`
```
> Tip: Use a subdomain for a consistent URL (e.g. `ngrok http -subdomain=mydomain http://localhost:3000`)
## API Endpoints ## API Endpoints
### GET / ### GET /
Health check endpoint that returns a "Hello, World!" message. Health check endpoint that returns a "Hello, World!" message.
### POST /api/dial ### POST /api/dial
Initiates a PSTN/SIP call with the following request body format: Initiates a PSTN/SIP call with the following request body format:
```json ```json
@@ -61,13 +76,15 @@ Initiates a PSTN/SIP call with the following request body format:
``` ```
#### Response #### Response
Returns a JSON object containing: Returns a JSON object containing:
- `status`: Success/failure status - `status`: Success/failure status
- `data`: Response from Daily API - `data`: Response from Daily API
- `room_properties`: Properties of the created Daily room - `room_properties`: Properties of the created Daily room
## Error Handling ## Error Handling
- 401: Invalid signature - 401: Invalid signature
- 400: Invalid authorization header (e.g. missing Daily API key in bot.py) - 400: Invalid authorization header (e.g. missing Daily API key in bot.py)
- 405: Method not allowed (e.g. incorrect route on the webhook URL) - 405: Method not allowed (e.g. incorrect route on the webhook URL)

View File

@@ -7,39 +7,61 @@ Next.js API routes for handling Daily Pipecat requests.
- API endpoint for handling Daily Pipecat requests - API endpoint for handling Daily Pipecat requests
- HMAC signature validation - HMAC signature validation
- Structured logging with Pino - Structured logging with Pino
- Support for dialin and dialout settings - Support for dial-in and dial-out settings
- Voicemail detection and call transfer functionality - Voicemail detection and call transfer functionality
- Test request handling - Test request handling
## Setup ## Setup
1. Clone the repository 1. Clone the repository
2. Install dependencies:
```bash 2. Navigate to the `vercel` directory:
npm install
``` ```bash
3. Create `.env.local` file with your credentials: cd vercel
``` ```
PIPECAT_CLOUD_API_KEY=pk_*
AGENT_NAME=my-first-agent 3. Install dependencies:
PINLESS_HMAC_SECRET=your_hmac_secret
LOG_LEVEL=info ```bash
``` npm install
4. Run the development server: ```
```bash
npm run dev 4. Create `.env.local` file with your credentials:
```
```bash
cp env.local.example .env.local
```
Add your secrets:
```bash
PIPECAT_CLOUD_API_KEY=pk_*
AGENT_NAME=my-first-agent
PINLESS_HMAC_SECRET=your_hmac_secret
LOG_LEVEL=info
```
5. Run the development server:
```bash
npm run dev
```
## API Endpoints ## API Endpoints
### GET /api ### GET /api
Returns a simple "Hello, World!" message with a cute cat emoji to verify the server is running. Returns a simple "Hello, World!" message with a cute cat emoji to verify the server is running.
### POST /api/dial ### POST /api/dial
Handles dialin and dialout requests for Daily Pipecat.
Handles dial-in and dial-out requests for Pipecat Cloud.
#### Test Requests #### Test Requests
The endpoint handles test requests when a webhook is configured. Send a request with `"Test": "test"` to verify your setup: The endpoint handles test requests when a webhook is configured. Send a request with `"Test": "test"` to verify your setup:
```json ```json
{ {
"Test": "test" "Test": "test"
@@ -47,6 +69,7 @@ The endpoint handles test requests when a webhook is configured. Send a request
``` ```
#### Production Request Format #### Production Request Format
```json ```json
{ {
// for dial-in from webhook // for dial-in from webhook
@@ -56,9 +79,9 @@ The endpoint handles test requests when a webhook is configured. Send a request
"callDomain": "string-contains-uuid", "callDomain": "string-contains-uuid",
// for making a dial out to a phone or SIP // for making a dial out to a phone or SIP
"dialout_settings": [ "dialout_settings": [
{"phoneNumber": "+14158483432", "callerId": "purchased_phone_uuid"}, { "phoneNumber": "+14158483432", "callerId": "purchased_phone_uuid" },
{"sipUri": "sip:username@sip.hostname.com"} { "sipUri": "sip:username@sip.hostname.com" }
], ]
} }
``` ```
@@ -79,4 +102,4 @@ The application is configured for Vercel deployment:
- HMAC signature validation for request authentication - HMAC signature validation for request authentication
- Environment variables for sensitive credentials - Environment variables for sensitive credentials
- Method validation (POST only for /dial) - Method validation (POST only for /dial)