Raven Docs

Chat Quickstart

Install, authenticate, connect, and send your first message — on every supported SDK.

What you'll build: a conversation two users can send messages into, with one seeing the other's messages arrive live.

Prerequisites: a Raven project and a project API key (see API Keys) — conversations are created and chat tokens are minted with it, server-side, and never in a browser or app.

1. Install

Not published to npm yet. The commands below are what installation will look like once these packages are released. Until then, install from a local checkout — see Installing from source.

npm install @corvidhq/chat

2. Create a conversation (once, from your backend)

import { Raven } from '@corvidhq/server';
const raven = new Raven({ apiKey: process.env.RAVEN_API_KEY });
 
const conversation = await raven.chat.createConversation({
  name: 'support-room-42',
  members: [{ userId: 'alice', role: 'ADMIN' }, { userId: 'bob' }],
});

3. Authenticate — mint a token per user

const token = await raven.chat.createToken({
  userId: 'alice',
  conversations: [conversation.publicId],
});

4. Connect from the client

import { createChatClient } from '@corvidhq/chat';
 
const chat = createChatClient({ token: token.token, apiUrl: token.apiUrl });
await chat.connect({ room: conversation.publicId });

5. Send a message

await chat.sendMessage({ text: 'Hello everyone!' });

6. Receive messages

chat.on('message', (message) => console.log(message.senderId, message.text));

You receive your own messages back too — render the same server-ordered row everyone else does, rather than an optimistic local copy.

7. Disconnect

await chat.disconnect();

What Raven handles vs. what you handle

Raven handles: the WebSocket connection, reconnection with backoff and catch-up, message ordering and durability, and idempotent retries.

You handle: minting tokens from your own authenticated backend session, and the UI around messages/typing/presence.

Common errors

ErrorWhyFix
chat:send scope missingToken was minted without it, or the role doesn't grant it.Check the member's role — see Members.
Message never arrives for other usersRejected server-side; a rejection never round-trips as a message event.Listen for error too, not just message — see Troubleshooting.
senderId in the request is ignoredA browser chat token can't set it.Expected — see Messages.

Production notes

  • Never call raven.chat.createConversation()/createToken() (or any @corvidhq/server/raven-sdk method) from a browser or app.
  • Derive userId from your own authenticated session — a chat token minted for the wrong user lets them send as someone else.
  • clientMessageId is attached automatically if you don't supply one, so retries from the SDK itself are already safe. Supply your own only when you control the retry (a job queue, an offline outbox).