window.replyful to your page. It works the same for every layout: floating bubble, side panel, full page and search bar.
Calling the API
There are two ways to call a command:Return values
Once the chat has loaded, every command returns a Promise. Before that, queued calls returnundefined, so don’t rely on a return value in code that may run early. To run code as soon as the chat is ready, listen for ready; it fires straight away if the chat is already ready:
Commands
The chat window loads on demand. With the chat bubble or side panel, that happens when the visitor first hovers over or opens the chat button.
identify and newConversation resolve once it has loaded, so call them early but don’t hold up your own page logic waiting for them.
In state(), available is false when the chat can’t run on this page (see the unavailable event), layout is floating, panel, page or search, and identified is true once identify has succeeded.
Events
Each callback receives one plaindetail object. An error thrown in your callback doesn’t affect the chat or other callbacks.
ready and unavailable are sticky: a callback added after they fired runs straight away.
reasononopenandcloseis what caused it:api(your code),launcher(the chat button),escape,backdrop,close-button, ornavigation(the visitor moved to a page where the chat is hidden).reasononunavailableisdomain-not-allowed(the page’s domain isn’t in the chatbot’s allowed domains),channel-unavailable(the chatbot is turned off or deleted) ornetwork.transferredis present when the visitor’s earlier anonymous chat moved to the signed-in user:{ conversations, messages }, as counts.- Message events carry no message text.
Examples
Open the chat from your own button
Single-page apps and React
Subscribe when your component mounts and remove the same callback when it unmounts.off also works on calls queued before the chat has loaded.
Your component can mount before the snippet has run, for example when Google Tag Manager adds the snippet later. If window.replyful doesn’t exist yet, wait for the replyful:load event on window before subscribing. The chat can’t fire events before then, so you won’t miss any. Don’t define window.replyful yourself: the snippet replaces it, and any calls you queued on it would be lost.