Call Flow
This page traces the lifecycle of an inbound call from the moment Cloudonix receives it, through OPBX routing decisions, to CDR and session-update handling.
Overview
Step 1: Cloudonix Receives the Call
When a caller dials a DID number, Cloudonix routes the call to the voice application configured for the domain. The voice application URL points to OPBX (/api/voice/route).
Cloudonix sends a JSON payload that includes:
Domain— the Cloudonix domainTo/to— the called numberFrom/from— the caller numberDirection— call direction- Additional Cloudonix session fields
Step 2: Voice Webhook Authentication
VerifyVoiceWebhookAuth runs first:
- Extracts the Bearer token from the
Authorizationheader. - Extracts
Domainand theto/fromnumbers. - Looks up
CloudonixSettingsbydomain_name, thendomain_uuid. - Compares the Bearer token to
domain_requests_api_keywithhash_equals(). - Injects
_organization_idinto the request. - Returns a CXML response on failure: 401 for a token or domain problem, 400 when
Domainor thetonumber is missing.
If authentication succeeds, the request reaches VoiceRoutingController@handleInbound.
Step 3: VoiceRoutingManager
VoiceRoutingController delegates to App\Services\VoiceRouting\VoiceRoutingManager.
Coach Calls
Before anything else, CoachRoutingService::tryHandle() checks whether the call is a supervisor coaching call (spy_{token}, whisper_{party}_{token} or barge_{token}, dialed from the supervisor's Web Phone) and, if so, answers it with a Cloudonix <Coach> verb.
Direction Dispatch
The manager dispatches by the Direction field:
| Direction | Handler | Typical Use |
|---|---|---|
subscriber | handleSubscriberDirection() | Internal PBX user call. |
inbound | handleInboundDirection() | External or internal-from-DID. |
outbound | handleOutgoingDirection() | Outbound calls only. |
application | handleApplicationDirection() | API-initiated calls. |
| default | handleUnknownDirection() | Falls back to inbound. |
A subscriber call tries, in order: a direct extension dial, the DID routing of the dialed number, then outbound routing (outbound whitelist). The calls are marked internal for call_recording_mode; inbound calls are marked inbound.
For an inbound call, the manager first checks the inbound blacklist against the dialed DID and, on a match, returns the rejection CXML. If the caller (From) is itself one of the organization's numbers, the call is handled as an internal call from a DID.
DID Resolution
For inbound calls, the manager resolves the called DID (To number):
- Look up an active
did_numbersrow with that phone number in the organization (InboundRoutingService::handleDidRouting()). - Read the DID's
routing_type, and the target ID fromrouting_config(for examplerouting_config.ring_group_id). - Load the destination model based on the routing type, then pick the strategy for it.
Destination Types
The DID's routing_type selects the destination. The routing config holds the target ID.
| Routing Type | Model | Handled by |
|---|---|---|
extension | Extension | Strategy for the extension's type (UserRoutingStrategy, ForwardRoutingStrategy, AiAgentRoutingStrategy, and so on) |
ring_group | RingGroup | RingGroupRoutingStrategy |
call_queue | CallQueue | QueueRoutingStrategy |
ivr_menu | IvrMenu | IvrRoutingStrategy |
conference_room | ConferenceRoom | ConferenceRoutingStrategy |
business_hours | BusinessHoursSchedule | InboundRoutingService resolves the schedule's current open or closed target, then that target's strategy runs |
ai_assistant | AiAssistant | AiAgentRoutingStrategy |
ai_load_balancer | AiAssistantLoadBalancer | AiLoadBalancerRoutingStrategy |
unavailable | none | Plays the "destination unavailable" prompt and hangs up |
A DID with no valid destination gets a spoken error prompt (Destination not configured or Unsupported routing configuration) and a hangup.
Step 4: Strategy Execution
InboundRoutingService maps the resolved destination to an ExtensionType (the extension's own type, or RING_GROUP, CONFERENCE, QUEUE, IVR, AI_ASSISTANT, AI_LOAD_BALANCER). VoiceRoutingStrategyExecutor iterates the registered strategies and runs the first one whose canHandle() accepts that type. The selected strategy returns a CXML response via CxmlBuilder.
CxmlBuilder
App\Services\CxmlBuilder\CxmlBuilder generates CXML using DOMDocument. All user-controlled input is XML-encoded to prevent injection. Common CXML outputs include:
| Method | CXML Output |
|---|---|
dialExtension($sipUri) | <Dial><Sip>...</Sip></Dial> |
dialRingGroup($sipUris[]) | <Dial> with multiple <Sip> or <Number> nouns |
simpleDial($dest, ...) | <Dial> for outbound numbers |
joinConference(...) | <Dial><Conference>...</Conference></Dial> |
gather(...) | <Gather> for IVR digit collection |
streamToWebSocket($url) | <Connect><Stream url="wss://..."/></Connect> |
dialQueueConference($room) | <Dial><Conference> for a queue offer through a conference |
busy($msg) / unavailable($msg) / destinationUnavailable() | Error prompt + hangup |
The CXML response is returned to Cloudonix with Content-Type: application/xml.
Step 5: IVR Input Callback
If the route returns an IVR Gather, Cloudonix POSTs the caller's digits to /api/voice/ivr-input. The flow:
- Authenticate with
VerifyVoiceWebhookAuth. - Validate the IVR menu exists and is active.
- Check/update call state in Redis (turn count, input history).
- No input → replay or increment turns toward failover.
- Valid option → route to the configured destination.
- Invalid option → error message, replay, or failover after
max_turns.
Step 6: Ring Group Callback
For ring groups with Sequential and Round Robin strategies, Cloudonix POSTs to /api/callbacks/voice/ring-group-callback after each dial attempt. VoiceRoutingManager::routeRingGroupCallback first reads the dial outcome (DialCallStatus, else CallStatus). When the dial was answered (answered, completed or in-progress), the call is over: the member named by the callback URL's dialed_extension is recorded as the call's answering extension (see CDR) and the response is <Hangup/>, so no further member is dialed and the fallback does not run, for every strategy. Any other outcome (no-answer, busy, failed, canceled, unknown, or no status) determines the next action as before (try the next member, or the fallback).
Simultaneous ring groups
A Simultaneous ring group does not use a multi-number <Dial> (Cloudonix's action callback would not say which member answered). RingGroupRoutingStrategy::handleSimultaneous hands the members to RingGroupConferenceService::offer, which originates one Cloudonix session per member (CloudonixCallsClient::originateApplicationCalls, POST /calls/{domain}/application; destination = the member's extension number or a Forward member's forward_to; caller ID = the caller's From; timeout = the group's ring timeout; URL = the signed /api/callbacks/voice/ring-group-member-connect). The caller's response is <Dial><Conference> into the room r + 15 hex characters of a hash of the group and the caller's session (16 characters, Cloudonix's conference name limit) (hold music while alone; recorded when call recording applies). Redis keeps the pending offer (rg:offer:{group}:{token}, member extension => member session token), each member session (rg:leg:{token}) and the caller (rg:caller:{token}). No member could be originated: the fallback runs at once.
- A member answers: its session fetches
ring-group-member-connect. The first member of the current offer winsSET NX rg:resolved:{group}:{token}, joins the caller's room, the other member sessions are ended (DELETE /calls/{domain}/sessions/{token}) and the member is recorded as the call's answering extension (see CDR). Any later answer gets<Hangup/>. - A member session ends unanswered (session update with a terminal status or
deleted, routed throughQueueCallLifecycleService): it leaves the offer; when the last one leaves, the fallback runs. - The ring timeout plus 10 seconds passes (
ExpireRingGroupOfferJob, delayed): the members still ringing are ended and the fallback runs. - The fallback runs by switching the caller's session (
POST /calls/{domain}/sessions/{token}/application) to the signed/api/callbacks/voice/ring-group-fallback, which answers the group's fallback action.rg:resolvedmakes the winner, the fallback and the caller hanging up (members ended) mutually exclusive. - Both the caller and the winning member end the room on exit, so the call ends when either hangs up.
Step 7: AI Load Balancer Follow-Through
For AI load balancers, /api/callbacks/voice/albs-follow-through handles failover when the primary AI provider is busy or unavailable. It tries the next assistant in the balancer distribution. When none is left, the balancer's fallback runs; a ring-group or call-queue fallback is handed to AiLoadBalancerRoutingStrategy (handleFallbackRingGroup, handleFallbackCallQueue), which runs the target's normal strategy.
A ring group is always routed through RingGroupRoutingStrategy (VoiceRoutingManager::executeStrategy(RING_GROUP, ...)), whatever reaches it: a DID, an extension, an IVR option or failover, a business-hours action (BusinessHoursRoutingService and the IVR business-hours path), or a ring group, call queue or AI load balancer fallback. So its strategy, fallback and answering-member attribution are the same on every path.
Step 8: Call Queues
A call routed to a call queue is enqueued in the ACD worker and hears hold music. After each hold segment Cloudonix POSTs to /api/callbacks/voice/queue-poll. Laravel asks the ACD worker for a decision: wait, dial (the selected agents' extensions) or overflow (to the queue's fallback). The dial result comes back on /api/callbacks/voice/queue-dial-callback. Agents who are already on a call are skipped, using the extension presence kept in Redis from session updates.
Step 9: Asynchronous Notifications
While the call is in progress, Cloudonix sends asynchronous JSON webhooks to OPBX.
call-initiated
POST /api/webhooks/cloudonix/call-initiated
- Normalizes
fromandtoto E.164. - Identifies the organization from the middleware-injected
_organization_idor by DID lookup. - Dispatches
ProcessInboundCallJobto create aCallLogand broadcastCallInitiated(call.initiatedon thepresence-org.{organization_id}channel).
session-update
POST /api/webhooks/cloudonix/session-update
- High-velocity stream of call progress events.
- Filters statuses to the allowed notification list.
- Creates a
SessionUpdaterecord. - Triggers call notification webhooks if configured.
- Does not broadcast. The
CallAnsweredandCallEndedevent classes exist, but no code dispatches them; the Live Calls page polls the API instead (see Real-Time).
CDR
POST /api/webhooks/cloudonix/cdr
- Creates a
CallDetailRecordviaCallDetailRecord::createFromWebhook(). The calldirection(incoming,outgoing,internalorapplication) is copied from the latest session update.extension_numbercomes from the calling subscriber, an extension caller ID, a DID routed directly to an extension, or else the answering extension recorded during routing (single-extension dial, answered ring group member of any strategy, answering queue agent). An answer recorded after the CDR (queue finalization runs after the CDR is stored) updates the CDR if itsextension_numberis still null. - Updates the legacy
CallLogrecord if one exists. - Creates a final
SessionUpdatewithaction = 'cdr_final_status'. - Triggers call notification webhooks for the final status.
- For auto-dialer calls:
- Updates
AutoDialerCallSessionandAutoDialerDestination. - Updates campaign counters.
- Decrements the Redis CAC counter using the
dialerconnection (raw keydialer:cac:{campaign_id}:active). Laravel owns this count, anddialer:reconcile-cacheals drift every minute.
- Updates
Call State in Redis
cdr:create:{organization_id}:{call_id}— lock that keeps a CDR from being created twicecdr:answerer:{organization_id}:{session_token}— the extension that answered the call (first one wins, 24-hour TTL), read when the CDR is stored- IVR state — turn count and digit history (
ivr:call:{call_sid}), withivr:idempotency:{event_id} - Dialer CAC counters —
dialer:cac:{campaign_id}:active - Call queue state —
acd:*keys owned by the ACD worker, and extension presenceacd:presence:{organization_id}:{extension}