Process Webhook Queue
Background worker function invoked on a schedule (cron) that claims and processes batches of queued webhook events. Each event is transformed into a call record via the upsert_call_from_webhook database RPC.
Endpoint
| Property | Value |
|---|---|
| Function Name | process-webhook-queue |
| HTTP Method | Any (no method restriction) |
| Authentication | None (cron/internal invocation). The source code explicitly notes "Auth check removed for cron compatibility." |
| Required Role | None (cron) |
Request
Headers
No headers are required. This function is designed to be invoked by a Supabase cron scheduler or internal trigger without user authentication.
Body
No request body is expected. The function discovers work by claiming items from the webhook queue.
Response
Success (200)
{
"processed": 45,
"failed": 2
}
Success -- No Pending Items (200)
{
"processed": 0
}
Error Responses
| Status | Condition |
|---|---|
| 500 | Failed to claim a batch from the queue, or unhandled top-level exception |
Behavior
- Claim batch: Calls
claim_webhook_queue_batchRPC with a batch size of 50 to atomically claim pending webhook events. - Per-item processing: For each claimed
WebhookQueueItem:- Calls
upsert_call_from_webhookRPC with the item'spayloadandagency_idto create or update the corresponding call record. - On success, marks the item as complete via
complete_webhook_queue_itemRPC. - On failure, marks the item as failed via
fail_webhook_queue_itemRPC with the error message.
- Calls
- Returns aggregate counts of processed and failed items.
Constants
| Constant | Value | Description |
|---|---|---|
BATCH_SIZE | 50 | Maximum number of webhook events claimed per invocation |
Database Tables / RPCs
| Table / RPC | Operation | Description |
|---|---|---|
claim_webhook_queue_batch (RPC) | Read/Write | Atomically claims up to N pending webhook queue items |
upsert_call_from_webhook (RPC) | Write | Creates or updates a call record from the webhook payload |
complete_webhook_queue_item (RPC) | Write | Marks a queue item as successfully processed |
fail_webhook_queue_item (RPC) | Write | Marks a queue item as failed with an error message |
External APIs
None. This function only processes data already stored in the webhook queue.
Related Functions
webhook-ingest-- Ingests raw webhook events from Ultravox and queues them for this function to processprocess-enrichment-queue-- Enriches call records (created by this function) with transcripts and AI analysis