RelayDocs

Support widget

Widget JavaScript API

Once widget.js has loaded, a global window.Relay function lets your app control the widget. Calls made before the widget is ready are queued and run as soon as it is.

Commands#

CallWhat it does
Relay("open")Opens the widget panel.
Relay("close")Closes the panel back to the launcher.
Relay("identify", { userId, name, email, meta })Attaches identity to the current visitor. Use after sign-in.

Open from your own button#

For example, a “Help” item in your app’s menu:

html
<button onclick="window.Relay && window.Relay('open')">Help &amp; support</button>

Identify after login#

js
async function onLogin() {
  const user = await api.me();
  window.Relay?.("identify", {
    userId: user.id,
    name: user.name,
    email: user.email,
    meta: { plan: user.plan }
  });
}

TypeScript#

Add a declaration so the global is typed in your project:

relay.d.ts
type RelayIdentity = { userId?: string; name?: string; email?: string; meta?: Record<string, string> };

declare global {
  interface Window {
    RelaySettings?: RelayIdentity;
    Relay?: {
      (command: "open" | "close"): void;
      (command: "identify", identity: RelayIdentity): void;
    };
  }
}
export {};