Browse docs
Widget JavaScript API reference
Every window.Axoryn method, init option and script data attribute of the Axoryn widget, with signatures, parameters and examples.
This is the reference for developers who control the widget from code. It lists every method on window.Axoryn, every option init() accepts, and every attribute the script tag reads. For a first install, start with Install the Axoryn widget.
How the API loads
widget.js defines window.Axoryn when it runs. With the standard async snippet, that happens after the rest of your page’s scripts may already have run, so wait for it before calling a method:
function whenAxoryn(timeoutMs = 10000) {
return new Promise((resolve, reject) => {
const started = Date.now()
const check = () => {
if (window.Axoryn) return resolve(window.Axoryn)
if (Date.now() - started > timeoutMs) return reject(new Error('Axoryn widget did not load'))
setTimeout(check, 100)
}
check()
})
}
whenAxoryn().then((Axoryn) => Axoryn.identify({ name: 'Jane Doe' }))
widget.js is a small loader. The full widget loads later: when the visitor opens the chat, when you call a method that opens it, or right away for a returning visitor with a conversation in progress. Calls made before the full widget loads are queued and replayed in order once it does. Several open calls in the queue (open, openWithGreeting, ask) collapse into the last one.
Note: The widget does not emit events or accept callbacks. There is no event for messages, opening or closing.
Methods
| Method | Returns | Loads the full widget |
|---|---|---|
init(config) | Promise<void> | Yes |
open(message?) | nothing | Yes |
openWithGreeting(greeting) | nothing | Yes |
ask(question, greeting?) | nothing | Yes |
close() | nothing | No |
identify(identity) | nothing | No (queued until it loads) |
setIdentity(identity) | nothing | No (same as identify) |
setLocale(locale) | nothing | No (queued until it loads) |
reset() | nothing | Yes |
destroy() | nothing | No |
init(config)
Starts the widget with the options you pass. Use it with data-auto-init="false" on the script tag, or to switch projects in a single-page app.
await window.Axoryn.init({
projectKey: 'YOUR_WIDGET_KEY',
locale: 'pt-BR',
})
config.projectKeyis required. Without it,init()logs a warning and does nothing.init()shows the launcher and loads the full widget right away. The promise resolves once it has loaded. It never rejects: if loading fails, the launcher shows a retry state instead.- Calling
init()with the sameprojectKeymerges the new options into the current ones. - Calling
init()with a differentprojectKeytears down the current widget and starts the new project.
See init options for every field.
open(message?)
Opens the chat panel.
window.Axoryn.open()
window.Axoryn.open('I need help with my invoice')
| Parameter | Type | Description |
|---|---|---|
message | string, optional | Opens the conversation screen with this text already in the message box. It is not sent: the visitor reviews it and selects send. |
Without message, the panel opens on the screen the visitor last used.
openWithGreeting(greeting)
Opens the conversation screen with a greeting bubble from your team or AI, without filling in the message box.
window.Axoryn.openWithGreeting('Questions about the Pro plan? Ask away.')
| Parameter | Type | Description |
|---|---|---|
greeting | string | The greeting shown at the top of the conversation. It is saved with the visitor’s first message, so your team sees what the visitor saw. |
ask(question, greeting?)
Opens the panel and sends question as the visitor’s first message in a new conversation. If the visitor already has a conversation, it stays available in the Messages tab.
window.Axoryn.ask('How do I export my data?')
| Parameter | Type | Description |
|---|---|---|
question | string | Sent immediately as the visitor’s message. Blank strings are ignored. |
greeting | string, optional | A greeting bubble shown above the question and saved with the conversation. |
Warning:
ask()sends a real message on the visitor’s behalf. Call it only from an action the visitor took, such as selecting a Ask about this button.
close()
Closes the chat panel. The launcher stays on the page.
window.Axoryn.close()
identify(identity)
Tells Axoryn who the visitor is. setIdentity() is the same function.
window.Axoryn.identify({
user_id: '42',
email: 'jane@acme.com',
name: 'Jane Doe',
user_hash: '<computed on your server>',
})
| Field | Type | Description |
|---|---|---|
user_id | string or number | Your app’s stable user id. |
email | string | The user’s email address. |
name | string | The user’s name. |
phone | string | The user’s phone number. |
custom | object | Extra attributes shown to your team. Merged into the ones already stored. |
user_hash | string | Hex HMAC-SHA256 of user_id (or of email when no user_id is sent), signed on your server with the project’s secret key. |
If user_id differs from the last user identified on this browser, the widget first resets (as with reset()) and then identifies the new user. How verification works, and server code for computing user_hash, are in Identify your users.
setLocale(locale)
Sets the widget’s interface language and keeps it, overriding the visitor’s browser language and the project setting.
window.Axoryn.setLocale('es')
| Parameter | Type | Description |
|---|---|---|
locale | string | en, pt-BR or es. Any pt-… tag becomes pt-BR and any es-… tag becomes es. Other languages fall back to English. |
reset()
Forgets the visitor on this browser and starts a fresh, anonymous widget with the same settings. It clears the visitor credential, the current conversation pointer, unread and mute state, and the last identified user. Call it when a user logs out of your app.
window.Axoryn.reset()
The visitor’s past conversations stay in your inbox. They are no longer shown in this browser.
destroy()
Removes the widget from the page completely: the launcher, any open panel and any proactive teaser. Queued calls are dropped. Call init() to start it again.
window.Axoryn.destroy()
init options
| Option | Type | Default | Description |
|---|---|---|---|
projectKey | string | none (required) | Your project’s widget key. |
locale | string | automatic | Interface language: en, pt-BR or es. Overrides the visitor’s browser and the project setting. |
greeting | string | localized default | Greeting shown when the project has no greeting set in the dashboard. |
offsetX | number | 20 | Launcher distance in pixels from the side of the screen. The dashboard value wins when set. |
offsetY | number | 20 | Launcher distance in pixels from the bottom of the screen. The dashboard value wins when set. |
primaryColor | string | #6366f1 | Launcher color used only until the project’s settings load. Set the color in the dashboard. |
position | 'bottom-right' or 'bottom-left' | 'bottom-right' | Launcher side used only until the project’s settings load. Set the position in the dashboard. |
nonce | string | from the script tag | Content-Security-Policy nonce for the style fallback on older browsers. |
apiUrl | string | https://api.axoryn.io | The Axoryn API origin. Leave it unset unless your snippet in the dashboard includes data-api-url. |
How the language is chosen
The widget uses the first match in this order:
localefrominit(),data-locale, orsetLocale().- The visitor’s browser languages, in their order of preference.
- Your page’s
<html lang>. - The project’s default language from the dashboard.
- English.
Only en, pt-BR and es count as a match at each step.
Script tag attributes
The script tag reads these attributes when it loads. They mirror the init() options.
| Attribute | Example | Description |
|---|---|---|
data-project-key | "YOUR_WIDGET_KEY" | Required for auto-start. Without it, the widget waits for init(). |
data-auto-init | "false" | Set to false to stop the widget starting on its own. Any other value, or no attribute, starts it. |
data-locale | "pt-BR" | Same as the locale option. |
data-greeting | "Hi! How can we help?" | Same as the greeting option. |
data-offset-x | "32" | Same as offsetX. Whole pixels from 0 to 400; larger values are capped at 400. |
data-offset-y | "96" | Same as offsetY, with the same range. |
data-color | "#0f766e" | Same as primaryColor. |
data-position | "bottom-left" | Same as position. |
data-nonce | "RANDOM_NONCE" | Same as nonce. The standard nonce attribute is read too. |
data-api-url | "https://api.axoryn.io" | Same as apiUrl. |
Example with several attributes:
<script src="https://api.axoryn.io/widget.js"
data-project-key="YOUR_WIDGET_KEY"
data-locale="pt-BR"
data-offset-y="96"
async></script>
Note:
data-coloranddata-positiononly style the launcher shown while the widget loads. Once the project’s settings arrive, the color and position from the dashboard apply. Change them in Customize the widget instead.
Set the identity before load
Instead of calling identify(), a server-rendered page can define window.axorynIdentity before the script tag. It takes the same fields as identify() and is read when the full widget starts.
<script>
window.axorynIdentity = { user_id: '42', name: 'Jane Doe', user_hash: '<computed on your server>' }
</script>
Elements and storage
These details help when you debug layout or privacy questions:
| Item | Value |
|---|---|
| Launcher before the full widget loads | <div id="axoryn-loader-launcher">, attached to <html> |
| Proactive teaser card | <div id="axoryn-loader-teaser">, attached to <html> |
| Full widget | <div id="axoryn-support-widget"> with a shadow root |
| Stacking | The widget sits on top with a very high z-index (2147483000). |
| Small screens | Below 640px wide, the open panel fills the screen. |
| Browser storage | localStorage keys that start with axoryn_. No cookies. When storage is blocked (for example in some private windows or sandboxed iframes), the widget keeps its state in memory for the current page. |
Use reset() rather than clearing these keys yourself.
TypeScript declaration
There is no types package. If you call the API from TypeScript, add a declaration like this one, which matches the methods above:
interface AxorynIdentity {
user_id?: string | number
email?: string
name?: string
phone?: string
custom?: Record<string, unknown>
user_hash?: string
}
interface AxorynInitConfig {
projectKey: string
locale?: string
greeting?: string
offsetX?: number
offsetY?: number
primaryColor?: string
position?: 'bottom-right' | 'bottom-left'
nonce?: string
apiUrl?: string
}
interface AxorynApi {
init(config: AxorynInitConfig): Promise<void>
open(message?: string): void
openWithGreeting(greeting: string): void
ask(question: string, greeting?: string): void
close(): void
identify(identity: AxorynIdentity): void
setIdentity(identity: AxorynIdentity): void
setLocale(locale: string): void
reset(): void
destroy(): void
}
declare global {
interface Window {
Axoryn?: AxorynApi
axorynIdentity?: AxorynIdentity
}
}
export {}