Chat and calls
1:1 and group chat, and ringing voice and video calls, between your own app's users.
Give the people in your app messaging and calling, like a messenger, inside your product and with your own interface. Your server creates users and hands each device a short-lived user token; the device then chats and calls as that person through @deewanio/sdk/client. Every call is a Deewan meeting underneath, so recording, breakout rooms, polls, captions and strict end-to-end encryption all work on it.
| Who calls it | Authorized by | |
|---|---|---|
/users, /channels, /messages, /calls | Your server | Your API key (chat:read, chat:write, calls:write) |
/chat/* | Your users' browsers and apps | That user's token (dwu_…): only what they're allowed |
1. On your server: users and tokens
Users are known by your own ids. Create (or update) someone when they sign in to your app, then give their device a token from an endpoint only signed-in people can reach.
import { Deewan } from "@deewanio/sdk";
const deewan = new Deewan({ apiKey: process.env.DEEWAN_API_KEY! });
// Your own route, behind your own sign-in.
app.post("/deewan/token", requireSignIn, async (req, res) => {
const me = req.user;
await deewan.users.upsert({ id: me.id, name: me.name, image: me.avatarUrl });
const { token } = await deewan.users.createToken(me.id, { expiresIn: 3600 });
res.json({ token });
});Only your server makes tokens, and only for the person who is signed in. A user token can do what that person can (their channels, their calls) and nothing else: it can't create users, read other people's chats or reach your meetings. Revoke the API key and its tokens stop within 30 seconds; delete a user and theirs stop at once.
2. In the browser: connect
import { connectChat } from "@deewanio/sdk/client";
// A function, so the SDK can get a new token when one expires.
const chat = await connectChat(async () => {
const r = await fetch("/deewan/token", { method: "POST" });
return (await r.json()).token;
});
chat.on("message", (m) => render(m));
chat.on("typing", ({ channel_id, user_id }) => showTyping(channel_id, user_id));
chat.on("read", ({ channel_id, user_id, seq }) => showSeen(channel_id, user_id, seq));
chat.on("call", (call) => {
if (call.status === "ringing" && call.created_by !== chat.me.id) showIncomingCall(call);
});| Platform | Package | Calls' audio and video |
|---|---|---|
| Web | connectChat from @deewanio/sdk/client | chat.calls.join(call) |
| React Native / Expo | connectChat from @deewanio/react-native/chat (works in Expo Go) | joinCall(chat, call) from @deewanio/react-native/custom |
| Flutter | DeewanChat.connect from package:deewan/chat.dart | joinCall(chat, call) from package:deewan/custom.dart |
| Your server | @deewanio/sdk (Node) or deewan (Python): users, tokens, channels, calls | — |
The connection stays live and reconnects on its own. After a reconnect, catch up with messages.list(channelId, { after: lastSeq }): every message has a seq (1, 2, 3… in its channel), so nothing is missed or shown twice.
3. Channels and messages
// A 1:1 (asking again returns the same one) or a group, with you as its admin.
const dm = await chat.channels.create({ kind: "direct", members: ["user_456"] });
const group = await chat.channels.create({ kind: "group", members: ["user_456", "user_789"], name: "Study group" });
await chat.messages.send(dm.id, { text: "Hi!" });
await chat.messages.send(group.id, {
text: "Notes from today",
attachments: [{ url: "https://files.example.com/notes.pdf", type: "application/pdf", name: "notes.pdf" }],
});
const { data, has_more } = await chat.messages.list(dm.id, { limit: 50 }); // newest page
await chat.messages.react(data[0].id, "👍");
await chat.channels.markRead(dm.id, data.at(-1)!.seq);
await chat.channels.typing(dm.id); // throttle: once every 2–3 seconds while typing- Attachments are files you host (
https://only); Deewan stores the link, never fetches it. Upload with your own storage and signed URLs. - Retries are safe:
messages.sendgives each message its own id, and sending the same id again returns the same message. - Admins of a group add and remove people, rename it and delete anyone's message; anyone can leave. Your server can do everything, including
frozen: true(only your server posts) and posting as the system. - Deleting a message erases its text, attachments and reactions from Deewan's servers.
4. Voice and video calls
// Caller: rings the others for 45 seconds.
const call = await chat.calls.start({ channel_id: dm.id, kind: "video" });
const meeting = await chat.calls.join(call); // camera + mic, your own UI
// Callee: when "call" arrives with status "ringing".
const meeting = await chat.calls.join(incoming); // answers and connects
await chat.calls.decline(incoming.id); // or says no
// The meeting is the same object as joinMeeting() returns:
meeting.on("participantJoined", (p) => addTile(p));
await meeting.leave(); // ends your part of the callA call's status goes ringing → active → ended, or ends as missed (nobody answered in 45 seconds) or declined (everyone said no). A 1:1 ends when either person leaves; a group call when only one person is left. Calling a channel that already has a call returns that call, so two people calling each other at once land in the same one.
Standard and strict encryption
| standard (default) | strict | |
|---|---|---|
| Media | End-to-end encrypted | End-to-end encrypted |
| The key | Made by Deewan, given to members | Made and kept on the devices; Deewan's servers never have it |
| Recording, captions | Yes | No (the server can't hear the call) |
| Use it for | Most apps | Health, legal, anything that must stay between the people in it |
const call = await chat.calls.start({ members: ["doctor_1"], kind: "video", encryption: "strict" });Recording, breakout rooms and the rest
Every call has a room_id: a private, single-use Deewan room only its members can join. From your server, use it with the room APIs exactly as for meetings: open breakout rooms, run a poll, see who's in it, mute or remove someone, or end it. Recordings made in a call are listed with GET /recordings?room_id= (Recordings).
const call = await deewan.calls.retrieve(callId);
await deewan.breakouts.start(call.room_id, { rooms: 3, duration_seconds: 600 });
await deewan.polls.create(call.room_id, { question: "Ready for the quiz?", options: ["Yes", "Not yet"] });Notifications when the app is closed
A closed app has no live connection, so ring phones with your own push service from webhooks. call.ringing lists who to ring; message.created lists the channel's members. Skip whoever is online (GET /users/{id}) if you'd rather not double-notify.
{
"type": "call.ringing",
"data": {
"call": { "id": "4e2a9b7c-…", "kind": "video", "status": "ringing", "created_by": "teacher_1", "room_id": "5f0c2b8e-…" },
"ring": ["user_123"],
"livemode": true
}
}| Event | When |
|---|---|
message.created / message.updated / message.deleted | A message is sent, edited or deleted |
channel.created / channel.updated / channel.deleted | A channel is made, renamed, frozen or changes members |
call.ringing | A call starts ringing (ring: who to notify) |
call.started | Someone answered |
call.ended / call.missed / call.declined | How a call finished |
Limits and isolation
- Each workspace and environment is sealed: test keys never see live users, and no app can read another's, enforced by the database itself, not only by the API.
- Groups up to 1000 members; calls up to 100 invited; messages up to 8000 characters and 10 attachments; metadata up to 8 KB.
- Per user: 240 requests a minute, 30 messages in 10 seconds, 10 new calls a minute, 6 live connections.