Messenger
Messenger JavaScript API
Reference for every Dimmi() command, runtime setting, script attribute, window event, and @dimmi/browser method.
Control the messenger from JavaScript using the global Dimmi(command, ...args) function or the @dimmi/browser client returned by every @dimmi framework package.
Commands
Section titled “Commands”| Command | Arguments | Client method | What it does |
|---|---|---|---|
open |
None | show() |
Opens the messenger. |
close |
None | hide() |
Closes the messenger. |
toggle |
None | toggle() |
Toggles the messenger open or closed. |
ask |
text |
showNewMessage(text) |
Starts a new conversation with text as the first message. |
update, boot |
settings |
update(settings) |
Merges settings over the current config and redraws. |
identify |
source (optional) |
identify(source?) |
Sets the identity token provider, or refreshes the current one if omitted. |
logout, shutdown |
None | shutdown() |
Ends the customer’s session in the browser and on the server. |
track |
name, metadata |
trackEvent(name, metadata?) |
Tracks a customer event. |
If you call Dimmi() before the loader script finishes loading, add this tiny queue stub first:
<script> window.Dimmi = window.Dimmi || function () { (Dimmi.q = Dimmi.q || []).push([].slice.call(arguments)); };</script>Runtime settings
Section titled “Runtime settings”Pass any of these keys to update. Omitted keys keep your dashboard defaults.
| Key | Value |
|---|---|
appearance.primary_color |
Hex color (such as #0f766e) |
appearance.header_color, appearance.button_color |
Hex color |
appearance.theme |
"light", "dark", or "auto" |
appearance.position |
"right" or "left" |
appearance.padding_x, appearance.padding_y |
Offset in pixels from the side and bottom edges |
appearance.launcher.style |
"bubble", "tab", or "hidden" |
appearance.launcher.shape |
"circle" or "squircle" |
appearance.launcher.label |
Custom tab label text |
appearance.font |
"system" or "inherit" (matches your page font) |
appearance.sound |
Boolean; false silences the messenger |
appearance.sent_sound, appearance.reply_sound |
"none" turns off the sound for a message going out or coming in; any other value ("pop", "chime", "bubble", "swoosh", "tick") turns it on |
texts |
Key-value overrides such as greeting, chat_title, or composer_placeholder |
language |
Language tag such as fr or pt-BR |
Dimmi("update", { appearance: { primary_color: "#0f766e", launcher: { style: "tab", label: "Help" } },});Script tag attributes
Section titled “Script tag attributes”| Attribute | Value |
|---|---|
src |
<host>/widget/v1/loader.js |
data-app-id |
Messenger app ID (wgt_...) |
data-api-base |
Custom API origin if different from the loader host |
data-identity-url |
Same-origin endpoint returning the identity token |
nonce |
Content Security Policy nonce |
HTML button triggers
Section titled “HTML button triggers”Clicking any element with data-dimmi="open", "close", or "toggle" runs that command automatically.
Window events
Section titled “Window events”The messenger fires dimmi:unread on window on startup and whenever the unread count changes. Read the count from event.detail.count.
@dimmi/browser functions and options
Section titled “@dimmi/browser functions and options”Every helper is SSR-safe and does nothing on the server.
| Function | What it does |
|---|---|
loadDimmi(options) |
Injects the loader script once and returns the client. |
getDimmi() |
Returns the client for a messenger loaded elsewhere (such as via script tag). |
dimmi(name, ...args) |
Sends a raw command (same as client.command()). |
loadDimmi(), <DimmiProvider>, <Dimmi>, createDimmi(), provideDimmi(), and initDimmi() share these options (<Dimmi> in @dimmi/nextjs accepts appId, host, identity, and nonce):
| Option | Value |
|---|---|
appId |
Required. Messenger app ID. |
host |
Required. https://trydimmi.com, or your self-hosted URL. |
apiBase |
Sets data-api-base. |
nonce |
Sets nonce. |
identity |
Function returning a JWT string or null. |
identityUrl |
Sets data-identity-url. |
settings |
Initial runtime settings. |
Along with every method in Commands, the client exposes:
| Member | What it does |
|---|---|
ready |
Promise that resolves when the loader finishes and rejects if blocked. |
onUnreadCountChange(fn) |
Subscribes to dimmi:unread with fn(count) and returns an unsubscribe function. |