Skip to content
AnytimeReply

Website SDK

Chat bubble JavaScript API

Open and close the chat, identify signed-in users, show proactive messages and register website actions with window.AnytimeReply.

The chat bubble script adds a global window.AnytimeReply object.

HTML
<script src="https://anytimereply.com/widget.js" data-agent="YOUR_AGENT_KEY" defer></script>

Methods

MethodWhat it does
AnytimeReply.open()Opens the chat window
AnytimeReply.close()Closes it
AnytimeReply.toggle()Opens or closes it
AnytimeReply.identify(user)Tells the chat who is signed in — see below
AnytimeReply.showMessage(id)Shows a proactive message now, by its ID
AnytimeReply.onAction(name, handler)Registers a website action handler

The script loads with defer, so call these after the page has loaded — for example from a click handler:

HTML
<button onclick="AnytimeReply.open()">Chat with us</button>

window.AgentChat is an older alias of the same object and keeps working.

Settings before the script loads

Define window.AnytimeReplySettings before the script tag:

HTML
<script>
  window.AnytimeReplySettings = {
    // a signed-in customer (pick one form)
    user: { token: "JWT_FROM_YOUR_SERVER" },
    // or the older form: user: { email: "[email protected]", name: "Nadia", hash: "HMAC_FROM_YOUR_SERVER" },

    // website action handlers
    actions: {
      add_to_cart: async ({ product_id, quantity }) => ({ ok: true, cart_count: 3 }),
    },
  };
</script>
<script src="https://anytimereply.com/widget.js" data-agent="YOUR_AGENT_KEY" defer></script>

Identify signed-in users

JavaScript
// after your user signs in (single-page apps)
AnytimeReply.identify({ token: "JWT_FROM_YOUR_SERVER" });

identify() takes { token } or { email, name, hash }. Call it before the visitor first opens the chat on that page — the identity is sent when the chat window loads. How to create the token: Identity verification.

The older email form also works as script attributes: data-user-email, data-user-name and data-user-hash.

Website actions

JavaScript
AnytimeReply.onAction("apply_coupon", async ({ code }) => {
  const ok = await shop.applyCoupon(code);
  return ok ? { ok: true, total: shop.total() } : { ok: false, error: "Invalid code" };
});

The handler receives the inputs the agent collected and returns an object (or a promise). Returning nothing sends { ok: true }; a thrown error sends { ok: false, error }. It must answer within 15 seconds. See Website actions.

Behaviour notes

  • The chat window is 400 px wide on desktop and full screen on phones (under 520 px).
  • Auto-open and proactive messages never show again in a visit after the visitor has opened the chat.
  • The bubble only appears on allowed domains and not for blocked countries.
  • Messages between the page and the chat window are only accepted from the chat's own origin.
Was this page helpful?
Still stuck? Contact us