Documentation

JavaScript API

Control the widget from your own code: open, close, send messages, and listen for events via window.EmbedMyBot.

Once the script has loaded, a global window.EmbedMyBot object is available. Calls made before the widget finishes loading are queued and run once it's ready.

Methods

MethodDescription
EmbedMyBot.open()Open the chat window.
EmbedMyBot.close()Close the chat window.
EmbedMyBot.toggle()Toggle the chat window open/closed.
EmbedMyBot.sendMessage(text)Open the chat and send a message as the visitor.
EmbedMyBot.on(event, callback)Subscribe to an event (see below).
EmbedMyBot.off(event, callback)Remove a previously added event listener.
open(), toggle(), and sendMessage() will also wake a lazy-loaded widget (data-lazy) on demand — so you can keep the widget deferred and still open it from your own button.

Events

  • ready — the widget has loaded and is ready.
  • open — the chat window was opened.
  • close — the chat window was closed.
  • message — a message was sent or received (payload includes the role).

Examples

Open the chat from your own button

html
<button id="help">Chat with us</button>
<script>
  document.getElementById("help").addEventListener("click", function () {
    window.EmbedMyBot.open();
  });
</script>

Send a message programmatically

js
window.EmbedMyBot.sendMessage("I need help with my order");

React to events

js
window.EmbedMyBot.on("ready", function () {
  console.log("Chatbot ready");
});

window.EmbedMyBot.on("open", function () {
  // e.g. fire your own analytics event
});
The widget also auto-forwards events to Google Analytics / GTM if present — see Analytics.