Skip to content

Architecture ​

pixel-phone answers the Pixelbar doorbell. See the overview for the call state diagram.

Parts ​

PartRole
OpenR intercomCalls a list of numbers when the doorbell is pressed, and moves on only when a call goes unanswered
TelnyxOwns the number and sends call events to pixel-phone's webhook (Call Control)
pixel-phoneTracks the call, flips the Home Assistant switch, tells Pixel, and answers when someone accepts
Home AssistantOwns the siren and the button. Turns the siren on and off from the switch, and calls the accept API when the button is pressed
PixelReads call events from a queue, posts the doorbell in Discord with an Answer button, and calls the accept API

Call flow ​

pixel-phone sends Telnyx no command until someone accepts (ADR 0002). If nobody accepts, the call rings out and OpenR tries the next number.

sequenceDiagram
    autonumber
    participant O as OpenR intercom
    participant T as Telnyx
    participant P as pixel-phone
    participant H as Home Assistant
    participant Q as phone-events queue
    participant X as Pixel (Discord)

    O->>T: calls the doorbell number
    T->>P: webhook call.initiated
    P->>P: save call as ringing (accept window 15 s)
    par ring the space
        P->>H: input_boolean.turn_on (pixel_phone_ringing)
    and tell Pixel
        P->>Q: ringing
        Q-->>X: polled about once a second
        X->>X: post the doorbell with an Answer button
    end

    alt someone accepts in time (button or Discord, first wins)
        H->>P: POST /api/v1/calls/current/accept (button)
        Note over X,P: or Pixel: POST /api/v1/calls/{callId}/accept
        P->>T: answer
        P->>T: play the accept recording
        P->>H: input_boolean.turn_off
        P->>Q: accepted (via, by)
        T->>P: webhook call.playback.ended
        P->>T: hang up
        P->>Q: ended
    else window passes, or the caller hangs up
        P->>H: input_boolean.turn_off
        P->>Q: missed (timeout or caller_hung_up)
        Note over O,T: no command was sent, so the call rings out<br/>and OpenR calls the next number
    end

Decisions ​

ADRDecision
0001TypeScript, ports and adapters, fastify
0002Telnyx Call Control, and we answer only on accept
0003Azure Container Apps, one always-warm replica (amended by #29), public ingress, two environments
0004Call state in Table storage, one call at a time, first accept wins
0005Home Assistant owns the siren
0006Pixel through an Azure Storage Queue
0007Telnyx config by a script, not Terraform
0008Recordings in our own Blob container
0009Sentry and pino; phone numbers aren't treated as private
0010Terraform bootstrap and GitHub OIDC

Configuration ​

Every setting is read in src/config.ts. This table grows as features land.

VariableRequiredDescription
PIXEL_PHONE_ENVno (local)local, dev or prod. Terraform sets it
PORTno (3000)HTTP port
LOG_LEVELno (info)pino level
PIXEL_PHONE_VERSION, PIXEL_PHONE_GIT_SHAnoBaked into the image; /version reports them
ACCEPT_WINDOW_SECONDSno (15)How long after a call arrives it can still be accepted (5–120)
TELNYX_API_KEY, TELNYX_PUBLIC_KEYtogetherTelnyx Call Control. Without them the webhook answers 503
HOME_ASSISTANT_URL, HOME_ASSISTANT_TOKEN, HOME_ASSISTANT_RINGING_ENTITYtogetherHome Assistant. Outside prod the entity must end in _dev
API_KEYS_YAMLnoThe accept API's callers
SENTRY_DSN, SENTRY_TRACES_SAMPLE_RATEnoSentry
AZURE_CLIENT_IDin AzureThe app's managed identity
AZURE_STORAGE_ACCOUNT_NAMEin dev and prodStorage for calls, webhook IDs, the queue and recordings
AZURE_STORAGE_CONNECTION_STRINGlocal onlyUseDevelopmentStorage=true for Azurite (just azurite). Unset locally: state is kept in memory
PHONE_EVENTS_QUEUE, MEDIA_CONTAINERnoQueue and blob container names
RECORDING_ACCEPTEDno (accepted.mp3)The accept recording's blob name in the media container (.mp3 or .wav)