AI Tema
Skip to content
AI Tema
What it doesChannelsQuestions
Wiki
EN
РусскийRUEspañolESSrpskiSREnglishEN
Log in
AI Tema wiki
InstallationPosition and CSS classesAppearance and labelsAll optionsJavaScript APIEventsLoading and sizeSPA and security
AI Tema wiki/Widget

JavaScript SDK 1.0.0

Website chat widget

Install, style and control your chat with JavaScript. One script, no libraries and no changes to your website build.

Installation

Create a Website chat connection, allow your domains and activate a workflow. Copy the snippet from connection settings and place it before </body>. Replace ACCOUNT_ID with the connection UUID.

Instructions for your platform ↗

HTML
<script
  src="https://api.aitema.cloud/api/v1/chat/widget.js"
  data-account="ACCOUNT_ID"
  defer
></script>

HTTPS is required. The www and non-www addresses work as a pair; add other subdomains separately. HTTP is supported for localhost and 127.0.0.1.

Position and CSS classes

The button starts in the bottom right corner. The root element has the .aitema-widget class. Use one of the four positioning classes or add your own with data-class. Classes can change after loading.

aitema-bottom-rightaitema-bottom-leftaitema-top-rightaitema-top-left
HTML
<script
  src="https://api.aitema.cloud/api/v1/chat/widget.js"
  data-account="ACCOUNT_ID"
  data-class="my-chat aitema-bottom-left"
  defer
></script>

Your website CSS can override the root position and --aitema-* variables. Style internal elements with ::part(). Page styles do not automatically enter the chat.

Numeric options and accent passed through data attributes or update() set inline variables. Use !important to override these explicit values in CSS. Position classes work without it.

CSS
.my-chat {
  --aitema-offset-x: 24px;
  --aitema-offset-y: 80px;
  --aitema-accent: #167d8d;
  --aitema-width: 380px;
  --aitema-height: 540px;
  --aitema-z-index: 1200;
}

.my-chat::part(launcher) { border-radius: 12px; }
.my-chat::part(panel) { border-radius: 20px; }
.my-chat::part(header) { font-weight: 600; }

::part(): launcher, panel, header, close, messages, message, user-message, bot-message, input, send, status.

CSS
.my-chat {
  --aitema-font: 14px/1.5 system-ui, sans-serif;
  --aitema-radius: 16px;
  --aitema-launcher-radius: 28px;
  --aitema-surface: #ffffff;
  --aitema-raised: #f0f4f6;
  --aitema-text: #1d303c;
  --aitema-muted: #596f7e;
  --aitema-border: #d7e0e6;
  --aitema-on-accent: #ffffff;
}

Appearance and labels

Use data attributes or update() to change options. locale="auto" selects Russian, English, Spanish or Serbian Latin from the browser. theme="auto" follows the system theme.

HTML
<script
  src="https://api.aitema.cloud/api/v1/chat/widget.js"
  data-account="ACCOUNT_ID"
  data-theme="light"
  data-locale="en"
  data-accent="#167d8d"
  data-launcher-text="Ask a question"
  data-title="Support"
  data-greeting="Hello! How can we help?"
  defer
></script>

greeting appears in an empty conversation. It does not send a visitor message or start a workflow. A message or visitor choice starts the workflow; write workflow messages in the editor.

All options

OptionType / valuesDefaultPurpose
accountdata-accountUUID—Connected account UUID
classNamedata-classstring""Additional CSS classes
positiondata-positionbottom-right | bottom-left | top-right | top-leftbottom-rightScreen corner
themedata-themeauto | light | darkautoColor theme
localedata-localeauto | ru | en | es | srautoInterface language
accentdata-accent#RRGGBB#6268d9Accent color
offsetX / offsetYdata-offset-x / data-offset-ynumber: 0–51222 / 22Edge offsets, px
width / heightdata-width / data-heightnumber: 280–640 / 300–900360 / 490Window width and height, px
zIndexdata-z-indexnumber: 1–214748364710000Page stacking level
launcherVisibledata-launcherbooleantrueShow the launcher
launcherTextdata-launcher-textstring ≤ 150localeLauncher label
title / subtitledata-title / data-subtitlestring ≤ 150account / localeTitle and subtitle
greetingdata-greetingstring ≤ 2000localeEmpty chat greeting
placeholderdata-placeholderstring ≤ 150localeInput placeholder
storagedata-storagelocal | session | nonelocalVisitor token storage
containerdata-container (selector)selector | Element | ShadowRootdocument.bodyParent element; mount only
noncedata-style-noncestringscript.nonceStyle nonce; mount only

JavaScript API

Aitema.get(ACCOUNT_ID) returns the automatically mounted instance. Aitema.mount(options) or new Aitema.Widget(options) creates one manually. A page supports one widget per connected account.

JavaScript
Aitema.ready(sdk => {
  const chat = sdk.get("ACCOUNT_ID");
  chat.update({
    position: "bottom-left",
    theme: "light",
    locale: "en",
    launcherVisible: false
  });

  document.querySelector("#contact-us")
    .addEventListener("click", () => {
      chat.open().catch(console.error);
    });
});
open(): Promise<Widget>Open the window; resolves after loading the UI.
close(): WidgetClose the window.
toggle(): Promise<Widget>Toggle the window.
update(options): WidgetChange options without losing the conversation.
on(name, listener): () => voidSubscribe; returns an unsubscribe function.
destroy(): voidRemove the instance and release resources.

Queue a callback when your code runs before the script. After loading, use Aitema.ready(callback).

JavaScript
window.Aitema = window.Aitema || { q: [] };
const configure = sdk => {
  const chat = sdk.get("ACCOUNT_ID");
  chat.update({ className: "my-chat" });
};
if (Aitema.ready) Aitema.ready(configure);
else Aitema.q.push(configure);
JavaScript
// Load widget.js without data-account for manual mounting.
Aitema.ready(sdk => {
  const chat = new sdk.Widget({
    account: "ACCOUNT_ID",
    container: "#support-root",
    className: "my-chat",
    position: "bottom-right",
    storage: "session"
  });

  chat.element.classList.add("aitema-bottom-left");
  // On SPA component cleanup:
  // chat.destroy();
});

Events

Events bubble from the root element to document. detail always contains account. The message event includes status and response count, without conversation text or tokens.

JavaScript
document.addEventListener("aitema:message", event => {
  const { account, status, messagesCount } = event.detail;
  console.log({ account, status, messagesCount });
});

Aitema.ready(sdk => {
  const chat = sdk.get("ACCOUNT_ID");
  const unsubscribe = chat.on("error", event => {
    console.log(event.detail.code);
  });
  // unsubscribe();
});
aitema:readyButton mounted; chat code is still unloaded.
aitema:openWindow opened.
aitema:closeWindow closed.
aitema:messageResponse processed: status and messagesCount.
aitema:errorFailure: code and message.

Loading and size

Installation loads only the button and loader. Chat code, UI, session and history load on the first open. When idle, the widget does not poll the server or run background animations.

Current build size, KiB
BrotligzipUncompressed
Initial load2.843.289.59
On first open4.455.2913.17

JavaScript and CSS are minified. The server sends prebuilt Brotli or gzip. The loader caches for 5 minutes with ETag; the hashed chat module caches for a year. Cached v1 loaders keep working after server updates. No fonts, images, iframes or third-party libraries are loaded.

SPA and security

Load the script once in an SPA. Call update() to change settings and destroy() when removing the widget. Destroy cancels requests and listeners, without deleting server history.

storage controls token storage: local across visits, session within a tab, none in memory only. Signed sessions last 24 hours after renewal. Clearing storage, switching browser or using another origin creates a separate visitor.

Allow api.aitema.cloud in Content Security Policy script-src and connect-src. When inline styles require a nonce, pass the current response nonce in data-style-nonce. Automatic mounting also inherits the script nonce. Keep your existing CSP restrictions.

HTML
<script
  src="https://api.aitema.cloud/api/v1/chat/widget.js"
  data-account="ACCOUNT_ID"
  data-style-nonce="RESPONSE_NONCE"
  nonce="RESPONSE_NONCE"
  defer
></script>
AI Tema

Automated replies and lead collection for your business.

My accountTry a workflow
© 2026 AI Tema
DocumentationPrivacy PolicyTerms of Service
A gomvp.dev product ↗