Install
Add one script tag with your workspace id. The widget mounts itself in an isolated Shadow DOM, so it never clashes with your page styles.
Script tag
The simplest install — paste this before the closing body tag.
Async command queue
Define a small stub before the SDK loads so calls made early are buffered and replayed once the widget mounts.
Configuration
Set window.awncareSettings before the SDK loads to configure the boot. These override the script tag's data-* attributes.
| Field | Type | Description |
|---|---|---|
workspaceId | string | Your workspace id. Required unless supplied via data-workspace-id. |
locale | "ar" | "en" | Initial UI language of the widget. |
position | "bottom-right" | "bottom-left" | Which corner the launcher sits in. |
color | string | Launcher and accent color (any CSS color). |
zIndex | number | Stacking order of the widget host. Defaults to the maximum. |
hideLauncher | boolean | Start with the launcher hidden; reveal it later with AwnCare.show(). |
baseUrl | string | Override the API origin the widget talks to. |
API reference
Every method available on window.AwnCare. Methods called before the widget finishes mounting are queued and replayed automatically.
version: string
The SDK semantic version string, e.g. "1.0.0".
open(): void
Open the chat window.
close(): void
Close the chat window.
toggle(): void
Toggle the chat window open or closed.
isOpen(): boolean
Returns true when the chat window is currently open.
sendMessage(text: string): void
Send a message from the visitor into the active conversation.
setUser(data): void
Set lightweight session attributes (name, email, and any extra keys) for the current visitor.
identify(data: IdentifyData): void
Persist contact traits to the server visitor record so agents see who they are talking to.
on(event, callback): void
Subscribe to a widget event with a callback.
off(event, callback?): void
Remove a specific listener, or every listener for an event when no callback is passed.
setLocale(locale: "ar" | "en"): void
Switch the widget UI language at runtime.
getUnreadCount(): number
Return the current unread message badge count.
hide(): void
Remove the widget from view entirely (host element hidden).
show(): void
Restore the widget after hide(); also reveals a launcher started with hideLauncher.
destroy(): void
Unmount the widget and remove it from the DOM.
logout(): void
Clear the current visitor identity — use on sign-out to start a fresh session.
trackEvent(name, data?): void
Record a custom visitor event with optional data for context and automations.
identify() data
The traits accepted by AwnCare.identify(). All fields are optional; provide what you know.
| Field | Type | Description |
|---|---|---|
name | string | The contact's display name. |
email | string | The contact's email address. |
phone | string | The contact's phone number. |
externalId | string | A stable id from your own system to link this contact. |
company | string | The contact's company name. |
metadata | Record<string, unknown> | Any additional custom traits, merged into the visitor record. |
Events
Subscribe with AwnCare.on(name, callback). Handlers receive the payload shown below.
| Event | Payload | Description |
|---|---|---|
ready | — | Fires once the widget has mounted and is ready to use. |
open | — | Fires when the chat window opens. |
close | — | Fires when the chat window closes. |
message | Message | Legacy alias — fires for every agent or bot message, with the full message object. |
message:received | { text, sender: "agent" | "bot" } | Fires when an agent or bot message arrives. |
message:sent | { text } | Fires when the visitor sends a message. |
conversation:started | { conversationId } | Fires when a new conversation is created. |
unread | number | Fires when the unread badge count changes. |