# Workspace Phone Number + Dispatcher Extension Routing Architecture

## Purpose
This document defines the planned Dispatch Spot telephony architecture for workspace-owned business numbers, dispatcher extensions, inbound extension routing, busy/offline fallback behavior, and callback/voicemail continuity.

This track is staged so Dispatch Spot can evolve from a browser dialer into a real business phone system without overloading the normal operator surface.

## End state
A workspace should be able to:
- own one or more business phone numbers
- assign internal extensions to dispatchers
- route inbound calls by extension
- fall back cleanly when a dispatcher is busy or offline
- preserve voicemail and callback continuity inside Dispatch Spot

## Core architecture rules
- The workspace owns the public phone numbers.
- Dispatchers get internal extensions.
- Inbound calls hit the workspace number first.
- Extension routing is controlled by Dispatch Spot, not hard-coded in Twilio.
- Busy/offline behavior must be explicit and reviewable.
- Callback and voicemail continuity must remain tied to the workspace record system.

## Planned workspace settings
- workspace phone number inventory
- inbound routing status
- extension digit length
- main routing mode
- busy fallback mode
- offline fallback mode
- callback continuity toggle
- voicemail toggle

## Planned dispatcher assignment model
Each dispatcher extension assignment should support:
- user id
- extension
- enabled/disabled state
- busy-route preference
- offline-route preference
- update timestamp

## Inbound routing flow
1. call hits workspace-owned number
2. workspace main routing rule runs
3. caller enters extension or reaches queue
4. Dispatch Spot resolves dispatcher assignment
5. system checks busy/offline state
6. route to dispatcher, backup path, queue, voicemail, or callback continuity

## Fallback modes
### Busy fallback
- keep primary dispatcher
- backup dispatcher
- dispatch queue
- voicemail

### Offline fallback
- dispatch queue
- voicemail
- callback task

## Continuity requirements
When the assigned dispatcher cannot take the call, Dispatch Spot should be able to:
- create callback continuity
- preserve caller context
- preserve workspace number context
- preserve intended dispatcher/extension target
- keep follow-up visible in the workspace workflow

## Early scaffolding in v309
v309 adds:
- workspace phone system planning section in Workspace Settings
- staged workspace number inventory input
- dispatcher extension assignment scaffolding
- inbound routing / fallback planning controls
- continuity-focused documentation for future inbound routing builds

## Not in scope yet
This track does not yet complete:
- production inbound Twilio routing
- live IVR / extension capture
- extension-based dispatcher ringing
- voicemail capture pipeline
- callback task automation from live inbound failures

Those belong to later telephony wiring phases.
