Chat Widget Setup

The RapiDesq chat widget lets you add real-time live chat to any website with a single script tag. This guide covers every aspect of widget configuration — from visual theming and pre-chat forms to identity authentication, business hours, and conversation flow assignment.

Overview

The chat widget is an embeddable JavaScript component that creates a persistent live-chat interface on your website. When a visitor clicks the chat icon, a conversation window opens and connects them directly to your support team through a real-time WebSocket connection. Messages are delivered instantly in both directions with no page reloads required.

Key capabilities of the widget include:

Creating a Widget

To create a new chat widget:

  1. Navigate to Admin > Chat Widgets in the left-hand sidebar.
  2. Click Create Widget.
  3. Fill in the widget configuration:
    • Name — a descriptive label for this widget (e.g., "Main Website Chat" or "Support Portal Widget"). This is only visible to your team.
    • Header Text — the text displayed at the top of the chat window. Defaults to "Chat with us".
    • Welcome Message — a greeting shown when the visitor first opens the widget (e.g., "Hi there! How can we help you today?").
    • Offline Message — text displayed when no agents are available or outside business hours (e.g., "We're currently offline. Leave a message and we'll get back to you.").
    • Team — select the team that should receive conversations from this widget.
    • Active — the isActive toggle controls whether the widget is live. Deactivating a widget hides it from your site without removing the embed code.
  4. Click Save. The widget is created and you can proceed to configure its appearance, behavior, and other settings.
Tip Create separate widgets for different pages or sections of your site (e.g., "Support Portal Chat" vs. "Sales Landing Page Chat"). Each widget has independent configuration and analytics, making it easy to tailor the experience and track performance by source.

Appearance & Theming

The widget provides granular control over its visual presentation. All settings take effect immediately for new visitors without any changes to your embed code.

Color and Branding

Setting Description Default
primaryColor Hex color used for the widget header, launcher button, and interactive elements. #1976d2
headerText Text displayed in the widget header bar. "Chat with us"
welcomeMessage Greeting message shown when the widget is first opened.
offlineMessage Message displayed when no agents are available or outside business hours.
defaultCloseMessage Message displayed to the visitor when a conversation is closed.

Widget Position

The position setting controls where the widget launcher appears on the page. Available options:

Tip Bottom-right is the most familiar position for live chat and is recommended unless it conflicts with other elements on your page. If you use a floating action button or other widget in the bottom-right, consider BOTTOM_LEFT to avoid overlap.

Dark Mode

If your website supports dark mode, the widget can adapt its colors to match. Enable dark mode with the darkModeEnabled toggle, then configure these three color properties:

Setting Description Default
darkPrimaryColor The primary accent color used for interactive elements, links, and buttons in dark mode. This replaces primaryColor when dark mode is active. #90caf9
darkHeaderBackgroundColor Background color for the widget header bar in dark mode. Use a dark, low-contrast color that is visually distinct from the message area. #1e1e1e
darkMessageBackgroundColor Background color for the message area (the conversation body) in dark mode. Should be slightly lighter than the header to create visual hierarchy. #333333
Note When darkModeEnabled is off, the widget always uses the standard primaryColor regardless of the visitor's system theme. When enabled, the widget detects the visitor's operating system or browser dark-mode preference and switches automatically.

Pre-Chat Forms

Pre-chat forms collect information from the visitor before the conversation begins. This gives your agents context and helps route conversations to the right team.

Enabling the Form

Set preChatFormEnabled to true in the widget settings. When enabled, visitors must complete the form before they can send their first message.

Standard Fields

The preChatStandardFields setting provides three built-in fields with automatic formatting and validation:

Each standard field can be independently toggled on or off and set as required or optional.

Custom Fields

The preChatFields array lets you define additional fields beyond the standard three. Each custom field supports the following properties:

Property Description
name Internal identifier for the field (used in APIs and reporting).
label The label displayed to the visitor above the input.
required Whether the visitor must fill in this field to proceed (true or false).
validationPattern A regular expression pattern for input validation (e.g., ^[A-Z]{3}-\\d{4}$ for a ticket reference format). The form will not submit if the input does not match.
placeholder Hint text displayed inside the empty input field.
helpText Descriptive text shown below the field to guide the visitor.
options An array of selectable values (only applicable to SELECT fields).
displayOrder Numeric value controlling the order in which fields appear on the form. Lower numbers appear first.

Field Types

Each custom field has a type that determines the input control rendered to the visitor:

Type Input Control Use Case
TEXT Single-line text input Short free-text answers such as a company name or order number.
EMAIL Email input with built-in format validation Collecting an additional email address (e.g., a billing contact).
PHONE Phone number input with format hints Collecting a callback number or alternate phone number.
TEXTAREA Multi-line text area Longer descriptions such as "Describe your issue" or "What are you looking for?"
SELECT Dropdown menu populated by the options array Categorized choices such as department selection ("Sales", "Support", "Billing") or issue type.
NUMBER Numeric input (integers and decimals) Collecting a quantity, account number, or other numeric value.
Tip Keep pre-chat forms short. Every additional field adds friction that may cause visitors to abandon the chat. Two to four fields is a good balance between gathering useful context and keeping the experience lightweight. Use displayOrder to put the most important fields first.

Behavioral Settings

These settings control how the widget behaves during and around conversations.

Auto-Open

The autoOpenDelaySeconds setting causes the widget to automatically open after the visitor has been on the page for the specified number of seconds. This can increase engagement by proactively offering help.

Note The auto-open fires once per visitor session. It does not repeatedly open the widget if the visitor closes it. Use a moderate delay (5–15 seconds) to avoid interrupting visitors who are still orienting themselves on the page.

Typing Indicators

When showAgentTyping is enabled, visitors see an animated "Agent is typing..." indicator while an agent composes a response. This reduces perceived wait time and reassures the visitor that their message is being addressed.

Agent Avatars

Enable showAgentAvatar to display the agent's profile picture next to their messages in the conversation. This adds a personal touch and helps visitors feel they are talking to a real person.

File Uploads

The enableFileUploads toggle controls whether visitors can attach files (screenshots, documents, etc.) to their messages. When enabled, a file-attachment button appears in the message input area.

Emoji Picker

When enableEmoji is enabled, an emoji picker button appears alongside the message input, allowing visitors to insert emoji into their messages.

Conversation Reopen Behavior

By default, once a conversation is closed, it is final. The reopen settings let you give visitors a window to continue a recently closed conversation instead of starting a new one:

Tip Enabling reopen with a reasonable timeout (30–60 minutes) is recommended. It prevents the frustrating experience of a visitor needing to repeat themselves if they have a quick follow-up question after a conversation is closed.

Embedding on Your Website

After configuring your widget, embed it on your site by adding the script tag to your HTML.

The Embed Snippet

In your widget settings, click Copy Embed Code to get the snippet. It looks like this:

<!-- RapiDesq Chat Widget -->
<script
  src="https://your-domain.rapidesq.com/widget.js"
  data-widget-id="YOUR_WIDGET_ID"
  async>
</script>

Place the snippet just before the closing </body> tag on every page where you want the widget to appear. The async attribute ensures the script loads without blocking page rendering — your page content loads first, and the widget initializes in the background.

Full Page Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>My Website</title>
</head>
<body>
  <!-- Your page content -->
  <h1>Welcome to our site</h1>

  <!-- RapiDesq Chat Widget — place just before </body> -->
  <script
    src="https://your-domain.rapidesq.com/widget.js"
    data-widget-id="abc123-def456-ghi789"
    async>
  </script>
</body>
</html>

Domain Restrictions

The allowedDomains setting controls which domains are permitted to load your widget. This is an important security measure that prevents unauthorized sites from embedding your widget and consuming agent time or impersonating your brand.

Example configuration:

allowedDomains: [
  "www.example.com",
  "support.example.com",
  "app.example.com"
]
Important Always configure allowedDomains for production widgets. Leaving it empty means anyone who obtains your widget ID can embed your chat widget on their site.

Identity Authentication

Identity authentication lets you verify the identity of logged-in visitors so your agents can trust that the person chatting is who they claim to be. This is essential for support scenarios involving account-specific information, billing, or sensitive data.

How It Works

  1. Enable identity authentication in your widget settings by setting identityAuthEnabled to true.
  2. Generate a shared secret. RapiDesq provides a randomly generated identityAuthSecret that is shared between your backend and RapiDesq. Copy this secret and store it securely in your backend environment (never expose it in client-side code).
  3. Choose a signing algorithm. The identityAuthAlgorithm setting defaults to HS256 (HMAC-SHA256). This is the algorithm your backend will use to sign the JWT.
  4. Your backend generates a JWT whenever a logged-in user loads a page with the widget. The token contains the visitor's identity claims and is signed with the shared secret.
  5. Pass the JWT to the widget. Your frontend provides the token to the widget (typically through a data attribute or JavaScript API call).
  6. RapiDesq verifies the token. When the visitor starts a conversation, the widget sends the JWT to RapiDesq. The server verifies the signature using the shared secret and extracts the identity claims. If verification fails, the conversation is rejected.

JWT Token Structure

Your backend should generate a JWT with the following structure:

// Header
{
  "alg": "HS256",
  "typ": "JWT"
}

// Payload
{
  "sub": "user-12345",          // Unique user ID in your system
  "email": "jane@example.com",  // User's email address
  "name": "Jane Smith",         // User's display name
  "iat": 1700000000,            // Issued-at timestamp (Unix epoch)
  "exp": 1700003600             // Expiration timestamp (Unix epoch)
}

Backend Example (Node.js)

const jwt = require('jsonwebtoken');

// The shared secret from your RapiDesq widget settings.
// Store this in an environment variable — never hard-code it.
const IDENTITY_SECRET = process.env.RAPIDESQ_IDENTITY_SECRET;

function generateWidgetToken(user) {
  return jwt.sign(
    {
      sub: user.id,
      email: user.email,
      name: user.displayName
    },
    IDENTITY_SECRET,
    {
      algorithm: 'HS256',
      expiresIn: '1h'
    }
  );
}

Passing the Token to the Widget

Include the generated token in the embed snippet as a data-identity-token attribute:

<script
  src="https://your-domain.rapidesq.com/widget.js"
  data-widget-id="YOUR_WIDGET_ID"
  data-identity-token="SERVER_GENERATED_JWT_HERE"
  async>
</script>
Important The identityAuthSecret must never be exposed in client-side JavaScript. Always generate the JWT on your server and pass only the signed token to the frontend. If your secret is compromised, rotate it immediately in the widget settings.
Note Identity authentication is optional. When disabled, visitors chat anonymously (or provide their details via pre-chat forms). When enabled, anonymous visitors are prevented from starting conversations — only visitors with a valid signed JWT can chat.

Business Hours

Business hours configuration lets the widget automatically reflect your team's availability. When the current time falls outside your defined schedule, the widget displays the offlineMessage and visitors know to expect a delayed response.

Configuring a Schedule

The businessHours setting defines operating hours per timezone with day-of-week schedules. In the widget settings:

  1. Select the timezone for this schedule (e.g., America/New_York or Europe/London).
  2. For each day of the week, define the start time and end time when your team is available, or mark the day as closed.
  3. Save the schedule. The widget immediately begins using it to determine online/offline state.

Off-Hours Behavior

When the current time is outside your configured business hours:

Tip If your team operates across multiple time zones, configure the business hours schedule based on the timezone where the majority of your visitors are located, or set a wide window that covers your combined coverage hours.

Assigning Conversation Flows

A conversation flow is an automated interaction sequence that runs at the start of every new conversation. Flows can greet visitors, collect structured information, answer common questions, or route the conversation to the appropriate team — all before an agent is involved.

Assigning a Flow

  1. Go to the widget's settings page.
  2. In the Conversation Flow dropdown, select the flow you want to assign.
  3. Save your changes. The flow takes effect immediately for all new conversations.

How Flow Assignment Works

Note See the Conversation Flows guide for full details on building, testing, and managing flows.

Testing Your Widget

Thorough testing ensures your visitors have a smooth experience. Work through each of the following scenarios after embedding the widget.

Basic Functionality

  1. Open your website in a browser and confirm the widget launcher icon appears in the configured position.
  2. Click the launcher. Verify the headerText and welcomeMessage display correctly.
  3. If the pre-chat form is enabled, fill it in and confirm validation works (try submitting with missing required fields and with invalid patterns).
  4. Send a test message and confirm it appears in your RapiDesq inbox.
  5. Reply from the RapiDesq inbox and verify the response appears in real time in the widget.

Online and Offline States

  1. Online state: with at least one agent available, verify the widget shows the normal chat experience.
  2. Offline state: set all agents to unavailable (or test outside business hours). Confirm the offlineMessage displays. If a conversation flow is assigned, verify it runs correctly during off-hours.

Feature-Specific Checks

Cross-Browser and Device Testing

Verify the widget renders and functions correctly on:

Important Always test both online and offline agent states. If you have configured identity authentication, test with valid tokens, expired tokens, and no token to ensure each scenario is handled gracefully.

Configuration Reference

A complete reference of all widget settings in one place.

Setting Category Default Description
isActiveGeneraltrueEnable or disable the widget.
primaryColorVisual#1976d2Primary color for header, buttons, and accents.
positionVisualBOTTOM_RIGHTScreen corner for the widget launcher.
headerTextVisual"Chat with us"Header bar text.
welcomeMessageVisualGreeting when the widget opens.
offlineMessageVisualMessage when agents are unavailable.
defaultCloseMessageVisualMessage when a conversation closes.
darkModeEnabledVisualfalseToggle dark mode support.
darkPrimaryColorVisual#90caf9Accent color in dark mode.
darkHeaderBackgroundColorVisual#1e1e1eHeader background in dark mode.
darkMessageBackgroundColorVisual#333333Message area background in dark mode.
autoOpenDelaySecondsBehavior0Seconds before auto-opening (0 = disabled).
showAgentTypingBehaviortrueShow "Agent is typing..." indicator.
showAgentAvatarBehaviortrueDisplay agent profile pictures.
enableFileUploadsBehaviortrueAllow visitors to attach files.
enableEmojiBehaviortrueShow emoji picker in message input.
allowReopenBehaviorfalseAllow visitors to reopen closed conversations.
reopenTimeoutMinutesBehavior60Window (minutes) for reopening conversations.
preChatFormEnabledPre-ChatfalseRequire a form before chat begins.
preChatStandardFieldsPre-ChatConfiguration for name, email, and phone fields.
preChatFieldsPre-Chat[]Custom field definitions (array).
allowedDomainsSecurity[]Domains where the widget can be loaded (empty = all).
identityAuthEnabledSecurityfalseEnable JWT-based identity verification.
identityAuthSecretSecurityShared secret for JWT signing.
identityAuthAlgorithmSecurityHS256JWT signing algorithm.
businessHoursScheduleOperating hours per timezone with day-of-week schedules.