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

  1. 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.
  2. Registration. PJ SIP sends REGISTER to the provider with digest authentication and refreshes it before expiry, so the number stays reachable after restarts and IP changes.
  3. Origination. An operator types /call +1… or uses a panel button. The bot sends INVITE with an SDP offer: Opus stripped if the provider cannot take it, G.711/G.722 offered, RTP port opened on the instance.
  4. Negotiation. 100 Trying, 180 Ringing, 200 OK with the provider's SDP answer, ACK. From this moment media flows.
  5. 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.
  6. 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.
  7. Termination. Either side sends BYE. The instance finalises the recording, uploads it to S3-compatible storage, and posts an event to the panel.
  8. 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.

Operational detail: instances are supervised containers with an explicit restart policy. Stopped or expired bots do not come back after a host reboot, which is how a 300-instance fleet stays predictable instead of waking up into a thundering herd.

What the panel sees

EventStored data
Bot startedstatus, timestamp, version
Call startednumber, direction, guild, licence, start time
Call endedduration, hangup cause, recording URL
Recording readyS3 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.

See it live in your own server — it takes one bot token and one SIP account.
Try CallBot