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 messagewidget.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:
Event Type
Direction
Description
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.