Skip to content

SDKs

React SDK

@channlize/react: the floating chat widget, an inline chat, a contact form and hooks for React and Next.js, with theming props.

On this page

@channlize/react (0.10.2) gives you a floating live-chat widget, an inline chat, a contact form, and hooks to build your own UI. Conversations land in your Slack channels, and replies from Slack appear in the widget in real time. React 18 or later.

Shell
npm install @channlize/react

All components call the API from the visitor's browser.

Note

The widget and contact form work on any website until you verify a domain. The widget key (wk_…) is public by design, so these routes are rate limited per IP address. Once you verify a domain, the key only works on your verified domains and localhost.

They use your widget key (wk_…, public) and project ID. Find both under API keys in the dashboard.

Next.js App Router

  • The components use state and browser APIs. Render them from a file marked 'use client' and import that file from your server layouts or pages.
  • Only NEXT_PUBLIC_ variables reach the browser. Put the widget key and project ID there, never the server key. Server-side work like notify() belongs in route handlers or server actions.
  • The widget renders after hydration only, so it never causes a hydration mismatch.
.env.local
NEXT_PUBLIC_CHANNLIZE_WIDGET_KEY=wk_your_widget_key
NEXT_PUBLIC_CHANNLIZE_PROJECT_ID=your-project-id
app/chat-widget.tsx
'use client';

import { ChannlizeChat } from '@channlize/react';

export function ChatWidget() {
  return (
    <ChannlizeChat
      config={{
        apiKey: process.env.NEXT_PUBLIC_CHANNLIZE_WIDGET_KEY!,
        projectId: process.env.NEXT_PUBLIC_CHANNLIZE_PROJECT_ID!,
      }}
      primaryColor="#2563eb"
      chatProps={{ title: 'Acme Support' }}
    />
  );
}
app/layout.tsx
import type { ReactNode } from 'react';
import { ChatWidget } from './chat-widget';

// Stays a server component: only ChatWidget runs on the client.
export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <ChatWidget />
      </body>
    </html>
  );
}

React and Vite

src/App.tsx
import { ChannlizeChat } from '@channlize/react';

export function App() {
  return (
    <>
      {/* …your app… */}
      <ChannlizeChat
        config={{ apiKey: 'wk_your_widget_key', projectId: 'your-project-id' }}
        primaryColor="#2563eb"
        chatProps={{ title: 'Acme Support' }}
      />
    </>
  );
}

ChannlizeChat

The all-in-one floating widget: provider, launcher button and chat window. Render it once near the root. It renders through a portal into document.body, with its styles scoped under .channlize-widget.

PropTypeDefaultDescription
configChannlizeConfigrequired{ apiKey, projectId, baseUrl?, timeout? }: widget key and project ID.
position'bottom-right' | 'bottom-left' | 'top-right' | 'top-left''bottom-right'Corner of the launcher.
offset{ x?: number; y?: number }{ x: 24, y: 24 }Distance from the edges, in px.
primaryColorstringAccent for the launcher and chat window (hex).
theme'auto' | 'light' | 'dark''auto'auto follows prefers-color-scheme.
defaultOpenbooleanfalseStart with the chat open.
showOnMobilebooleantrueShow the launcher under 640px. On phones the chat opens full screen.
chatPropsSupportChatProps{}Passed to the chat window: title, greeting, suggestions… See SupportChat.
buttonSizenumber56Launcher size, in px.
buttonColors{ background?, hover?, text? }primaryColorLauncher colours.
buttonElement / buttonIconReactNodeReplace the whole launcher, or just its icon.
showBadge / unreadCountboolean / numberfalse / 0Show your own unread count. Without it, the launcher counts agent replies received while closed.
zIndexnumber2147483000Stacking order of the widget.
enableAnimationsbooleantrueAlways reduced with prefers-reduced-motion.
onOpen / onClose() => voidOpen and close callbacks.
buttonClassName / chatClassNamestringExtra classes on the launcher and chat container.

SupportChat

The chat window on its own, sized by its container. Render it inside a ChannlizeProvider. The same props go in ChannlizeChat's chatProps (except autoConnect and onMinimize).

components/help-panel.tsx
'use client';

import { ChannlizeProvider, SupportChat } from '@channlize/react';

export function HelpPanel() {
  return (
    <ChannlizeProvider config={{ apiKey: 'wk_your_widget_key', projectId: 'your-project-id' }}>
      <div style={{ height: 560 }}>
        <SupportChat
          title="Acme Support"
          suggestions={['Billing question', 'Report a bug']}
          allowAttachments
          theme="light"
        />
      </div>
    </ChannlizeProvider>
  );
}
PropTypeDefaultDescription
titlestring'Support'Header title: your team or brand.
greetingstring'Hi there!'Welcome heading before the first message.
welcomeMessagestring'Ask us anything. We’re here to help.'Welcome text under the greeting.
suggestionsstring[]Quick replies on the welcome screen; a click sends one.
placeholderstring'Write a message…'Composer placeholder.
statusTextstring'Replies in a few minutes'Shown after "Online" in the header. '' hides it.
avatarUrl / avatarstring / ReactNodeLogo in the header and on the welcome screen.
allowAttachmentsbooleanfalseLet visitors attach files.
reactionsEnabledbooleanthe workspace settingOffer emoji reactions on messages. The API reports whether the workspace allows them; false turns the picker off. A reaction your team adds in the dashboard or in Slack shows on the message either way.
allowEndChatbooleantrue"End conversation" in the header menu.
showTimestampsbooleantrueTimes on messages.
maxLengthnumber5000Maximum message length.
theme'auto' | 'light' | 'dark''auto'Colour scheme.
primaryColor / primaryTextColorstringAccent colour, and the text colour on it (picked for contrast when omitted).
localestringbrowser localeLocale for dates and times.
labelsPartial<SupportChatLabels>Override any UI string. Defaults: defaultSupportChatLabels.
styles / classNameper-part CSSProperties / stringInline style overrides; they win over the theme.
sendButtonTextstring'Send message'Accessible label of the send button.
onMinimize() => voidShows a minimize button; Esc calls it.
autoConnectbooleantrueStart the session on mount.
metadataRecord<string, unknown>Attached to the conversation (plan, user ID…).
persistSession / storageKeyboolean / stringtrue / channlize_session_<widget key>Resume the session after a reload (localStorage).
sessionIdstringResume a known session.
onMessage / onError(message) => void / (error) => voidNew message and failure callbacks.

Reactions

When the workspace allows reactions, every message gets a picker with the emoji the workspace offers: picking one adds the customer's reaction, picking it again takes it back. A reaction your team adds in the dashboard or in Slack shows on the message in the widget too.

With useChatSession, each message carries the reactions of that message (ChatMessage.reactions: the emoji, how many people reacted, whether the customer is one of them, and who they are), and toggleReaction(messageId, emoji, add) adds or removes the customer's own reaction.

Satisfaction rating

When the workspace has CSAT turned on for the widget, the chat asks the customer to rate the conversation from 1 to 5, with an optional comment, once it's closed: by the visitor, or by your team resolving it while the chat is open. The customer can change the rating for 7 days. Nothing to configure in the component.

Coming soon

The rating prompt ships in the next minor release of @channlize/react, with getRating and rateConversation on @channlize/core's client for your own UI.

ContactForm

A themed, accessible contact form that files a conversation in Slack: inline validation, loading, success and error states, an optional topic select and company field, and a honeypot spam guard. Render it inside a ChannlizeProvider.

app/contact/contact-form.tsx
'use client';

import { ChannlizeProvider, ContactForm } from '@channlize/react';

export function ContactSection() {
  return (
    <ChannlizeProvider
      config={{
        apiKey: process.env.NEXT_PUBLIC_CHANNLIZE_WIDGET_KEY!,
        projectId: process.env.NEXT_PUBLIC_CHANNLIZE_PROJECT_ID!,
      }}
    >
      <ContactForm
        theme="auto"
        primaryColor="#2563eb"
        fields={{ company: 'optional' }}
        topics={['Sales', 'Support', { value: 'billing', label: 'Billing' }]}
        onSuccess={(res) => console.log('Filed as', res.conversationId)}
        onError={(err) => console.error(err.message)}
      />
    </ChannlizeProvider>
  );
}

The API accepts a message of 10 to 10,000 characters and an optional subject up to 200. When the subject is blank, Channlize uses the topic, then the first line of the message. The topic, company and customFields values are sent as customFields and shown on the Slack post (at most 20 fields).

PropTypeDefaultDescription
onSuccess(response: CreateContactResponse) => voidCalled with { success, conversationId, message }.
onError(error: Error) => voidCalled when sending fails.
theme'auto' | 'system' | 'light' | 'dark''light'auto and system follow prefers-color-scheme.
primaryColor / primaryTextColorstringAccent colour (button, focus ring) and the text colour on it.
variant'card' | 'plain''card'card draws a themed surface; plain inherits your page.
unstyledbooleanfalseSkip the built-in stylesheet; class names stay for your own CSS.
fields{ name?, company?, subject?, topic? }name required, subject optional, company hiddenEach 'required' | 'optional' | 'hidden'. Email and message are always required.
topicsArray<string | { value, label? }>Options of the topic select, shown only when set.
defaultValuesPartial<ContactFormValues>Initial values, e.g. a topic from ?topic=sales (matched case-insensitively).
customFieldsArray<{ name, label, type, required?, options?, placeholder? }>[]Extra inputs; type is 'text' | 'email' | 'textarea' | 'select'.
labelsPartial<ContactFormLabels>Override any string. Defaults: defaultContactFormLabels.
submitText / successMessagestring'Send message' / 'Thanks for reaching out. We’ll get back to you by email.'Shortcuts for labels.submit and labels.successMessage.
minMessageLength / maxMessageLengthnumber10 / 5000Client-side length checks.
honeypotbooleantrueHidden field; bots that fill it get a fake success.
showSuccessStatebooleantrueShow the built-in success state after sending.
idPrefixstring'channlize'Prefix of field ids (channlize-email).
styles / className{ form, field, label, input, textarea, button, error, success } / stringInline styles per part (they win over the theme), extra class on the form.

A submission opens a Slack thread like a chat message does, labelled 📝 Contact form (chats are 💬 Live chat); the dashboard shows the same source on each conversation. The sender gets an automatic "we got your message" email.

Replies by email

The sender has left your site, so your replies to a contact-form conversation, in the Slack thread or from the dashboard, are emailed to them:

  • From " Support via Channlize", with the subject Re: <their subject or topic>. The email quotes their original message and threads under the automatic reply.
  • Reply-To is your organization's Billing and contact email (dashboard Settings), so their answer reaches that inbox. Channlize has no inbound address per organization yet: answers don't come back into the conversation, so keep that inbox monitored.
  • Quick replies are batched: replies sent within 30 seconds of each other go out as one email.
  • Delivery shows in the dashboard: each reply is marked Emailed ✓ or Email failed, and the reply box says where the reply goes. A failure also posts a note in the Slack thread, and the first email of a conversation posts one saying where replies go.
  • Never emailed: live-chat conversations (replies show in the widget), internal notes, test conversations, and senders without a real address (placeholders, .invalid and GitHub noreply addresses).

Hooks

All hooks need a ChannlizeProvider above them.

HookReturnsUse it for
useChatSession(options){ session, messages, isConnecting, isConnected, error, sendMessage, startSession, endSession, reconnect }Live chat state for your own UI. Options as in SupportChat; autoConnect defaults to false here.
useContactForm({ onSuccess, onError }){ submit, isSubmitting, isSuccess, error, reset }A headless contact form.
useChannlizeAnalytics(){ track(name, options) }Log tracking from the browser, with the widget key.
useChannlize(){ client, config }The @channlize/core client behind the provider.
mini-chat.tsx
'use client';

import { useState } from 'react';
import { useChatSession } from '@channlize/react';

// Your own chat UI; render inside <ChannlizeProvider>.
export function MiniChat() {
  const { messages, sendMessage, isConnected, error } = useChatSession({
    autoConnect: true, // start a session on mount (the hook defaults to false)
    metadata: { plan: 'Pro' },
  });
  const [text, setText] = useState('');

  return (
    <form
      onSubmit={async (e) => {
        e.preventDefault();
        await sendMessage(text);
        setText('');
      }}
    >
      <p>{isConnected ? 'Online' : 'Connecting…'}</p>
      <ul>
        {messages.map((m) => (
          <li key={m.id}>
            <b>{m.author === 'agent' ? (m.authorData?.name ?? 'Support') : 'You'}:</b> {m.content}
          </li>
        ))}
      </ul>
      {error && <p role="alert">{error.message}</p>}
      <input value={text} onChange={(e) => setText(e.target.value)} />
      <button type="submit" disabled={!isConnected || !text}>Send</button>
    </form>
  );
}
pricing-question.tsx
'use client';

import { useChannlizeAnalytics, useContactForm } from '@channlize/react';

// Render inside <ChannlizeProvider>.
export function PricingQuestion() {
  // Log tracking from the browser (shown under Log tracking)
  const { track } = useChannlizeAnalytics();

  // Headless contact form: your own fields, Channlize's submission state
  const { submit, isSubmitting, isSuccess, error } = useContactForm({
    onSuccess: (res) => console.log('conversation', res.conversationId),
  });

  return (
    <button
      type="button"
      disabled={isSubmitting || isSuccess}
      onClick={async () => {
        await track('cta_clicked', { properties: { section: 'pricing' } });
        await submit({
          name: 'Ada',
          email: 'ada@example.com',
          subject: 'Pricing',
          message: 'Do you offer yearly discounts?',
        });
      }}
    >
      {isSuccess ? 'Sent' : error ? error.message : 'Ask about pricing'}
    </button>
  );
}

useChatSession reconnects its real-time stream on its own. Call reconnect() only after it reports a failed stream (error.code === 'SSE_ERROR').

Dashboard appearance

Each widget key can carry an appearance set in the dashboard (Integration → API keys → Appearance). ChannlizeChat and SupportChat read it once per page and use each value only when you didn't pass the matching prop, so an integration that sets its props in code looks the same as before.

Dashboard fieldProp it fills in
Primary colourprimaryColor (and the launcher's buttonColors.background)
Launcher positionposition on ChannlizeChat
Greetinggreeting
Welcome textwelcomeMessage
Logo URLavatarUrl
  • If the key is unknown or inactive, or the request fails, the built-in defaults apply.
  • When the launcher's colour or position comes from the dashboard, ChannlizeChat keeps the launcher hidden until the appearance arrives (at most appearanceWaitMs, 1.5 s by default), so it doesn't jump.
  • loadAppearance={false} skips the request.
  • Saved changes reach a returning visitor within about a minute.

"Powered by Channlize"

The chat shows a small "Powered by Channlize" line under the composer. On the Business plan, turn on Hide "Powered by Channlize" in the widget's Appearance to remove it. The server decides: the line is hidden only when the widget asks for it and the plan includes white-labeling, so a prop can't hide it. showBranding forces it on. With loadAppearance={false} there's no request, so it shows. This needs @channlize/react 0.9.0.

Theming

Every component supports light and dark, an accent colour, and inline style overrides. Text on the accent colour is picked for contrast unless you set it.

themed-widget.tsx
'use client';

import { ChannlizeChat } from '@channlize/react';

export function ThemedWidget() {
  return (
    <ChannlizeChat
      config={{ apiKey: 'wk_your_widget_key', projectId: 'your-project-id' }}
      theme="auto" // 'auto' (follows the OS) | 'light' | 'dark'
      primaryColor="#0f766e"
      position="bottom-left"
      offset={{ x: 16, y: 16 }}
      chatProps={{
        primaryTextColor: '#ffffff',
        avatarUrl: '/logo.png',
        statusText: 'Replies within an hour',
        locale: 'fr-FR',
        labels: { online: 'En ligne', endChat: 'Terminer' },
      }}
    />
  );
}
  • Translate or reword any string with labels; start from defaultSupportChatLabels or defaultContactFormLabels.
  • ContactForm defaults to theme="light"; the chat defaults to auto.
  • Need full control? ContactForm unstyled keeps the class names and drops the stylesheet, or build on the hooks.

Exports

Components: ChannlizeProvider, ChannlizeChat, SupportChat, ContactForm. Hooks: useChannlize, useChatSession, useContactForm, useChannlizeAnalytics. Values: defaultSupportChatLabels, defaultContactFormLabels. Types: ChannlizeChatProps, SupportChatProps, SupportChatLabels, ChatTheme, ContactFormProps, ContactFormLabels, ContactFormTheme, ContactFieldMode, ContactFormTopic, ContactFormValues, ContactFormCustomField, UseChatSessionOptions, UseChatSessionReturn, plus the core types re-exported from @channlize/core.