Skip to main content

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 domain
  • To / to — the called number
  • From / from — the caller number
  • Direction — call direction
  • Additional Cloudonix session fields

Step 2: Voice Webhook Authentication​

VerifyVoiceWebhookAuth runs first:

  1. Extracts the Bearer token from the Authorization header.
  2. Extracts Domain and the to/from numbers.
  3. Looks up CloudonixSettings by domain_name, then domain_uuid.
  4. Compares the Bearer token to domain_requests_api_key with hash_equals().
  5. Injects _organization_id into the request.
  6. Returns a CXML response on failure: 401 for a token or domain problem, 400 when Domain or the to number 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:

DirectionHandlerTypical Use
subscriberhandleSubscriberDirection()Internal PBX user call.
inboundhandleInboundDirection()External or internal-from-DID.
outboundhandleOutgoingDirection()Outbound calls only.
applicationhandleApplicationDirection()API-initiated calls.
defaulthandleUnknownDirection()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):

  1. Look up an active did_numbers row with that phone number in the organization (InboundRoutingService::handleDidRouting()).
  2. Read the DID's routing_type, and the target ID from routing_config (for example routing_config.ring_group_id).
  3. 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 TypeModelHandled by
extensionExtensionStrategy for the extension's type (UserRoutingStrategy, ForwardRoutingStrategy, AiAgentRoutingStrategy, and so on)
ring_groupRingGroupRingGroupRoutingStrategy
call_queueCallQueueQueueRoutingStrategy
ivr_menuIvrMenuIvrRoutingStrategy
conference_roomConferenceRoomConferenceRoutingStrategy
business_hoursBusinessHoursScheduleInboundRoutingService resolves the schedule's current open or closed target, then that target's strategy runs
ai_assistantAiAssistantAiAgentRoutingStrategy
ai_load_balancerAiAssistantLoadBalancerAiLoadBalancerRoutingStrategy
unavailablenonePlays 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:

MethodCXML 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:

  1. Authenticate with VerifyVoiceWebhookAuth.
  2. Validate the IVR menu exists and is active.
  3. Check/update call state in Redis (turn count, input history).
  4. No input → replay or increment turns toward failover.
  5. Valid option → route to the configured destination.
  6. 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 wins SET 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 through QueueCallLifecycleService): 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:resolved makes 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 from and to to E.164.
  • Identifies the organization from the middleware-injected _organization_id or by DID lookup.
  • Dispatches ProcessInboundCallJob to create a CallLog and broadcast CallInitiated (call.initiated on the presence-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 SessionUpdate record.
  • Triggers call notification webhooks if configured.
  • Does not broadcast. The CallAnswered and CallEnded event 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 CallDetailRecord via CallDetailRecord::createFromWebhook(). The call direction (incoming, outgoing, internal or application) is copied from the latest session update. extension_number comes 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 its extension_number is still null.
  • Updates the legacy CallLog record if one exists.
  • Creates a final SessionUpdate with action = 'cdr_final_status'.
  • Triggers call notification webhooks for the final status.
  • For auto-dialer calls:
    • Updates AutoDialerCallSession and AutoDialerDestination.
    • Updates campaign counters.
    • Decrements the Redis CAC counter using the dialer connection (raw key dialer:cac:{campaign_id}:active). Laravel owns this count, and dialer:reconcile-cac heals drift every minute.

Call State in Redis​

  • cdr:create:{organization_id}:{call_id} — lock that keeps a CDR from being created twice
  • cdr: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}), with ivr:idempotency:{event_id}
  • Dialer CAC counters — dialer:cac:{campaign_id}:active
  • Call queue state — acd:* keys owned by the ACD worker, and extension presence acd:presence:{organization_id}:{extension}