Skip to content

Telephony and PBX Specification

Overview

The current telephony stack is hybrid. Twilio remains deeply involved in SMS, delivery status, replay, and several call-related flows, while PBX/FreePBX files and Edge Functions support click-to-call and operational call synchronization.

Current Components

PBX-side assets

  • freepbx/gm-call.php
  • freepbx/extensions_custom.conf
  • freepbx/extensions_override_freepbx.conf

Twilio-side assets

  • twilio/call-handle-ib.js
  • twilio/call-handle-ob.js
  • twilio/send-sms-local-cid.js
  • twilio/voicemail-drop.js
  • twilio/supa-handle-ib.js
  • twilio/supa-handle-ob.js
  • supporting scripts such as get-messages.py and test-sms.js

Supabase telephony functions

  • thread-call-dial
  • thread-update-last-call-user
  • thread-voicemail-open
  • lead-pbx-actions
  • lead-pbx-sms-actions
  • call-missed-answered
  • call-recording-transcript
  • voicemail-drop
  • twilio-message-retrieve
  • twilio-message-replay

Outbound Call Flow

Browser preflight

  • The UI calls thread-call-dial to:
  • verify no conflicting active caller
  • stamp thread active caller metadata
  • record analytics

Browser PBX URL generation

  • src/utils/callHelpers.ts builds the PBX click-to-call URL
  • The URL points at https://pbx.glassmaster.app/gm-call.php
  • If both a lead phone and insurance phone are present, they are passed as lead|insurance

PBX originate

  • gm-call.php authenticates to the Asterisk AMI
  • It originates a call to the user extension
  • It passes the target number(s) into the click-to-call-out dialplan context

FreePBX dialplan behavior

  • extensions_custom.conf splits the lead|insurance payload
  • It selects whether the call is a lead call or insurance call
  • It fires async webhooks back to Supabase
  • It dials out through PJSIP/...@Twilio

Inbound and Voicemail Flow

  • FreePBX override files contain macros that fire webhooks on inbound answer and voicemail entry
  • thread-voicemail-open is used to reopen or mark thread/message state when voicemail occurs
  • call-missed-answered handles call lifecycle updates from webhook traffic

SMS Flow Reality

  • The message path is still predominantly Twilio-based
  • message-inbound, message-send, message-delivery-status, campaign-lead-send, and related functions are central to SMS operations
  • PBX helper functions exist, but they do not replace the current Twilio-centered messaging pipeline

Architectural Assessment

What is true today

  • PBX is a real operational part of click-to-call and some webhook flows
  • Twilio is still a real operational part of messaging and portions of calling/transcript behavior
  • The system is not yet a clean “PBX replaced Twilio” architecture

Risks

  • Provider split increases debugging complexity
  • Telephony config is partly encoded in repo files with environment-specific assumptions
  • Some webhook wiring appears operationally brittle because behavior is distributed across PHP, dialplan, Twilio scripts, and Edge Functions

Documentation Rule

When changing telephony behavior, document both: - the UI/API entrypoint - the provider-specific execution path after handoff