Skip to main content

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

PropertyValue
Function Nameprocess-webhook-queue
HTTP MethodAny (no method restriction)
AuthenticationNone (cron/internal invocation). The source code explicitly notes "Auth check removed for cron compatibility."
Required RoleNone (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

StatusCondition
500Failed to claim a batch from the queue, or unhandled top-level exception

Behavior

  1. Claim batch: Calls claim_webhook_queue_batch RPC with a batch size of 50 to atomically claim pending webhook events.
  2. Per-item processing: For each claimed WebhookQueueItem:
    • Calls upsert_call_from_webhook RPC with the item's payload and agency_id to create or update the corresponding call record.
    • On success, marks the item as complete via complete_webhook_queue_item RPC.
    • On failure, marks the item as failed via fail_webhook_queue_item RPC with the error message.
  3. Returns aggregate counts of processed and failed items.

Constants

ConstantValueDescription
BATCH_SIZE50Maximum number of webhook events claimed per invocation

Database Tables / RPCs

Table / RPCOperationDescription
claim_webhook_queue_batch (RPC)Read/WriteAtomically claims up to N pending webhook queue items
upsert_call_from_webhook (RPC)WriteCreates or updates a call record from the webhook payload
complete_webhook_queue_item (RPC)WriteMarks a queue item as successfully processed
fail_webhook_queue_item (RPC)WriteMarks a queue item as failed with an error message

External APIs

None. This function only processes data already stored in the webhook queue.

  • webhook-ingest -- Ingests raw webhook events from Ultravox and queues them for this function to process
  • process-enrichment-queue -- Enriches call records (created by this function) with transcripts and AI analysis