SDK
SDK Reference
💬Get free consultation

SDK Reference

Who can use this feature?

  • Available to all users on any plan.
  • New to the SDK? Start with the SDK overview.

The SDK is the global object window.$chatty. This page lists everything it exposes.


Methods

MethodReturnsDescription
push([verb, action, ...args])Run a command. Verbs: do, set, on, off.
on(event, callback)Subscribe to an event.
off(event, callback)Unsubscribe. Pass the same function reference used in on.
is(key)booleanSynchronously read a boolean state (see States).
get(key)valueSynchronously read a value (see Values).
versionstringSDK version, e.g. '1.0.0'.

on / off are also available as push verbs — push(['on', event, cb]) is equivalent to on(event, cb).


do actions

Run with push(['do', action, ...args]).

ActionArgumentsDescription
chat:openOpen the chatbox.
chat:closeClose the chatbox.
chat:showShow the widget launcher.
chat:hideHide the widget launcher.
message:send'text', contentSend a message as the visitor.
event:trackname, data?Track a custom event.
session:resetReset the current chat session.
window.$chatty.push(['do', 'message:send', 'text', 'Hello!'])
window.$chatty.push(['do', 'event:track', 'viewed_pricing', { plan: 'pro' }])

set actions

Run with push(['set', action, value]).

ActionValueDescription
message:textstringPrefill the input box (without sending).
user:emailstringSet the visitor's email.
user:contextobjectMerge custom data about the visitor.
shop:dataobjectMerge custom data about the shop/page context.
window.$chatty.push(['set', 'message:text', 'I need a refund'])
window.$chatty.push(['set', 'user:context', { vip: true, lifetimeOrders: 12 }])

Events

Subscribe with on(event, callback).

EventPayloadFires when…
sdk:readyThe SDK has loaded and is ready.
chat:openedThe chatbox opens.
chat:closedThe chatbox closes.
message:sent{ text, type }The visitor sends a message.
message:received{ text, isAdmin }A reply arrives (agent or AI).
window.$chatty.on('sdk:ready', () => {
  console.log('Chatty is ready')
})
 
window.$chatty.on('message:received', ({ text, isAdmin }) => {
  if (isAdmin) console.log('Reply:', text)
})

To remove a listener with off, keep a reference to the same function you passed to on. Anonymous inline functions can't be removed.


States

Read synchronously with is(key)boolean.

KeyTrue when…
chat:openedThe chatbox is open.
chat:closedThe chatbox is closed.
chat:visibleThe launcher is visible.
session:ongoingThere's an active chat session.
if (window.$chatty.is('chat:opened')) {
  window.$chatty.push(['do', 'chat:close'])
}

Values

Read synchronously with get(key).

KeyReturns
message:textCurrent text in the input box.
session:identifierThe current session ID.
chat:unread:countNumber of unread messages.
const unread = window.$chatty.get('chat:unread:count')

Limits

To keep the widget responsive and prevent abuse, the SDK enforces a few limits:

ActionLimit
message:sendUp to 15/min, at least 1 second apart, max 5,000 characters.
event:trackEvent name ≤ 200 chars; data ≤ 20 keys / 1,000 chars.
user:emailMust be a valid email, ≤ 254 chars.
user:context≤ 50 keys; each value ≤ 2,000 chars (string, number, or boolean).

All text inputs are sanitized — <script>, <iframe>, javascript: URLs, and inline on*= handlers are stripped.


Full example

<button id="help-btn">Need help?</button>
 
<script>
  window.$chatty = window.$chatty || [];
 
  // Identify the visitor
  window.$chatty.push(['set', 'user:email', '[email protected]'])
  window.$chatty.push(['set', 'user:context', { plan: 'vip' }])
 
  // Open chat from a custom button with a prefilled message
  document.getElementById('help-btn').addEventListener('click', () => {
    window.$chatty.push(['set', 'message:text', 'I have a question about my order'])
    window.$chatty.push(['do', 'chat:open'])
  })
 
  // Log replies
  window.$chatty.on('message:received', ({ text, isAdmin }) => {
    console.log(isAdmin ? 'Agent: ' : 'AI: ', text)
  })
</script>

Need help?

If a command isn't working, confirm the Chatty widget is installed and loading on the page (window.$chatty should be defined). Still stuck? Contact the Chatty support team from your dashboard.