How it works
Any source, one channel, any sink
Every message flows through a channel: the string between two cans. The payload can be text, audio, video or structured data; the envelope and the infrastructure stay the same.
The message
The universal envelope.
Every message has
- id
- unique
- channelId
- the string it travels on
- direction
- inbound or outbound
- sender
- a participant: user, agent or system
- content
- text, html, json, binary, audio or event
- metadata
- free-form
- timestamp
- when it was made
import { TinPhoneClient } from "@tin-phone/sdk";
const client = new TinPhoneClient({ apiUrl, apiKey });
const channel = await client.createChannel("websocket", [
{ id: "user1", type: "user", name: "Alice" },
{ id: "agent1", type: "agent", name: "Support Bot" },
]);
await client.sendMessage(channel.id, { id: "user1", type: "user" },
{ type: "text", body: "Hello!" });
Channels
Two cans and a string.
A channel has an id, a status (open, paused or closed), its participants, a primary adapter and metadata. Channels do not know about transports; the adapter handles delivery.
Adapters
How a message is carried. Each one implements send(), parse() and, for webhooks, verify().
| Adapter | What it is | Realtime | Both ways | Rich content | Presence | Typing |
|---|---|---|---|---|---|---|
websocket | Durable Objects, presence and typing | Yes | Yes | No | Yes | Yes |
sse | One-way push for dashboards and notifications | Yes | No | No | No | No |
webhook | Async both ways over HTTP, retry with backoff | No | Yes | No | No | No |
slack | Channels and DMs: Events API and chat.postMessage | Yes | Yes | Yes | No | No |
email | Email through an API (SendGrid or Mailgun pattern), inbound webhooks | No | Yes | Yes | No | No |
The AdapterRegistry in @tin-phone/core routes each message to its channel's adapter. A new adapter implements the Adapter interface, declares its capabilities and ships its tests; see Writing an adapter.
Bridges
Two adapters joined, so messages flow between them.
A bridge connects two adapters: a Slack message can go on as an email, a webhook event can reach a WebSocket dashboard. The same envelope crosses the bridge; only the delivery changes.
Receipts and seals
Every step leaves a record that can be checked without trusting the server.
A chain per subject
Each notice, push-to-talk channel and workflow run has its own chain. A receipt names the one before it by hash, so nothing can be removed, reordered or changed unseen.
Signed
Each hash is signed with the server's Ed25519 seal key. The public keys are published at /receipts/v1/keys, current and retired.
Digests, not content
A receipt holds a SHA-256 of what was sent or said, ids and states. The words and the voice are never in it.
Where it runs
| Runtime | Storage | Push | Notes |
|---|---|---|---|
| Cloudflare Workers | D1 | WebSocket (Durable Objects), SSE | No Node APIs; crypto is WebCrypto |
| Node 22, self-hosted | SQLite (node:sqlite) | WebSocket, SSE | packages/server-node; push-to-talk runs here today |
Both sit behind one SqlDatabase interface, so the same SQL runs on D1 and SQLite.