From a Discord voice channel to a real phone number: the CallBot architecture
This is the part most "SIP for Discord" products hide: what exactly happens between pressing a button in a voice channel and a phone ringing on a mobile network. Here is the whole path.
Components
- Discord bot — JDA client per instance, one per licensed bot, joined to the server voice channel;
- SIP stack — PJ SIP embedded in the same process: registration, dialogs, media, DTMF;
- Control API — HTTPS endpoints to create/start/stop instances and receive call events;
- Panel + billing — licensing, balances, subscriptions, call history.
Call flow, step by step
- Provisioning. The panel writes a bot record: Discord token, guild id, SIP provider credentials, caller ID, licence. The instance starts in a container with its own config.
- Registration. PJ SIP sends
REGISTERto the provider with digest authentication and refreshes it before expiry, so the number stays reachable after restarts and IP changes. - Origination. An operator types
/call +1…or uses a panel button. The bot sendsINVITEwith an SDP offer: Opus stripped if the provider cannot take it, G.711/G.722 offered, RTP port opened on the instance. - Negotiation.
100 Trying,180 Ringing,200 OKwith the provider's SDP answer,ACK. From this moment media flows. - Media. Discord audio (Opus, 48 kHz) is decoded, resampled and encoded to the negotiated codec; the phone side is decoded back into Opus and played into the voice channel. Echo cancellation and jitter buffers run per leg.
- In-call features. DTMF goes out as RFC 2833 or in-band depending on the provider; hold is a re-INVITE with
a=sendonly; volume and mute are handled at the audio pipeline, not by the bot muting itself. - Termination. Either side sends
BYE. The instance finalises the recording, uploads it to S3-compatible storage, and posts an event to the panel. - Reporting. The panel writes a call row (number, direction, duration, recording URL, guild, bot) and increments the licence call counter. Search, filters and sorting work on top of that table.
Why an embedded stack and not a gateway
A media gateway between Discord and SIP introduces a second failure domain and usually loses DTMF, hold and recording. Embedding PJ SIP means the bot is the endpoint: one process owns the dialog and the audio, so state is never split between two services.
What the panel sees
| Event | Stored data |
|---|---|
| Bot started | status, timestamp, version |
| Call started | number, direction, guild, licence, start time |
| Call ended | duration, hangup cause, recording URL |
| Recording ready | S3 object key, size, retention |
Security model in one paragraph
Each bot has its own panel API secret; the public webhook requires a shared secret header; per-instance credentials are never reused across customers; recordings are private objects behind an authenticated endpoint. The SIP credentials belong to the customer's provider, so revocation is immediate on their side.
Conclusion
There is no magic: it is a SIP client with a Discord audio front-end, a database and a billing layer. The engineering work is in the details — codecs, NAT, registration, recording — and that is precisely what separates a working phone line from a demo video.