JavaScript API
The widget exposes a global window.MailAgent object with methods to open, control, and close the widget programmatically.
MailAgent.open(options)
Opens the widget and returns a handle for interacting with it.
const widget = await MailAgent.open({
bottom: "20px",
right: "20px",
width: "400px",
height: "600px"
});Returns: Promise<WidgetHandle>
See Configuration for all available options.
Widget Handle
The object returned by MailAgent.open() provides the following interface:
widget.send(message)
Send a message to the chat programmatically. This triggers the AI assistant to respond as if the user typed the message.
// Send a text message
widget.send({ text: "Draft a follow-up email to the client" });widget.mounted
A read-only boolean indicating whether the widget iframe is still attached to the DOM.
widget.unmount()
Closes and removes the widget from the page with a fade-out animation.
Full Example
Events
The widget communicates with the parent page via postMessage. You can listen for these events if you need deeper integration:
init
Parent ← Widget
Widget requests initialization data.
init
Parent → Widget
Parent sends config (userId, etc.).
initialized
Parent ← Widget
Widget is fully loaded and ready.
__widget_resize__
Parent ← Widget
Widget reports its content dimensions.
close
Parent ← Widget
Widget requests to be closed.
send
Parent → Widget
Parent sends a message to the chat.
Note: You typically don't need to handle these events directly — the
MailAgent.open()API manages them for you. These are documented for advanced use cases only.
Last updated