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#
Open from your own button#
For example, a “Help” item in your app’s menu:
html
<button onclick="window.Relay && window.Relay('open')">Help & 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 {};