Sign inStart for free
ConvoWeb Package
IntroductionPrerequisitesInstallationProject setupQuick start
Package structureConfigurationComponentsHooksAPI integrationSocket events
OverviewReplace entire UIReplace componentsStyle with classNamesThemes & localePhone & video callingIn-call control barTranslationsFeatures
Everyday chat toolsEvent callbacksUnread badgeRich-text messagesPins, stars & datesMessage threadsMentionsCanvas & draftsNotificationsAdmin permissionsServer refusalsSession & token refresh
Host app integrationTroubleshootingFAQVersion historyBest practicesSupport & contact
Web packageGetting started

Project setup

One CSS import, a couple of bundler settings and a config file.

CSS setup

Add these lines to your global CSS file (for example src/index.css or app/globals.css) - once:

css
1@tailwind base;2@tailwind components;3@tailwind utilities;4@import "@convo-sco/sdk-react/styles.css";

That's everything chat needs. styles.cssis pre-compiled, so there's no @source, no @theme and no chat-specific Tailwind config. The @tailwindlines are only for your own app - leave them out if you don't use Tailwind. Set the brand color with the themeColor prop.

Warning

Import it once, globally - not inside a CSS module scoped to one component. Chat modals portal to document.body and need the global styles. See Host app integration for import order and z-index.

Vite - vite.config.ts

Only the chat-related parts - merge them into your existing config:

typescript
1import path from "path";2import { defineConfig } from "vite";3import react from "@vitejs/plugin-react";4 5export default defineConfig({6  plugins: [react()],7  resolve: {8    alias: { "@": path.join(__dirname, "src") },9    // Keep a single copy so the chat shares your app's React, store and socket.10    dedupe: ["react", "react-dom", "@convo-sco/sdk-react"],11  },12  optimizeDeps: {13    exclude: ["@convo-sco/sdk-react"],14    // @convo-sco/sdk-react stays excluded, but Vite must still pre-bundle its nested15    // deps (CJS interop, needed under pnpm). Nested `>` paths mean you do16    // NOT add these to your own package.json.17    include: [18      "@convo-sco/sdk-react > socket.io-client",19      "@convo-sco/sdk-react > zustand",20      "@convo-sco/sdk-react > @videosdk.live/react-sdk",21    ],22  },23  server: {24    proxy: {25      // Optional local-dev proxy for the chat REST API (avoids CORS).26      // Point `apiUrl` at "/chat-api" when running locally, and set27      // `socketUrl` to the real host (see Dev proxy below).28      "/chat-api": {29        target: "https://api.example.com",30        changeOrigin: true,31        secure: true,32        rewrite: (p) => p.replace(/^\/chat-api/, "/api/v1"),33      },34    },35  },36});

Next.js - next.config.ts

typescript
1import type { NextConfig } from "next";2 3const nextConfig: NextConfig = {4  transpilePackages: ["@convo-sco/sdk-react"],5};6 7export default nextConfig;

Add "use client" at the top of any file that imports chat.

Project config file

Create src/configs/chat.config.ts:

typescript
1/** Optional: read _id from the JWT so it always matches the token */2function userIdFromToken(token: string): string | undefined {3  try {4    const payload = JSON.parse(5      atob(token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"))6    );7    return payload._id || payload.id;8  } catch {9    return undefined;10  }11}12 13const accessToken = "YOUR_JWT_ACCESS_TOKEN";14 15export const chatConfig = {16  clientId: "YOUR_CLIENT_ID",17  accessToken,18  loggedUserDetails: {19    _id: userIdFromToken(accessToken) ?? "YOUR_USER_ID",20    name: "Your Name",21    email: "you@example.com",22  },23  apiUrl: "https://api.example.com/api/v1",24  themeColor: "#6366f1",25} as const;

Environment variables

Optional - read them in chat.config.ts:

shell
1# .env.local (Next.js) or .env (Vite, with the VITE_ prefix)2NEXT_PUBLIC_CHAT_CLIENT_ID=your-client-id3NEXT_PUBLIC_API_V1_BASE_URL=https://api.example.com/api/v1
typescript
1export const chatConfig = {2  clientId: process.env.NEXT_PUBLIC_CHAT_CLIENT_ID ?? "",3  accessToken: "YOUR_JWT_ACCESS_TOKEN",4  apiUrl: process.env.NEXT_PUBLIC_API_V1_BASE_URL ?? "",5  // ...6};

Vite uses import.meta.env.VITE_* instead of NEXT_PUBLIC_*.

Dev proxy (CORS)

If the API blocks browser requests during local development, proxy them through your dev server (Vite):

typescript
1server: {2  proxy: {3    "/chat-api": {4      target: "https://YOUR_API_HOST",5      changeOrigin: true,6      rewrite: (path) => path.replace(/^\/chat-api/, "/api/v1"),7    },8  },9},

Then set apiUrl: "/chat-api" in chat.config.ts for local development.

This proxy only carries REST calls. Normally the socket host comes from apiUrl, but /chat-api has no host, so also pass the real one: socketUrl: "https://YOUR_API_HOST". This is the only setup that needs socketUrl.

PreviousInstallationNextQuick start

On this page

CSS setupVite - vite.config.tsNext.js - next.config.tsProject config fileEnvironment variablesDev proxy (CORS)
Back to top