Guide · Developer
Add Live Chat and Reactions Without a Chat Server
Add live chat, reactions, direct messages and moderation to a web app with VoltKit RTC's ChatClient: chat tokens from your backend, history, chat-only readers.
- Author
- VoltKit
- Published
- Reading time
- 8 min read
Live chat under a page, beside a video, next to a match: it makes a page feel inhabited, and teams keep postponing it because it seems to need a chat server, a database for history and a rate limiter. With VoltKit RTC it needs none of those. A chat channel exists the moment someone opens it, your backend mints a chat token per user, and the browser SDK's ChatClient sends and receives messages, reactions and direct messages over a connection the service manages. This guide adds live chat and reactions to a web app without running a chat server: the token endpoint, the browser client, reactions that are not stored, history, moderation and posting from your backend.
Chat is part of every VoltKit RTC room, so a room with video or voice has it already, on the same connection. This guide is about the other case: a page with chat and nothing else, or an audience that reads along without joining the room.
Before you start
You need a VoltKit account and an RTC project; the quickstart creates both and gives you the API base URL and secret. Chat needs no media setting: there is nothing to switch on, and chat messages and chat-only connections are not billed. Your users sign in with your own login, and the page never holds the API secret.
Step 1: mint a chat token on your backend
A chat token admits one user to one channel, with no media rights. Your backend mints it for a signed-in user, with your API secret, and returns the token and the socket URL to the page:
curl -X POST "$VOLTKIT_RTC_URL/v1/chat/show-42/tokens" \
-H "X-API-Key: $VOLTKIT_RTC_SECRET" \
-H "Content-Type: application/json" \
-d '{"identity":"user-99","role":"viewer"}'
{
"token": "eyJhbGciOi...",
"wsUrl": "wss://your-api-base-url/ws/chat",
"role": "viewer",
"identity": "user-99",
"channel": "show-42",
"expiresAt": 1755600600
}
The channel is any name you choose, such as the id of the page, the article or the match. A channel shares its name with the room of the same name, so the people in room show-42 and the people who are only in its chat are in one conversation. A chat token cannot join a room, and a room token cannot open a chat-only connection: admitting someone to chat never admits them to video. With the Node.js server SDK the same call is rtc.createChatToken({ channel, identity }), and Python, Go, PHP and Java have it too.
Step 2: connect from the browser
npm install @voltkit-rtc/client
ChatClient opens a connection that carries chat and nothing else. Wire the events, connect, and the recent history comes with the join:
import { ChatClient } from "@voltkit-rtc/client";
const chat = new ChatClient(wsUrl, token);
chat.on("message", (m) => appendToList(m)); // includes your own
chat.on("messageDeleted", ({ id }) => removeFromList(id));
chat.on("chatMuted", ({ identity, muted }) => lockComposer(identity, muted));
chat.on("typing", ({ identity, typing }) => showTyping(identity, typing));
const { messages, members } = await chat.connect(); // recent history comes with the join
renderAll(messages);
await chat.sendMessage("hello");
Your own message comes back on message too, so the list has one source of truth. A message is JSON with an id that increases within the channel, from, a type (text unless you say otherwise), text of up to 4096 bytes, and up to 4 KB of metadata the service never reads. Render text as text, never as HTML: it is delivered exactly as it was sent, and escaping is your renderer's job. The service refreshes the token by itself, and the client reconnects with up to eight attempts; closed says when it is over, with left, ended or gave-up.
Step 3: reactions that are not stored
Hearts, claps and emoji rain are worth showing and not worth replaying to everyone who joins later. Send them as ephemeral messages: delivered to everyone connected now, then forgotten:
await chat.sendMessage("", { type: "reaction", metadata: { emoji: "heart" }, ephemeral: true });
A message needs text or metadata, so a reaction with an empty text and an emoji in metadata is a message like any other; draw it as a floating heart rather than a line in the list. type is any short lowercase name you define: reaction, sticker, gift. The gift events of a live room travel the same way, with the gift's id in metadata, as add gift assets to an RTC app shows. Emoji storms are fine: the rates only stop machines flooding a channel, at 20 messages a second per user and 1,000 a second per channel.
Step 4: direct messages and typing
A direct message reaches its recipient and the sender's own devices, and nobody else; it is absent from everyone else's history:
await chat.sendMessage("can you hear me?", { to: "user-7" });
A typing indicator is one call, safe on every keystroke, because the service limits it to one notice a second:
await chat.setTyping(true);
Step 5: history
A chat-only connection receives the most recent 50 messages when it joins. Page further back with the oldest id you hold:
const older = await chat.getMessages({ before: messages[0].id, limit: 50 });
Each channel keeps its most recent 500 messages. History is cleared when the channel's room closes, or after 24 hours of silence for a channel with no room: this is a live chat, not an archive. To keep messages, take them by webhook into your own database.
Step 6: moderation and posting from your backend
A host or moderator mutes someone with chat.muteChat(identity, true) and deletes any message with chat.deleteMessage(id); anyone may delete their own. A mute is held for the channel, not for the connection, so reconnecting does not undo it, and a muted user can still read. The same actions work from your backend without holding a connection, which is also how a system notice or a gift announcement is posted:
// Admit someone to a channel's chat with no media rights (role defaults to viewer).
const chat = await rtc.createChatToken({ channel: "show-42", identity: "user-99" });
// -> { token, wsUrl, role, identity, channel, expiresAt }
// Take part without holding a connection.
await rtc.sendMessage({ channel: "show-42", text: "The show starts in 5 minutes", type: "system" });
await rtc.sendMessage({ channel: "show-42", type: "gift", from: "user-7", metadata: { gift: "rose", count: 5 } });
await rtc.sendMessage({ channel: "show-42", type: "reaction", metadata: { emoji: "heart" }, ephemeral: true }); // not stored
await rtc.sendMessage({ channel: "show-42", to: "user-13", text: "Please keep it friendly" }); // a direct message
const messages = await rtc.listMessages("show-42", { limit: 100 }); // oldest first
const older = await rtc.listMessages("show-42", { before: messages[0].id }); // the page before that
await rtc.deleteMessage("show-42", messageId);
await rtc.muteChat("show-42", "user-13"); // survives reconnecting; they can still read
await rtc.unmuteChat("show-42", "user-13");
await rtc.listChatMutes("show-42"); // -> ["user-13"]
await rtc.getChatInfo("show-42"); // -> { channel, members }
Your backend's own posts skip the per-user rate, since your backend is the authority on your users. getChatInfo returns the member count, everyone connected to the channel, in the room or only in its chat, which makes a good "watching now" figure.
What chat is for, and its limits
Chat carries the conversation beside a page, a room or a match: text, emoji, stickers and gift events. It is not a file transfer or a place to store data. A message whose text or metadata is mostly a long run of encoded characters is refused as a file, with bad-params on a connection and 400 over REST; emoji-heavy text, links and the JSON of a gift all pass. Past a rate, sending answers rate-limited, and error.data names the limit and when to try again: show it rather than retry.
Each project may send 20,000 messages a day, plus 200 more for every participant-minute of rooms it used that day, so a busy room earns its own allowance. The full table is on Chat, and GET /v1/usage shows where a project stands today. If your app needs more, write to us.
Test it
Open the page in two browsers as two users. Send a message from each, a reaction, a direct message, and mute one user from the other; reload the muted user's page and check the composer stays locked. Then paste a message with a link and one with only emoji: both pass. The JSON Formatter is handy for reading a message or a token reply while you build:
Read a message payload with theJSON FormatterChat beside a call
When the page also has video or voice, there is nothing more to build: the room's StreamClient has the same chat methods and events, so a host needs no ChatClient. Add a video call to a Next.js app has the call, add voice chat to a browser game uses the same reactions as emotes, and the React and React Native SDKs listen with useVoltkitEvent("message", ...).
Chat on its own uses no minutes at all. When you add a room beside it, every account gets 10,000 free participant-minutes every month, shared by all your projects and spent before anything paid: what the free minutes cover.
Where to go next
- Chat: every field, the limits and the REST calls.
- Live chat: what the room's chat does, at a glance.
- Webhooks: keep messages and events in your own database.
While you develop, the JWT Decoder shows a chat token's channel and expiry on your own device and never sends it anywhere:
Inspect a test token with theJWT DecoderFrequently asked questions
Do I need to run a chat server?
No. VoltKit RTC carries the messages, keeps the recent history and enforces the rates and mutes. What you run is one endpoint on your backend that mints a chat token for a signed-in user. The page connects with the token and sends and receives messages over a WebSocket the SDK manages.
Is chat billed?
No. Chat messages and chat-only connections are counted in your usage and not charged. Each project has a daily allowance of messages that grows with its live minutes, and the limits only stop machines flooding a channel, not people typing.
Can people chat without joining a call?
Yes. A chat-only connection carries messages and nothing else, for an audience that reads along without sitting in a room. The people in the room and the people only in its chat are in one conversation, and a chat token can never admit someone to video.
How do I moderate a chat?
A host or moderator mutes someone with muteChat and deletes any message with deleteMessage, from the page or from your backend over REST. A mute is held for the channel, so reconnecting does not undo it, and a muted person can still read.
Is the chat history kept?
Each channel keeps its most recent 500 messages, and a chat-only connection receives the last 50 when it joins. History is cleared when the channel's room closes, or after 24 hours of silence for a channel with no room. To keep messages for good, take them by webhook into your own database.