---
title: "CommSite Integration Guide"
slug: "commsite-integration-guide"
updated: 2026-11-30T10:30:41Z
published: 2026-11-30T10:30:41Z
canonical: "help.commbox.io/commsite-integration-guide"
---
> ## Documentation Index
> Fetch the complete documentation index at: https://help.commbox.io/llms.txt
> Use this file to discover all available pages before exploring further.
# CommSite Integration Guide
## Overview
CommSite drops onto your site as two script tags. No build step, no framework, no package to install — paste the snippet, and your visitors get the chat launcher on every page. One more tag adds AI Summary: answers and summaries from your CommSite AI agent, shown inside your own search results and pages. This guide covers the basic install, every optional setting and when it's worth using, and AI Summary with examples you can copy.
- **Time to install:** About 5 minutes
- **You'll need:** Your CommSite Stream ID
- **Requires:** HTTPS
- **Works with:** Any site or framework
- **New:** [AI Summary on your own pages](/docs/commsite-integration-guide#ai-start)
*On this page*
1. [Basic install](/docs/commsite-integration-guide#install)
2. [The two required values](/docs/commsite-integration-guide#essentials)
3. [All optional settings](/docs/commsite-integration-guide#options)
4. [Common setups](/docs/commsite-integration-guide#recipes)
5. [Signed-in visitors](/docs/commsite-integration-guide#signedin)
6. [Open the chat from your page](/docs/commsite-integration-guide#open-chat)
7. [What the AI agent knows about the page](/docs/commsite-integration-guide#page-context)
8. [AI Summary: get started](/docs/commsite-integration-guide#ai-start)
9. [AI Summary examples](/docs/commsite-integration-guide#ai-examples)
10. [AI Summary reference](/docs/commsite-integration-guide#ai-reference)
11. [Troubleshooting](/docs/commsite-integration-guide#troubleshooting)
12. [For your IT team](/docs/commsite-integration-guide#security)
13. [Good to know](/docs/commsite-integration-guide#goodtoknow)
*Step by step*
## Basic install
This is the whole thing. Add it once to every page where you want the chat available — usually your shared layout, footer template, or tag manager.
### 1. Load the connector script
It's a single small file served by Commbox. Load it from Commbox rather than copying it to your own server, so you automatically get fixes and improvements.
*Your page — before `</body>`*
```
```
### 2. Start CommSite
Everything starts with `window.CMSITE.init()`. Call it once, after the page has a `<body>` to attach to.
Replace the whole placeholder — square brackets included — with your Stream ID ([where to find it](/docs/commsite-integration-guide#p-streamId)), keeping the quotes around it. The result looks like `streamId: 'aBc123XyZ%3d'`. Everything else can stay exactly as it is: the `url` is the same for every customer.
*Your page — right after the tag above*
```
```
The `if` check isn't ceremony — if the connector was blocked by an ad blocker, a firewall, or a Content-Security-Policy rule, this is the line that tells you so in the console instead of failing silently.
### 3. Reload and look for the launcher
You should see the CommSite launcher appear at the bottom of the page. If it doesn't, it's almost always a blocked connector script or a mistyped `url` — both are in [Troubleshooting](/docs/commsite-integration-guide#troubleshooting).
> **If you add the snippet dynamically**
>
>
> `DOMContentLoaded` only fires once. If you inject the snippet later — from a tag manager, a cookie-consent callback, or a single-page app — that event may already have passed, and `init` would never run. This version handles both cases:
>
>
> *Safe in both cases*
>
>
> ```
> function startCommSite() {
> if (!window.CMSITE || typeof window.CMSITE.init !== "function") {
> console.error("CommSite could not be loaded.");
> return;
> }
> window.CMSITE.init({ streamId: '[Your CommSite Stream ID]', url: 'https://apps.commbox.io/commsite/' });
> }
>
> if (document.readyState === "loading") {
> window.addEventListener("DOMContentLoaded", startCommSite);
> } else {
> startCommSite(); // page is already parsed
> }
> ```
> **Don't add async to the connector tag**
>
>
> A plain script tag and a `defer` tag both finish before `DOMContentLoaded`, so either is fine. An `async` tag can execute *after* that event — when it does, your `init` call has already run and given up, and the widget silently never appears.
*Get these right first*
## The two required values
Everything else on this page is optional. These two are not, and almost every failed install traces back to one of them. Only the first is specific to you — the second is the same for every customer, so there's just one value to go and find.
### `streamId`
*required · string*
**What it is**
The **Stream ID of your CommSite channel** in Commbox. It tells CommSite which bot, design and settings to load, which makes it the one value in the snippet that's unique to you.
**Where to find it**
Open the CommSite channel in your Commbox account and copy its Stream ID. If you run several channels — WhatsApp, email, chat — take the ID from the **CommSite** channel specifically: every channel has its own, and another channel's ID won't load the widget.
**Copy it exactly**
The value often ends in `%3d` or `%3D`, and can contain `_` and `-`. That's normal. Paste it character for character — don't URL-decode it, don't re-encode it, and don't trim the tail. An altered ID won't load.
**Is it secret?**
No. It sits in your page's HTML where any visitor can read it, and that's by design — it identifies a CommSite, it doesn't grant access to anything. There's no API key or secret in this snippet.
### `url`
*always set it · same for every customer*
**What it is**
The address of the CommSite app. There's nothing to look up here — it's the same value for every customer and every site:
*Always exactly this*
```
https://apps.commbox.io/commsite/
```
Paste it as-is. A trailing slash is fine either way; nothing else should change.
**Why you shouldn't adjust it**
Your page and the chat widget are separate documents that talk to each other, and each only accepts messages from an address it has been told to trust. `url` is how your page learns that address, so it has to match where the widget really loads from *exactly*. Switching `https` for `http`, adding a `www.`, or routing it through a proxy on your own domain all break that match.
The symptom is distinctive: the widget appears but is **inert**. It never resizes, never opens, and prints no error. If you see that, this is almost always why.
**Two rules**
- **Never leave it out.** Without it, the connector assumes CommSite is
hosted on *your* domain and looks for it there — which fails on any normal
installation.
- **Keep it absolute.** A relative value like `"/commsite"`
breaks the trust check entirely and stops the widget responding to anything.
*Reference*
## All optional settings
You can ignore this whole section and still have a working install. Reach for these when you want the widget somewhere other than floating in the corner, or when your site is a single-page app, right-to-left, or has signed-in users.
| Setting | Default | Reach for it when… |
| --- | --- | --- |
| `type` | Floating launcher | You want the chat open on arrival, or embedded in the page instead of floating. |
| `msg` | — | You want the conversation to start with a specific question already asked. |
| `dir` | `"ltr"` | Your site is right-to-left (Hebrew, Arabic…). |
| `navType` | Full page reload | Your site is a single-page app and you don't want full reloads. |
| `targetElement` | Floats over the page | You want the chat inside a specific section of your layout. |
| `showFrameButtons` | `true` | You're embedding inline and the minimize / back controls don't belong. |
| `ta` | Anonymous visitor | The visitor is signed in to your site and CommSite should know who they are. |
### `type`
*optional · default: floating launcher*
**What it does**
Chooses how CommSite presents itself when the page loads. Leave it out and you get the floating launcher, which is the right answer for most sites.
**The options**
| Value | What the visitor sees | Covers the page? |
| --- | --- | --- |
| *omitted* | **The floating launcher.** A compact bar at the bottom of the page that the visitor can type into directly. It measures itself and stays only as big as it looks, so the rest of your page is untouched. | No |
| `"openInCompactView"` | Opens as a **small chat window** without the visitor clicking anything. Good for a "we're here to help" moment on a specific page. | No |
| `"openWithoutLauncher"` | Opens the **full chat immediately**, with no launcher step. | Yes — instantly |
| `"sendMessage"` | Opens the full chat and **starts a new conversation** with the text in `msg` already sent. | Yes — instantly |
| `"full"` | The **complete CommSite app**, filling whatever space you give it. This is the one to use with `targetElement`. | Yes, unless you use `targetElement` |
**Choosing**
- **Site-wide?** Leave `type` out. The three full-screen modes
cover your page the moment they load, so they belong on a dedicated page —
`/support`, `/contact` — not on your homepage.
- **A page section?** Use `"full"` with
`targetElement`.
- **A nudge on one page?** Use `"openInCompactView"`.
**Watch out**
- A typo in the value doesn't raise an error, and it isn't harmless: you get the floating
launcher, but the frame is laid out full-screen first and covers the page —
swallowing clicks — until the launcher reports its real size and visibly shrinks.
An unexplained full-page overlay that shrinks a moment after load means a misspelled
`type`.
- After your bot sends the visitor to another page on your site with a full page load,
CommSite reopens there as a compact chat window whatever your `type` says, so
the conversation survives the navigation. The page load after that uses your configured
`type` again.
- `"sendMessage"` starts a *brand-new* conversation every time
`init` runs. Put it behind a button or on one specific page, not on every
page of your site, or visitors will accumulate abandoned conversations.
### `msg`
*optional · pairs with type: "sendMessage"*
**What it does**
The message to send on the visitor's behalf as the conversation opens. It's only read when `type` is `"sendMessage"` — on its own it does nothing.
Special characters are escaped for you, so you can pass plain text. Keep it short: it travels in the URL, so it's meant for a starting question, not a paragraph.
*"Ask about this product" button*
```
window.CMSITE.init({
streamId: '[Your CommSite Stream ID]',
url: 'https://apps.commbox.io/commsite/',
type: 'sendMessage',
msg: 'I have a question about the Aurora 14 laptop',
});
```
On a page that already shows the launcher, a button is usually better served by `CMSITE.open({ message })`: it works at any moment and continues the open conversation instead of starting a new one. See [Open the chat from your page](/docs/commsite-integration-guide#open-chat).
### `dir`
*optional · default: "ltr"*
**What it does**
Tells CommSite which way *your page* reads, so the launcher settles against the correct edge on the very first paint instead of appearing and then jumping across.
**Note**
- This describes your **page layout**, not the chat language. The chat
picks its own direction from the language it's speaking.
- Only the exact lowercase string `"rtl"` counts.
`"RTL"` is treated as left-to-right.
*Right-to-left site*
```
window.CMSITE.init({
streamId: '[Your CommSite Stream ID]',
url: 'https://apps.commbox.io/commsite/',
dir: 'rtl',
});
```
### `navType`
*optional · default: full page reload*
**What it does**
Your bot can send visitors to pages on your own site — "here's our pricing page". `navType` tells the connector *how* to perform that navigation, so it matches how your site handles routing.
**The options**
| Value | Use it for | How it navigates |
| --- | --- | --- |
| *omitted* | Classic multi-page websites — WordPress, Shopify, server-rendered sites. | A normal full page load. |
| `"spa"` | React, Vue, Angular and similar apps with a client-side router. | Updates the URL in place and asks your router to re-render — no reload. |
| `"hash"` | Apps that route on the URL fragment (`#/products`). | Changes the fragment only. |
**Worth knowing**
- **It needs a Commbox setting as well.** `navType` only applies to
links pointing at your own site, and only when "open links to your site in the same
page" is enabled for your CommSite in Commbox. If `navType` appears to do
nothing, check there before changing the value.
- **Test `"spa"` against your router.** It signals the
navigation the standard way, but a few routers only respond to navigations they
started themselves. If the address bar changes and the page doesn't, drop the setting
and take the full reload.
- **With `"hash"`, only the fragment changes** — the path
stays as it is. That's the point of hash routing, but it means the result depends on
which page the visitor started from.
- **A typo isn't harmless here.** An unrecognized value still triggers the
shrink animation and then does a full reload. Either use one of the two exact values
or leave it out.
- **Still call `init` only once**, even in a single-page app. See
[Good to know](/docs/commsite-integration-guide#goodtoknow).
### `targetElement`
*optional · an element id, as a string*
**What it does**
Puts CommSite *inside* an element on your page instead of floating it over everything. Perfect for a dedicated help page, a support tab, or a chat panel in a dashboard.
**Three requirements**
- **Pass the `id`, not the element.** It's a string like
`"chat-container"` — not a DOM node, not a CSS selector, no
`#`.
- **Pair it with `type: "full"`.** That combination is the one
laid out for in-page embedding. Other combinations are positioned for floating and
will sit visibly off-center inside your container.
- **Give the container a real height.** CommSite fills 100% of it, and 100%
of nothing is nothing. Set an explicit height or min-height.
**The container must already exist**
`init` looks the element up immediately. If it isn't in the page yet you'll see a `TypeError` in the console and no widget at all. Put the snippet after the container in your markup, or call `init` once the container is rendered.
*Inline embed*
```
```
### `showFrameButtons`
*optional · default: true*
**What it does**
Set it to `false` to hide the controls CommSite draws for managing its own window: minimize, expand, "Back to website", the conversation-history menu and the home button.
**When to use it**
Mainly with `targetElement`. In an inline embed those controls don't just look out of place — "minimize" would collapse your carefully sized container down to a small bar with no way back. Turning them off keeps your layout stable.
**Two behaviors to expect**
- **It doesn't apply to the floating launcher.** The setting is passed along
with the four explicit `type` modes only. On a default launcher embed it has
no effect.
- **It's remembered for the rest of the browser tab.** Once a page has
loaded CommSite with `false`, the same CommSite keeps its controls hidden
for that tab — including on other pages. If you mix an inline embed and a
floating launcher on the same site, expect the launcher to inherit the hidden controls
after a visitor has seen the inline one. Open a fresh tab to check the clean state.
### `ta`
*optional · needs server-side work*
**What it does**
Tells CommSite who the visitor is, so the conversation starts with their name, history and details already in place instead of asking. Covered properly in [Signed-in visitors](/docs/commsite-integration-guide#signedin) below — it's the one setting that needs code on your server.
*Copy and paste*
## Common setups
Four setups. Each block shows only the `init` options — drop them into the snippet from [Basic install](/docs/commsite-integration-guide#install).
### Floating launcher on every page
The standard install. Add it to your shared layout and you're done.
*Recommended default*
```
window.CMSITE.init({
streamId: '[Your CommSite Stream ID]',
url: 'https://apps.commbox.io/commsite/',
});
```
### Single-page app (React, Vue, Angular)
The important part is *once*. Mount it at the app root, not inside a routed component — re-running `init` on every route change would rebuild the widget and throw away the visitor's open conversation.
*React — app root*
```
useEffect(() => {
if (window.__commsiteStarted) return; // guard: run once only
window.__commsiteStarted = true;
const s = document.createElement("script");
s.src = "https://apps.commbox.io/commsite/commsite-connect.js";
s.onload = () => {
window.CMSITE?.init({
streamId: '[Your CommSite Stream ID]',
url: 'https://apps.commbox.io/commsite/',
navType: 'spa', // bot links won't reload the app
});
};
document.body.appendChild(s);
}, []);
```
> **Development mode**
>
>
> React's Strict Mode runs effects twice on purpose. The `__commsiteStarted` guard above is what keeps that from starting CommSite twice — keep it.
### Inside a page — a dedicated support page
Chat as part of your layout rather than floating over it.
*Inline embed*
```
```
### Right-to-left site with a signed-in visitor
Everything combined. The `ta` value is rendered by your server — see the next section.
*Server-rendered page*
```
window.CMSITE.init({
streamId: '[Your CommSite Stream ID]',
url: 'https://apps.commbox.io/commsite/',
dir: 'rtl',
ta: '<%= commsiteTicket %>', // fresh per page load
});
```
*Optional — needs server-side code*
## Signed-in visitors
If visitors log in to your site, you can hand that identity to CommSite so the conversation opens already knowing them — no "what's your email?" and your agents see real order history instead of an anonymous session. That's what `ta` is for.
**Visitor signs in** On your site, as normal.
**Your server asks for a ticket** It calls the Commbox API with your API key and the visitor's details.
**You render it into the page** The API returns an encrypted string. Pass it as `ta`.
**CommSite verifies it** Server to server, then greets the visitor by name.
### Requesting a ticket
Your backend requests the ticket from the Commbox API (`POST /v1/auth/ticket`). Ask your Commbox contact for the ticket API reference — you'll need the endpoint host, how to send your API key, and the exact field names.
Every request has to carry at least one of `email`, `uniqueId` or `username`; one built only from names or a phone number comes back as an error with no ticket at all. **Use the email address where you can** — email, or failing that a phone number, is what matches the visitor to their existing contact record and conversation history. A ticket carrying only a `uniqueId` is issued, but for a visitor Commbox hasn't seen in that browser before it creates a fresh anonymous contact on each page load.
You can also pass first and last name, phone, your own unique ID for the visitor, and a small JSON payload of extra attributes for the bot to use. The API returns an encrypted string; that string is your `ta` value.
> **Must-know rules**
>
>
> - **Generate it on your server, never in browser JavaScript.** The request
>
> needs your API key, and an API key in a web page is public.
> - **One ticket, one page load.** Generate a fresh ticket each time you render
>
> the page — never cache one, and never hardcode one. Tickets expire after about five
>
> minutes by default, and until one expires anyone holding it can reuse it. If you need each
>
> ticket to work exactly once, ask your Commbox contact to enable one-time tickets.
> - **No `|` characters in any field.** The pipe is the ticket's own
>
> field separator, so a pipe inside a value silently truncates that field — and the
>
> ticket is still accepted, so you get wrong contact data with no error anywhere. Strip or
>
> replace pipes before requesting.
> - **A bad ticket fails quietly.** Expired, already used or malformed —
>
> the chat still loads, just with the visitor anonymous, and nothing is reported to your
>
> page. If the greeting doesn't use their name, suspect the ticket first, usually a cached
>
> or reused one.
> **Two quiet behaviors**
>
>
> - **Invalid field values are dropped, not reported.** A malformed email, a
>
> phone number with fewer than seven digits, or an over-long name is silently discarded
>
> while the rest of the ticket still works. If a detail isn't showing up in Commbox, check
>
> its format before anything else.
> - **Phone numbers get normalized.** Formatting characters are removed, and a
>
> leading zero or `+` country prefix is not preserved. Store the canonical form
>
> you want in a field of your own if the exact string matters.
### When the visitor signs out
Simply leaving `ta` out on the next page load does *not* sign them out of CommSite — the session persists until the browser is closed. To end it, request the CommSite logout address as part of your own sign-out flow:
*Clears the CommSite session*
```
https://apps.commbox.io/commsite/[Your CommSite Stream ID]/logout
```
Load that address in a hidden iframe as part of your sign-out. Don't navigate the top window to it: it clears the session and then redirects into the CommSite app, which would leave the visitor sitting in the chat rather than back on your page.
This matters most on shared or public computers, where the next person would otherwise inherit the previous visitor's chat identity.
*Optional — one line of JavaScript*
## Open the chat from your page
Once `init` has run, `window.CMSITE.open()` opens the chat from anywhere on your page: a button, a link, or the end of an [AI Summary](/docs/commsite-integration-guide#ex-search). It can send the visitor's first message for them.
*"Ask about this product" button*
```
```
### `CMSITE.open(options)`
*optional · needs init on the same page*
**What it does**
Opens the chat and sends `message` as the visitor's message, into the conversation that's already open when there is one. Without `message`, the chat just opens. The page the visitor is on goes with the message; see [the next section](/docs/commsite-integration-guide#page-context).
**Options**
- `message`: the text to send. Over 1,500 characters it's cut to that length,
the most one message can hold.
- `context`: your own data about the page, the same as setting
[`CMSITE.context`](/docs/commsite-integration-guide#p-context).
**How it opens**
- **With the launcher**, the chat opens the way your CommSite settings say:
the compact window or full screen. A launcher the visitor closed comes back for the call.
If the chat is still loading, the call waits for it: up to 30 seconds for it to load, then
up to 5 seconds for it to be ready.
- **Without the launcher** (`type` set to `"full"`,
`"openWithoutLauncher"` or `"sendMessage"`), the chat reloads into
a new conversation that starts with the message.
- **Before `init`**, nothing happens and the call returns
`false`. Run the [Basic install](/docs/commsite-integration-guide#install) on the same page first.
**open() or type: "sendMessage" ?**
| | `open({ message })` | `type: "sendMessage"` |
| --- | --- | --- |
| Runs | Whenever you call it, for example on a click | When the page loads, as part of `init` |
| Conversation | Continues the open one (with the launcher) | A new one every time `init` runs |
| Best for | Buttons, links and AI Summary follow-ups | A dedicated page that opens on one question |
*Works out of the box*
## What the AI agent knows about the page
Every message a visitor sends from the chat carries the page they're on, and your AI agent uses it as the default subject: "does it support fast charging?" asked on a product page is answered about that product. Nothing is needed on your site for this. Read on to add your own data, mark regions, or collect less.
### How much is collected
An administrator picks the level in the CommSite channel's settings, under **Website page context shared with the AI Agent**. A page can lower the level, never raise it.
| Level | Adds |
| --- | --- |
| Off | Nothing is collected or sent. |
| Basic | Address, canonical address, title, meta description and language. |
| Standard default | Page type, site name, main heading, breadcrumbs, the site search the address holds, structured data about the page's subject (schema.org JSON-LD and microdata, Open Graph product tags: name, SKU, brand, price, availability, rating, specs, FAQ), and the browser's language, time zone and device type. |
| Full | The page's main text (up to 3,000 characters) and the text the visitor selected. |
At every level except Off, your own additions below are sent too.
> **Never collected**
>
>
> Form fields, cookies, local or session storage, and the page's HTML.
> **Privacy, best effort**
>
>
> - Query values in the address are dropped unless their name describes the page. Kept names
>
> include `utm_*`, `q`, `search`, `page`,
>
> `sort`, `category`, `lang`, `variant`,
>
> `sku`, `color` and `size`, and short plain values of other
>
> names are kept too. A value that looks like a token is dropped even under a kept name, except
>
> the site search.
> - Path segments that look like an email address or a token are replaced, and fragments other
>
> than `#/` routes are dropped.
> - Email addresses and phone numbers in collected text become `[email]` and
>
> `[phone]`.
>
>
> Keep secrets out of your addresses, and mark private regions with `data-commsite-ai-ignore`. The data comes from the visitor's browser, so the AI treats it as unverified information, never as instructions or proof of identity.
### Add your own data: `CMSITE.context`
Set an object, or a function that returns one. A function is called each time a message is sent, so it can return the current state; a single-page app can also just update the object when the route or the cart changes.
*A product page with a cart*
```
window.CMSITE = window.CMSITE || {};
window.CMSITE.context = function () {
return {
products: [{ name: "Aurora 14", sku: "AUR14-SLV", price: 1199, currency: "USD" }],
cart: { items: cart.count, total: cart.total, currency: "USD" }, // your own cart state
customer: { tier: "gold", loggedIn: true },
};
};
```
- **Any JSON works.** Suggested sections: `products`, `cart`,
`order`, `customer`, `search`, `error`,
`marketing`, `lead`, `service` and `custom`.
- **Limits:** 4 KB of JSON, five levels deep, 20 items per list and 500 characters
per text. Longer sections are left out.
- **Return the object itself**, not a Promise. A value that throws when it's read
is left out, and the rest is sent.
- `init({ context })` and `open({ context })` set `CMSITE.context` too.
### Markup
| Markup | Effect |
| --- | --- |
| `<meta name="commsite:page-type" content="product">` | The page's type, for the AI. Any `commsite:<key>` meta is sent as a page tag. |
| `<meta name="commsite:page-context" content="basic">` | Lowers the level on this page: `off`, `basic`, `standard` or `full`. |
| `<div data-commsite-context="shipping">` | Sends this element's visible text, labelled `shipping`, at every level except Off: up to 5 regions, 1,000 characters each. A hidden region isn't sent. |
| `data-commsite-ai-ignore` | Keeps an element out of the page text, the regions and the main heading. |
`init({ pageContext: "basic" })` lowers the level on every page that calls it, and `pageContext: false` turns it off. Case and spaces are ignored; any other value turns page context off, with a warning in the console.
> **Check what's sent**
>
>
> In the browser console, `CMSITE.getPageContext("full")` returns what a message would carry from the page right now, at that level or lower.
> **Where it goes**
>
>
> The AI agent gets the current page with every message, and earlier pages with the messages sent from them. Commbox keeps the latest page of each conversation apart from its messages; bot conditions and merge fields can't read it. Page context travels with chat messages only: an [AI Summary](/docs/commsite-integration-guide#ai-start) request carries just the text you give it.
*New — AI Summary*
## AI Summary on your own pages
Your page, your design. One more script, `commsite-ai.js`, sends a question or a piece of page text to your CommSite AI agent and streams the answer, word by word, into an element you choose.
`ask` A question, usually from your search box. The classic use is an AI Summary above your search results, answered from your knowledge base.
`summarize` A text, or the visible text of an element on your page: "Summarize this article", or a quick summary on a product card.
Answers come from the AI agent configured on your CommSite channel: its persona, its instructions and its knowledge base. No conversation is created, and nothing reaches your agents' inbox. [The examples](/docs/commsite-integration-guide#ai-examples) show what visitors see.
### Before you start, in Commbox
#### 1. Check that AI is ready
AI is active for your account, and your CommSite channel has an AI agent. `ask` answers from that agent's knowledge base when it has one. If the **AI Answer API** settings below don't appear in your channel, AI isn't activated for your account yet; your Commbox contact can turn it on.
#### 2. Turn on the AI Answer API
A brand administrator opens the CommSite channel's settings and, under **AI Answer API**, turns on **Enable AI Answer API**. It's off by default on every channel.
#### 3. Approve your websites
In **AI API approved domains**, add each website that will show AI answers, written as an origin: scheme and host, no path.
- `https://www.example.com` allows exactly that site (https only, default port only).
- `https://*.example.com` allows its subdomains only; add
`https://example.com` as well if you need it.
- An empty list blocks every website. `http://` pages, `localhost`,
IP addresses and other ports are never accepted.
The script uses the same Stream ID as your chat snippet ([where to find it](/docs/commsite-integration-guide#p-streamId)).
> **Every answer uses AI credits**
>
>
> Each answered request uses AI credits and appears in the **AI Actions Report**: as *AI Agent Generates a Response* for `ask` on a channel whose agent has a knowledge base, and as *Summarize Conversation* for `ask` without one and for every `summarize`. Ask when a visitor acts, on a search or a click, and never on every keystroke.
### Quick start
Add the script once per page, give the answer a place, and ask.
*Your page — before `</body>`*
```
```
Replace the placeholder with your Stream ID, exactly as in the chat snippet.
### `commsite-ai.js`
*load it right · one tag per page*
**Use this address**
*Always exactly this*
```
https://apps.commbox.io/commsite/commsite-ai.js
```
Other Commbox addresses for CommSite only redirect here, and a redirected AI request fails.
**Check for it before you use it**
An ad blocker, a strict Content-Security-Policy or an old browser can stop the script. Check `window.CMSITE.ai` first, and let the page carry on without the AI block when it's missing.
**Plain, defer or async**
A plain or `defer` tag runs before `DOMContentLoaded`, so `CMSITE.ai` is there in that handler and in any later click or search. Unlike the chat connector, this script may also load `async` or from a tag manager, as long as your code waits for it with the queue below.
### From a tag manager, or with `async`
You can't know whether the script has run yet, so queue your call. Queued functions run as soon as the AI script is ready, or at once if it already is.
*Safe in any order*
```
window.CMSITE = window.CMSITE || {};
(window.CMSITE.aiQueue = window.CMSITE.aiQueue || []).push(function (ai) {
ai.ask({ text: "How do I extend the battery life?", target: "#ai-summary" });
});
```
The script also dispatches `commsite-ai:ready` on `document`, once, with `event.detail = { version, ai }`. Because it fires only once, check first and listen second:
*Or wait for the event*
```
function run() { window.CMSITE.ai.ask({ text: query, target: "#ai-summary" }); }
if (window.CMSITE && window.CMSITE.ai) run();
else document.addEventListener("commsite-ai:ready", run, { once: true });
```
If your tag manager drops `data-` attributes, set the Stream ID before the script loads instead:
*Without data attributes*
```
window.CMSITE = window.CMSITE || {};
window.CMSITE.aiConfig = { streamId: "[Your CommSite Stream ID]" };
```
> **With the chat on the same page**
>
>
> The chat connector and the AI script share `window.CMSITE` without stepping on each other: the connector owns `init`, `open`, `getPageContext` and `context`, and the AI script owns `ai`, `aiConfig` and `aiQueue`. Load them in any order.
>
>
> One exception: an old copy of the connector served from your own server replaces `window.CMSITE` when it runs, which drops an `aiConfig` or `aiQueue` set before it. Load the connector from Commbox, as the [Basic install](/docs/commsite-integration-guide#install) says, or put your AI snippet after the old copy's tag.
*Copy and adapt*
## AI Summary examples
Five setups that cover most sites. Each one fails quietly: when AI isn't available, the AI block stays hidden and the page works as before. The figures show a fictional store; the markup and styles are yours to change.
### An AI Summary above your search results
The visitor searches your site as usual. Above the results, an AI Summary answers the search from your knowledge base, with links to the sources it used. A long answer folds behind *Show more*, and *Still have questions?* hands the visitor to the chat with their search already asked.
> Illustration:
>
>
> 1. Your own search box and results, unchanged.
> 2. The AI Summary block: your markup and your styles. The answer streams in word by word.
> 3. The sources the answer used, as links you render.
> 4. The follow-up: `CMSITE.open()` opens the CommSite chat with the search already sent.
> 5. The conversation carries on in the chat, with the page the visitor is on attached.
1 · Markup, above your results
*Search results page*
```
AI Summary
Still have questions?
AI-generated from our help center. Check important details.
```
2 · Styles: a loading placeholder and the fold
*Your stylesheet*
```
/* While the answer loads. The SDK marks the target, and :empty stops
matching the moment the first words arrive. */
.ai-summary[data-commsite-ai-state="loading"]:empty::before {
content: ""; display: block; height: 4.5em;
border-radius: 8px; background: #eef1f5;
}
/* Long answers fold after about six lines; the fade shows only when there is more */
.ai-fold.is-folded { max-height: 9em; overflow: hidden; }
.ai-fold.is-folded.has-more {
-webkit-mask-image: linear-gradient(#000 60%, transparent);
mask-image: linear-gradient(#000 60%, transparent);
}
```
3 · Script
*After the AI script tag*
```
var block = document.getElementById("ai-block");
var fold = document.getElementById("ai-fold");
var summary = document.getElementById("ai-summary");
var more = document.getElementById("ai-more");
var sources = document.getElementById("ai-sources");
var lastQuery = "";
function showAiSummary(query) {
if (!window.CMSITE || !window.CMSITE.ai) return; // no AI: the block stays hidden
lastQuery = query.trim();
sources.textContent = "";
more.hidden = true;
more.textContent = "Show more";
more.setAttribute("aria-expanded", "false");
fold.classList.add("is-folded");
fold.classList.remove("has-more");
if (lastQuery.length < 3) { // too short to be worth an answer
window.CMSITE.ai.reset(summary);
block.hidden = true;
return;
}
block.hidden = false;
window.CMSITE.ai.ask({
text: lastQuery,
target: summary, // a new search on the same target cancels the previous one
onDone: function (result) {
var overflows = fold.scrollHeight > fold.clientHeight + 1;
fold.classList.toggle("has-more", overflows);
more.hidden = !overflows;
result.sources.forEach(function (source) {
var link = document.createElement("a");
link.href = source.url;
link.textContent = source.title; // text, never HTML
var item = document.createElement("li");
item.appendChild(link);
sources.appendChild(item);
});
},
onError: function () { block.hidden = true; }, // not called when a newer search replaced this one
});
}
more.addEventListener("click", function () {
var folded = fold.classList.toggle("is-folded");
more.textContent = folded ? "Show more" : "Show less";
more.setAttribute("aria-expanded", String(!folded));
});
// The follow-up: the chat opens with the search already sent (needs the chat snippet on this page)
document.getElementById("ai-ask").addEventListener("click", function () {
if (window.CMSITE && typeof window.CMSITE.open === "function") {
window.CMSITE.open({ message: lastQuery });
}
});
// On a results page: answer the search in the address once the AI script is ready
window.CMSITE = window.CMSITE || {};
(window.CMSITE.aiQueue = window.CMSITE.aiQueue || []).push(function () {
showAiSummary(new URLSearchParams(location.search).get("q") || "");
});
```
For instant search, call `showAiSummary(query)` from your own search code instead of the last three lines.
- **Cancelling.** A new `ask` on the same target cancels the previous
one. The cancelled job ends with `ABORTED` (and `error.superseded`), and
`onError` isn't called for it. If you use the returned promise instead of
callbacks, ignore `ABORTED`.
- **On any error** the SDK removes what it rendered and puts back what the target
held before. Hide the block, as above.
- **Sources:** up to 5 `{ title, url }` pairs, http and https only. A
title that names another site than its URL is replaced by the URL, so it's safe link text;
still set it with `textContent`. Or pass `renderSources: true` to have
the list drawn inside the answer.
- **Search as you type:** call `ask` on submit, or debounce typing by at
least 400 ms and require a minimum length. Each call is billed, and fast typing trips the
page's rate guard (`BUSY`).
- **Keeping the previous answer:** by default a new search clears the old answer
while the new one loads. `keepPrevious: true` keeps it until the new one starts,
and `commsite-ai.css` dims it meanwhile.
> **A follow-up text box instead of a button**
>
>
> The follow-up can also be a text box styled like your chat. On submit, pass what the visitor typed to the chat:
>
>
> *Follow-up form*
>
>
> ```
> followForm.addEventListener("submit", function (event) {
> event.preventDefault();
> if (window.CMSITE && typeof window.CMSITE.open === "function") {
> window.CMSITE.open({ message: followInput.value });
> followInput.value = "";
> }
> });
> ```
### "Summarize this article" on a long page
Support articles, specifications and policies get a one-click summary. `summarize` reads the visible text of the element you name.
> Illustration:
>
>
> The summary appears under the button, in an element you choose. Anything marked `data-commsite-ai-ignore`, such as member prices, is left out of what's sent.
*Article page*
```
Battery care for the Aurora 14
…
```
- **What's read:** visible text only. Scripts, styles, form fields, buttons and
hidden elements (`hidden`, `aria-hidden="true"`,
`display: none`, `visibility: hidden`) are skipped, as are the job's own
target and other answers.
- **Leave out** anything else with `data-commsite-ai-ignore`: member
prices, account details, reviews you don't want summarized.
- **Name a specific container.** `body` and `html` aren't accepted.
- **Over 12,000 characters** the job fails with `TEXT_TOO_LONG`, unless
`truncate: true` cuts the text at a word and sets `result.truncated`.
- **`redact: true`** replaces email addresses with `[email]`
and phone numbers with `[phone]` before sending. It's best effort; prefer
`data-commsite-ai-ignore`.
- **Summaries show no links** by default (`links: "none"`), because page
text can carry injected instructions.
### Quick summaries on a product listing
A *Quick summary* on each card of a listing or comparison page, started by a click, or by hovering for a moment.
> Illustration:
>
>
> Each *Quick summary* summarizes that card's visible text, specifications included, into the card's own summary element.
*On a click*
```
document.querySelectorAll(".product-card").forEach(function (card) {
card.querySelector(".quick-summary-button").addEventListener("click", function () {
if (!window.CMSITE || !window.CMSITE.ai) return;
window.CMSITE.ai.summarize({ element: card, target: card.querySelector(".quick-summary") });
});
});
```
*Or on hover — inside the same loop*
```
var timer, job;
card.addEventListener("mouseenter", function () {
timer = setTimeout(function () { // a pointer passing over the card costs nothing
job = window.CMSITE.ai.summarize({ element: card, target: card.querySelector(".quick-summary") });
}, 500);
});
card.addEventListener("mouseleave", function () {
clearTimeout(timer);
if (job) job.abort();
});
```
- **At most 4 jobs run at once** on a page (`maxConcurrent`); more wait
in line, for up to 30 seconds.
- **Aborting:** a waiting job that's aborted never sends a request and costs
nothing. A running job that's aborted stops on the page, but the agent may already be
answering it, and that answer can still count toward your AI credits.
- **Touch screens have no hover**, so keep the button for them.
### Your own rendering
Leave out `target` and the SDK renders nothing. It reports the text as it arrives, and you draw it: in a chat bubble, a card, or your own components.
*Callbacks only*
```
var out = document.getElementById("my-answer");
function show(fragment) {
while (out.firstChild) out.removeChild(out.firstChild);
out.appendChild(fragment);
}
window.CMSITE.ai.ask({
text: query,
onChunk: function (delta, full, cleaned) { show(window.CMSITE.ai.toFragment(cleaned, { partial: true })); },
onDone: function (result) { show(window.CMSITE.ai.toFragment(result.text)); },
onError: function () { show(document.createDocumentFragment()); }, // take back what was shown
});
```
- `onChunk(delta, full, cleaned)` runs on every arrival: `delta` is the new
text, `full` the raw text so far, and `cleaned` the text so far without
leading whitespace and citation markers.
- `partial: true` applies the streaming rules: it hides a dangling `**`, an
unfinished link or citation, and holds back a last line that may still become a list item,
heading, code fence or table row.
- `toFragment` doesn't know which call a text came from, so it renders links by
default. For a `summarize` result, pass `links: "none"`, as the SDK does
in a target.
> **The text is untrusted markdown**
>
>
> Never put `delta`, `full`, `cleaned`, `result.text` or source titles into `innerHTML`, or through a markdown-to-HTML library without sanitizing. `toFragment` builds safe DOM nodes for you.
### React and other single-page apps
Give the SDK an element your framework renders empty, start jobs in effects or event handlers, and abort them in the cleanup.
*React*
```
function AiSummary({ query }) {
const ref = useRef(null);
useEffect(() => {
if (!window.CMSITE?.ai || !query) return;
const job = window.CMSITE.ai.ask({ text: query, target: ref.current });
return () => job.abort(); // a new query or leaving the page cancels it
}, [query]);
return ; // rendered empty; the SDK fills it
}
```
- **Never render children into the target.** The SDK moves the element's children
aside while it answers, so React must not own them. StrictMode's double effect is harmless:
the second job replaces the first.
- **Next.js:**
`<Script src="https://apps.commbox.io/commsite/commsite-ai.js" data-stream-id="…" strategy="afterInteractive" />`,
plus the [queue](/docs/commsite-integration-guide#ai-start) for your calls.
- **Route changes:** abort your jobs, or call `CMSITE.ai.reset()` to
reset every target with a running job. Leaving the page aborts running jobs quietly.
- **Links in answers** are normal links that load a new page. To route them in your
app, catch clicks on `.commsite-ai-link` with event delegation.
- **Angular:** start jobs with `NgZone.runOutsideAngular`, so the SDK's
animation frames don't trigger change detection.
*Reference*
## AI Summary reference
Everything `commsite-ai.js` accepts and returns. `ask` and `summarize` never throw: every problem, invalid options included, rejects the job with a `CommsiteAIError`.
### The script tag
| Attribute | What it does |
| --- | --- |
| `data-stream-id` | Your Stream ID. |
| `data-base-url` | Where requests go, for example `https://apps.commbox.io/commsite`. Only needed when you [host the script yourself](/docs/commsite-integration-guide#ai-selfhost). |
| `data-debug="true"` | Logs each request's lifecycle to the console: ids, lengths and timings, never text. |
### `CMSITE.ai`
| Member | What it does |
| --- | --- |
| `ask(options)` `ask(text, options)` | Answers a question. Returns a [job](/docs/commsite-integration-guide#ai-job). |
| `summarize(options)` | Summarizes `text` or `element` (exactly one of them). Returns a job. |
| `reset(target)` | Aborts the target's job and puts its original content back. Without an argument, does that for every target with a running job. |
| `toFragment(markdown, options)` | Safe DOM for markdown, citation markers removed. `partial: true` applies the streaming rules; links render unless you pass `links: "none"`. |
| `configure(settings)` | Merges [page-wide settings](/docs/commsite-integration-guide#ai-config). Invalid fields are ignored with a console warning; it never throws. |
| `getConfig()` | The settings in effect, frozen. |
| `version` | The SDK version. |
| `CommsiteAIError` | The error class, for `instanceof`. |
### Options for `ask` and `summarize`
| Option | Default | What it does |
| --- | --- | --- |
| `text` | | `ask`: the question, up to 2,000 characters. `summarize`: the text, up to 12,000. Empty text does nothing ([below](/docs/commsite-integration-guide#ai-empty)). |
| `element` | | `summarize` only: an element or CSS selector whose visible text is summarized. |
| `target` | none | The element or CSS selector to render into. Without it, callbacks only. A container such as `div`, `section`, `p`, `span`, `li`, `td`, or a custom element without a shadow root; not inside another answer or another running target. |
| `instructions` | | Up to 500 characters of extra guidance, such as `"Answer in two short bullets."` It travels with the request as part of the question and can't change the agent's persona, knowledge or safety settings. |
| `language` | the page's `lang` | A language tag such as `en`, `he` or `ja-JP`. Invalid tags are dropped. It also sets `lang` on the answer. |
| `stream` | `true` | `false` shows nothing until the answer is complete, then all of it at once. Use it behind a proxy that buffers streamed responses. |
| `smooth` | `true` | Reveals the text gradually. Off for visitors who ask for reduced motion. |
| `format` | `"markdown"` | Or `"text"`: plain paragraphs. |
| `renderSources` | `false` | Adds the sources list inside the answer. |
| `links` | `"all"` for ask, `"none"` for summarize | `"none"` shows links as their text. |
| `allowedLinkHosts` | all | Only links to these hosts render as links, for example `["example.com", "*.example.com"]`. An email link needs the domain of every recipient; a phone link needs the entry `"tel:"`. Applies to the sources list too. |
| `linkTarget` | `"auto"` | `"auto"` opens links to your own site in the same tab and others in a new tab. Or `"_blank"`, `"_self"`, `"_parent"`, `"_top"`. |
| `headingLevel` | `3` | The HTML heading level of a markdown `#`. |
| `classPrefix` | `"commsite-ai"` | The prefix of every class in the answer. Letters, digits, `_` and `-`, starting with a letter, up to 32 characters. |
| `dir` | `"inherit"` | Text direction; see [Styling](/docs/commsite-integration-guide#ai-styling). |
| `keepPrevious` | `false` | Keeps the previous answer visible until the new one starts. |
| `signal` | | An `AbortSignal`; aborting it aborts the job. |
| `streamId` | tag or settings | Uses another channel for this call. |
| `timeoutMs` | `110000` | The overall client timeout from the moment the request is sent, 5,000 to 120,000. |
| `truncate` | `false` | `summarize`: cuts over-long text at a word instead of failing. |
| `redact` | `false` | `summarize`: `true`, or `{ emails, phones }`, to replace them before sending. |
| `onStart`, `onChunk`, `onDone`, `onError` | | Callbacks; see [below](/docs/commsite-integration-guide#ai-callbacks). |
### Page-wide settings: `configure()` and `aiConfig`
Both accept the same fields. Options passed to a single call win over them.
| Setting | Default | What it does |
| --- | --- | --- |
| `streamId` | the tag's | The channel to ask. |
| `baseUrl` | the script's own | Where requests go; for a self-hosted script. |
| `maxConcurrent` | `4` | Jobs running at once on the page, 1 to 10. More wait in line. |
| `maxPerMinute` | `60` | Requests per minute from the page, up to 600; `0` turns the guard off. |
| `queueTimeoutMs` | `30000` | How long a job may wait in line, 1,000 to 120,000, before it fails with `BUSY`. |
| `debug` | `false` | Like `data-debug`. |
| `classPrefix`, `linkTarget`, `headingLevel`, `dir`, `allowedLinkHosts` | | Page-wide defaults for the options of the same name. |
> **Empty text**
>
>
> When the text is empty after trimming, nothing happens: no request, no change to the target, and the job resolves with `{ text: "", skipped: true, rendered: false }`. Only `onDone` is called. Use `reset(target)` to clear a previous answer.
### The job
`ask` and `summarize` return a promise-like job: `then`, `catch`, `finally` and `await` all work.
| Member | What it is |
| --- | --- |
| `state` | `queued`, `connecting`, `streaming`, `finishing`, then `done`, `error` or `aborted`. |
| `requestId` | The server's id for the request, once known. Quote it to support. |
| `abort()` | Stops the job and puts the target's original content back. Does nothing once the job has settled. |
### Callbacks and the result
The order is `onStart` (once the response opened), `onChunk` on every arrival, then exactly one of `onDone` or `onError`; for `ABORTED`, neither. The promise settles after that callback. A callback that throws is logged to the console and doesn't affect the job.
`onStart` doesn't promise success: a refusal such as `ORIGIN_NOT_ALLOWED` can still follow. Reveal your UI on the first `onChunk`, or when `data-commsite-ai-state` becomes `streaming`.
The result holds `text` (the final markdown, citation markers removed), `sources` (up to 5 `{ title, url }`, http and https only), `requestId`, `rendered` (true when the final answer is in the target and the target is still on the page), `truncated`, `skipped`, and `timings`: `ttfbMs`, `firstTokenMs` and `totalMs`, from the moment the request was sent.
> **Streamed text can be taken back**
>
>
> Text appears while the agent writes it. If the request fails late, for example when the agent errors after streaming, the SDK removes the partial answer and restores your content. Visitors may briefly see text that's then removed.
### Styling the answer
Answers are plain HTML with predictable classes and no inline styles, so they take your page's fonts and colors. For a sensible base, add the optional stylesheet. Its rules have zero specificity, so any rule of yours wins.
*Optional base styles*
```
```
The structure inside your target, with the default prefix:
*Rendered answer*
```
```
| Markdown | Element and classes |
| --- | --- |
| paragraph | `p.commsite-ai-p` |
| heading `#` to `######` | `h3` to `h6` (from `headingLevel`), `.commsite-ai-h` plus `.commsite-ai-h1` to `-h6` |
| bullet / numbered list | `ul.commsite-ai-ul` / `ol.commsite-ai-ol`, items `li.commsite-ai-li` |
| quote | `blockquote.commsite-ai-blockquote` |
| code block | `pre.commsite-ai-pre` > `code.commsite-ai-code-block`, always left to right |
| rule | `hr.commsite-ai-hr` |
| table | `table.commsite-ai-table`, `th.commsite-ai-th`, `td.commsite-ai-td`; alignment `.commsite-ai-align-left`, `-center`, `-right` |
| bold, italic, strikethrough | `strong.commsite-ai-strong`, `em.commsite-ai-em`, `del.commsite-ai-del` |
| inline code | `code.commsite-ai-code` |
| link | `a.commsite-ai-link` |
| HTML paragraphs or lists inside a paragraph | `div.commsite-ai-html` wrapper |
| streaming caret | `span.commsite-ai-caret`: empty, hidden from screen readers, invisible unless you style it |
- **Target attributes.** While a job runs, the SDK sets `aria-busy="true"`
and `data-commsite-ai-state` on your target: `loading` while it waits for
the first words, then `streaming`, then `done`. On an error or abort both
go back to what they were. The SDK never changes your target's `class` or
`style`, or anything outside the target.
- **Text direction.** By default (`dir: "inherit"`) each block takes the
direction of most of its first 40 letters, so Hebrew and Arabic read right to left; lists
decide on the whole list. A block whose direction matches your target's gets no
`dir`, so an English brand name at the start of a Hebrew answer doesn't flip it.
Until a block has 40 letters it shows a provisional direction, so passing
`language` when you know it avoids a late switch. `dir: "auto"` sets
`dir="auto"` on every block; `"rtl"` or `"ltr"` force one
direction. Code blocks are always left to right.
- **Plain text.** `format: "text"` renders every block as a paragraph of
plain text: no marks or links, list items as lines starting with a bullet or a number, table
rows as `a | b` lines.
### Errors
Every error is a `CommsiteAIError` with a `code`, an English `message` for developers (don't show it to visitors), the `requestId`, `retryable`, and depending on the code `status`, `retryAfterMs`, `limit`, `field`, `superseded` or `serverCode`.
| Code | Meaning | Retry | What to do |
| --- | --- | --- | --- |
| `ABORTED` | `abort()`, your `signal`, `reset()`, a newer job on the same target (`superseded`), or the visitor left the page. | no | Ignore it. It's never passed to `onError`. |
| `INVALID_REQUEST` | Invalid options or input; the message names the problem. | no | Fix the call. |
| `TEXT_TOO_LONG` | Over a limit: `field` is `text`, `instructions` or `body`, and `limit` says how much is allowed. | no | Shorten the input, or use `truncate: true` with `summarize`. |
| `ORIGIN_REQUIRED` | The request came without a browser origin. | no | Call it from a web page. |
| `ORIGIN_NOT_ALLOWED` | This page's origin isn't in the channel's approved domains. | no | Fix **AI API approved domains**. The SDK also warns once in the console. |
| `AI_API_DISABLED` | The AI Answer API is off for this channel, or temporarily disabled by Commbox. | no | Turn on **Enable AI Answer API**. |
| `STREAM_NOT_FOUND` | Unknown or inactive Stream ID. | no | Check `data-stream-id`. |
| `AGENT_NOT_AVAILABLE` | The channel has no usable AI agent. | no | Set up the channel's AI agent. |
| `AI_NOT_ENABLED` | AI isn't enabled for your account. | no | Ask your Commbox contact. |
| `AI_QUOTA_EXCEEDED` | Your AI credits are used up, or the channel reached its daily request limit. | no | Hide the block. |
| `NO_ANSWER` | The agent had no answer. | no | Hide the block. |
| `AGENT_ERROR` | The agent failed. | yes | Hide the block; retry later, at most once. |
| `BUSY` | Capacity reached on the server, or in the page: the rate guard, or a job that waited too long in line. | yes | Wait at least `retryAfterMs` (else 2 seconds) plus a little random jitter, and retry at most twice. |
| `TIMEOUT` | No response in time: no first response within 15 seconds, no data for 45 seconds, or over `timeoutMs`. The server stops at about 100 seconds. | yes | Retry later. Behind a buffering proxy, use `stream: false`. |
| `NETWORK_ERROR` | The request failed: offline, blocked by CORS or by your CSP's `connect-src`, a redirect, or a broken connection. | yes | Check the console, your CSP, and the script address. |
| `INTERNAL_ERROR` | Anything else. `serverCode` holds a code the SDK doesn't know; the message "check baseUrl" means the address answered 404. | yes | Retry later, and report it with the `requestId`. |
### Limits
| What | Limit |
| --- | --- |
| `ask` text | 2,000 characters |
| `summarize` text | 12,000 characters |
| `instructions` | 500 characters |
| Request body | 64 KB (reached only with unusual text) |
| Answer | 100,000 characters; up to 5 sources |
| Client timeouts | 15 seconds for the response to start, 45 seconds without data (off with `stream: false`), 110 seconds overall |
| Server | Stops after about 100 seconds |
| Per page | 4 jobs at once (more wait in line, up to 30 seconds), 60 requests per minute |
Characters are counted like JavaScript's `string.length`, and a line break counts as one. The text limits are fixed; the per-page limits are the `maxConcurrent`, `queueTimeoutMs` and `maxPerMinute` settings.
### Browser support
| Browser | Minimum |
| --- | --- |
| Chrome, Edge | 66 |
| Firefox | 65 (57 to 64 work without the word-by-word display) |
| Safari, iOS | 12.1 |
| Samsung Internet | 9.2 |
Internet Explorer isn't supported: the script doesn't run and `CMSITE.ai` stays undefined, which is one more reason to check for it. `commsite-ai.css` needs Chrome 88, Safari 14 or Firefox 78; older browsers show the answers unstyled.
### Versions and caching
- `https://apps.commbox.io/commsite/commsite-ai.js` is the supported address: always
the latest version 1 build. Browsers check it on every load (a cheap 304), so fixes reach you at
once. Changes within version 1 only add things; a breaking change would ship under a new file
name.
- Don't pin a versioned copy or use Subresource Integrity in production yet: earlier versions
aren't kept across releases.
### Hosting the script yourself
Loading it from Commbox is the recommended way. If your policy requires serving it from your own domain or CDN, tell it where CommSite is with `data-base-url` (or `configure({ baseUrl })`):
*Self-hosted copy*
```
```
The file may be renamed, for example with a hash from your asset pipeline: the SDK reads the attributes of the tag that runs it, as long as that tag carries `data-stream-id`. Update your copy regularly; the API is versioned, but your copy isn't.
### TypeScript
Declarations you can copy into your project.
*commsite-ai.d.ts*
```
type AiErrorCode =
| "INVALID_REQUEST" | "TEXT_TOO_LONG" | "ORIGIN_REQUIRED" | "ORIGIN_NOT_ALLOWED" | "AI_API_DISABLED"
| "STREAM_NOT_FOUND" | "AGENT_NOT_AVAILABLE" | "AI_NOT_ENABLED" | "AI_QUOTA_EXCEEDED" | "NO_ANSWER"
| "AGENT_ERROR" | "BUSY" | "TIMEOUT" | "INTERNAL_ERROR" | "NETWORK_ERROR" | "ABORTED"
interface AiSource { title: string; url: string }
interface AiResult {
text: string; sources: AiSource[]; requestId: string | null; rendered: boolean
skipped?: true; truncated?: true
timings: { ttfbMs: number | null; firstTokenMs: number | null; totalMs: number }
}
interface CommsiteAIError extends Error {
name: "CommsiteAIError"; code: AiErrorCode; requestId: string | null; status?: number; retryable: boolean
retryAfterMs?: number; superseded?: true; limit?: number; field?: "text" | "instructions" | "body"; serverCode?: string
}
interface AiCommonOptions {
target?: Element | string | null
format?: "markdown" | "text"; language?: string; instructions?: string; stream?: boolean; smooth?: boolean
linkTarget?: "auto" | "_blank" | "_self" | "_parent" | "_top"; renderSources?: boolean; classPrefix?: string
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6; dir?: "inherit" | "auto" | "rtl" | "ltr"; links?: "all" | "none"
allowedLinkHosts?: string[]; keepPrevious?: boolean; signal?: AbortSignal; streamId?: string; timeoutMs?: number
onStart?(info: { requestId: string | null }): void
onChunk?(delta: string, full: string, cleaned: string): void
onDone?(result: AiResult): void
onError?(error: CommsiteAIError): void
}
interface AiJob extends PromiseLike {
readonly requestId: string | null
readonly state: "queued" | "connecting" | "streaming" | "finishing" | "done" | "error" | "aborted"
abort(): void
catch(onRejected?: ((e: CommsiteAIError) => R | PromiseLike) | null): Promise
finally(onFinally?: (() => void) | null): Promise
}
interface AiConfig {
streamId?: string; baseUrl?: string; classPrefix?: string; linkTarget?: AiCommonOptions["linkTarget"]
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6; dir?: AiCommonOptions["dir"]; allowedLinkHosts?: string[]
maxConcurrent?: number; maxPerMinute?: number; queueTimeoutMs?: number; debug?: boolean
}
interface CommsiteAiApi {
readonly version: string
configure(config: AiConfig): void
getConfig(): Readonly
ask(options: AiCommonOptions & { text: string }): AiJob
ask(text: string, options?: AiCommonOptions): AiJob
summarize(options: AiCommonOptions & ({ text: string } | { element: Element | string }) &
{ truncate?: boolean; redact?: boolean | { emails?: boolean; phones?: boolean } }): AiJob
reset(target?: Element | string): void
toFragment(markdown: string, options?: { format?: "markdown" | "text"; partial?: boolean; classPrefix?: string;
linkTarget?: AiCommonOptions["linkTarget"]; headingLevel?: number; dir?: AiCommonOptions["dir"];
links?: "all" | "none"; allowedLinkHosts?: string[] }): DocumentFragment
readonly CommsiteAIError: new (code: AiErrorCode, message: string) => CommsiteAIError
}
declare global {
interface Window {
CMSITE?: { ai?: CommsiteAiApi; aiConfig?: AiConfig; aiQueue?: { push(...f: Array<(ai: CommsiteAiApi) => void>): number } }
}
}
```
*If something's off*
## Troubleshooting
CommSite reports very little to the host page, so most failures are silent rather than logged. Match the symptom below to get straight to the fix.
### Nothing appears, and the console says "CommSite could not be loaded."
The connector script didn't load or didn't run. In order of likelihood:
- A Content-Security-Policy on your page is blocking it — see [For your IT team](/docs/commsite-integration-guide#security).
- An ad blocker or corporate network filter is blocking the request.
- The `src` URL has a typo. Open it directly in a browser tab; you should see JavaScript.
- The script tag has `async` on it. Remove it, or use `defer`.
### Nothing appears, and there's no console message at all
`init` ran, so check what it produced. In your browser's element inspector, search for `commsite-iframe`.
- **It isn't there** — if you're using `targetElement`, the
container id probably doesn't exist yet. Look for a `TypeError`.
- **It's there but `display: none`** — expected briefly with
`type: "openInCompactView"`. If it never becomes visible, it's the
`url` mismatch below.
- **It's there and visible but empty** — your CSP is blocking the frame
itself. Check for a `frame-src` message in the console.
### The launcher shows up but nothing happens when you click it
This is the single most common install problem, and it's almost always `url`. Your page trusts exactly one address, and the widget is loading from a slightly different one, so the two can't talk.
The value must be `https://apps.commbox.io/commsite/`. Each of these counts as a different address:
- `http://` instead of `https://`
- An added `www.`
- A relative path such as `"/commsite"`
- A proxy or vanity domain on your own site pointing at Commbox
- Omitting `url` entirely
The match is byte-exact and nothing is logged when it fails, so compare your value with the string above character by character.
### A small dark box with cut-off artwork appears instead of the chat
That's a "not found" page rendered inside the launcher's small frame. Your `streamId` didn't resolve. Re-copy it from your CommSite channel in Commbox, complete with any trailing `%3d`, and check nothing altered it on the way into your template — some content-management systems and template engines re-encode `%` characters.
If the ID is definitely right, it's worth checking with Commbox support: the same page appears if the CommSite service can't be reached.
### Voice input or dictation doesn't work
- The page must be served over **HTTPS**. Browsers don't grant microphone
access on plain HTTP.
- If your site sends a `Permissions-Policy` header, it must allow
`microphone` for the CommSite origin. Your page's policy overrides what the
widget asks for.
- **Firefox doesn't support browser speech recognition**, so voice input is
unavailable there regardless of settings. Chrome, Edge and Safari are fine.
### A visitor closed the widget and it won't come back
Closing from the launcher's menu hides the widget for the rest of that page view; it returns on the next page load or refresh. The snippet can't bring it back sooner — a navigation or reload is the only way.
### The frame controls are hidden on a page where you didn't turn them off
`showFrameButtons: false` is remembered for the whole browser tab, per CommSite. If another page in the same tab loaded the widget with the controls hidden, later pages inherit that. Open a new tab to confirm, and avoid mixing an inline embed and a floating launcher for the same CommSite across your site.
Some controls are also governed by your CommSite settings in Commbox rather than by the snippet — if they're missing in a fresh tab too, check there.
### Something near the bottom of your page isn't clickable anymore
The launcher occupies a rectangle on your page, and that rectangle captures clicks across its full area — including the parts that look empty, since it reserves a little room for its shadow. Anything underneath it won't respond.
It's sized to be as small as possible, but if it overlaps something important — a cookie banner button, a back-to-top control, footer links — move that element up, or ask your Commbox contact about changing the launcher's alignment, which is a CommSite setting rather than a snippet option.
### `CMSITE.open()` does nothing
It returns `false` when `init` hasn't run on that page yet. Run the [Basic install](/docs/commsite-integration-guide#install) first, on the same page. If the chat is still loading, the call waits for it rather than failing.
### AI Summary
Every AI error carries a `requestId`; include it when you contact support. `data-debug="true"` on the script tag logs each request's lifecycle to the console.
| Symptom | Cause and fix |
| --- | --- |
| `NETWORK_ERROR`, with a CORS message in the console | The script was loaded from another Commbox address, or a proxy or your CSP blocked the request. Load `https://apps.commbox.io/commsite/commsite-ai.js` and allow it in `connect-src`. |
| `ORIGIN_NOT_ALLOWED` | Add the page's exact origin (scheme and host, no path) to **AI API approved domains**. Pages on `http://`, `localhost` or an IP address are never accepted, whatever the list says; the console warning tells the two cases apart. |
| `AI_API_DISABLED` | **Enable AI Answer API** is off for this channel. |
| Nothing happens | The text was empty (`result.skipped`), the target isn't allowed (the error message says why), or `CMSITE.ai` wasn't ready yet: use the `aiQueue`. |
| The placeholder or old content stays | A framework re-rendered the target. Give the SDK an element the framework renders empty. |
| The answer appears only at the end, or `TIMEOUT` after 45 seconds | A proxy buffers streamed responses. Use `stream: false`. |
| `BUSY` while typing | Too many calls. Debounce, and require a minimum length. |
| A link shows as plain text | `links: "none"`, the default for summaries, or `allowedLinkHosts` doesn't cover it. An email link needs every recipient's domain, a phone link the entry `"tel:"`. |
| `INTERNAL_ERROR`, "check baseUrl" | The request went to an address without the API: a self-hosted script without `data-base-url`. |
| `aiConfig` or an `aiQueue` function is ignored | An old copy of `commsite-connect.js` on your own server replaced `window.CMSITE` after your snippet ran. Load the connector from Commbox, or put the snippet after the old copy's tag. |
*Reference*
## For your IT team
The answers to the questions that come up in a security or platform review, and the headers you may need to change.
### Content-Security-Policy
If your site sends a CSP, it needs to allow the Commbox origin in two places — one to load the connector, one to frame the app.
*Minimum additions*
```
script-src https://apps.commbox.io;
frame-src https://apps.commbox.io;
```
The `init` call in the snippet is an inline script. If your policy doesn't allow inline scripts, either give that tag a `nonce` or move the call into a JavaScript file of your own — the cleaner option of the two.
*AI Summary also needs*
```
connect-src https://apps.commbox.io;
style-src https://apps.commbox.io;
```
`script-src` above covers `commsite-ai.js`, and `style-src` is needed only if you load `commsite-ai.css`. The AI script injects no inline scripts or styles and never parses HTML, so it also works under Trusted Types.
### Permissions-Policy
Only needed if you use voice or location features, and only if your site sends this header at all. The widget requests microphone, geolocation, autoplay, clipboard and fullscreen access, but your page's policy has the final say — if it doesn't delegate them, they fail silently inside the chat.
*Only if you send this header*
```
Permissions-Policy: microphone=(self "https://apps.commbox.io")
```
### Common review questions
| Question | Answer |
| --- | --- |
| Does it read our page or our users' data? | The chat itself runs in a sandboxed iframe on a separate origin — it cannot read your page's content, forms, cookies or storage. The connector script runs in your page like any first-party script: it creates the frame, listens for its messages, and reads and clears one cookie of its own (see the next row). When a visitor sends a message, it also reads the page details your page-context level allows and hands them to the chat; see [What the AI agent knows about the page](/docs/commsite-integration-guide#page-context). It never reads form fields, other cookies or storage. |
| What can it do to our page? | Four things: resize or hide its own frame, navigate the visitor to a link your bot provides, lock page scrolling while the chat is full screen, and set one short-lived first-party cookie on your domain (`iframeRedirected`, path `/`, SameSite=Lax, Secure) so an open conversation survives a bot-driven page navigation. Nothing else. |
| Can it navigate users off-site? | Only to `http` and `https` destinations. Other schemes are refused. |
| How are page and widget messages secured? | Every message your page accepts from the widget is checked against the exact origin you configure in `url`; anything else is discarded. Messages your page sends in carry layout information — viewport width, height and text direction — plus the page details and `CMSITE.open()` messages for the AI agent, which go to the CommSite origin only. |
| Is HTTPS required? | Yes. Microphone access, session continuity across navigations, and cookie handling all depend on it. |
| Third-party cookies? | The widget is cross-site by nature. It handles browsers that block third-party cookies (Safari in particular), with sessions scoped to the browser session. |
| Where does it sit in our stacking order? | At the top — above modals, cookie banners and sticky headers. Not configurable from the snippet. |
| Any known limitation? | File downloads started from inside the chat are blocked by the iframe sandbox. Also avoid `Cross-Origin-Embedder-Policy: require-corp` on pages hosting the widget — it prevents the frame loading. |
### AI Summary review questions
| Question | Answer |
| --- | --- |
| What does a request send? | The text you pass (or the visible text of the element you name), the language, your instructions and the SDK version, to `https://apps.commbox.io`. The browser adds your page's origin. No cookies, no page address, no page title; the referrer is limited to your origin. |
| What does Commbox keep? | No conversation or inbox record is created. Each request appears in usage reports. The AI provider may retain request content according to its configuration. |
| Is personal data masked? | Commbox masks credit card numbers, and masks long digit sequences when the channel's **Hiding Numeric Data from AI Providers** setting is on. Email addresses and names are never masked on the server, so keep personal data out of what you send: `data-commsite-ai-ignore` first, `redact` as a best-effort extra. |
| Who can call it? | Browsers on pages in the channel's **AI API approved domains**. The list stops other websites from using your channel; it isn't authentication, because a script or server can claim any origin. Treat the Stream ID as public, keep secrets out of the page, and watch the AI Actions Report. Commbox also caps each channel's requests per day. |
| Can an answer put code or misleading links on our page? | Answers are built from a fixed set of safe elements; HTML in an answer is never parsed. Only `http`, `https`, `mailto` and `tel` links render, all with `rel="noopener noreferrer nofollow ugc"`. Link text that reads as an address must match the real destination, or the real address is shown instead. Summaries show no links by default, and `allowedLinkHosts` limits links to your own sites. |
| Does it change anything else on the page? | No. It renders inside the target you give it, never changes the target's `class` or `style`, and touches nothing outside it. |
| Which browsers? | Chrome and Edge 66, Firefox 65, Safari and iOS 12.1, Samsung Internet 9.2. Internet Explorer isn't supported. |
*Before you ship*
## Good to know
> **Call init once per page load**
>
>
> Running `init` again rebuilds the widget from scratch and discards whatever conversation was on screen. In a single-page app, call it at the app root behind a guard — not from a component that re-mounts on navigation.
> **One widget per page**
>
>
> You can't run two CommSites side by side on the same page — a second `init` replaces the first. If you need different bots for different sections of your site, use a different `streamId` per page.
> **Some things live in Commbox, not in the snippet**
>
>
> Which edge the launcher sits on, its size when open, colors and branding, greetings and suggested questions, and whether the launcher starts open are all CommSite settings managed in your Commbox account. If you want to change one of those, that's where to go — no code change needed, and it applies everywhere the snippet is installed.
> **Add a frame title for accessibility**
>
>
> CommSite doesn't set a title on its own frame, so screen readers announce an unlabeled frame. Give it an accessible name after `init`:
>
>
> *After init*
>
>
> ```
> const f = document.getElementById("commsite-iframe");
> if (f) f.title = "Customer support chat";
> ```
> **Test on a phone before you ship**
>
>
> The chat behaves differently on small screens — it goes full screen where a desktop browser would open a compact window. That's intended, and worth seeing for yourself on the pages where you've installed it.
> **Ask for AI answers when a visitor acts**
>
>
> Every answered request uses AI credits. Start `ask` on a search or a click, debounce typing, and delay hover summaries, then check the AI Actions Report after launch.
> **Say that answers are AI-generated**
>
>
> Tell visitors that the content is AI-generated (a short line under the block is enough), and cover the processing in your privacy notice and data processing agreement.
> **AI Summary works without the chat**
>
>
> `commsite-ai.js` doesn't need the chat on the page. Only the follow-up that opens the chat, `CMSITE.open()`, needs the chat snippet.
Stuck on something this guide doesn't cover? Your Commbox contact can look at your specific CommSite configuration — and if the widget loads but behaves oddly, mentioning the exact `streamId` and `url` you're passing will get you to an answer fastest. For AI Summary, include the `requestId` from the error.