Skip to main content
The widget supports bidirectional communication between the parent page and the embedded chat iframe using the postMessage API. This enables rich integrations where the parent application can send context to the widget and receive events back.

Overview

Features

  • Metadata Injection: Parent page can send arbitrary metadata to the widget
  • Event Notification: Widget notifies parent of user actions and state changes
  • Mobile State Detection: Automatic detection and handling of mobile/desktop states
  • Widget Mode Detection: Automatic detection when running in iframe vs standalone mode
  • Secure Communication: Origin validation for all messages

Parent to Widget Communication

Window Configuration

When embedding the widget, configure it through the window.AGO object before loading the widget script. These options control authentication, appearance, and behavior.

Panel size

The chat panel is 550px wide by default. Set panelWidth to change it:
Percentages resolve against the viewport, not against any element on your page, because the panel is positioned fixed. panelWidth: "50%" on a 1400px screen is 700px. An invalid value is ignored, the panel stays at 550px, and the reason is logged to the browser console:

Setting the width from CSS instead

The same value is exposed as a CSS custom property, which lets you vary it with media queries. Set it on #ago-chatbot and it wins over panelWidth — no !important needed:
Precedence: #ago-chatbot always wins because a value declared on the panel itself takes priority over one it inherits from the page root, which is where panelWidth writes. Setting it on #ago-chatbot is the recommended form: it behaves the same either way, so there is nothing to remember.
Chat content is capped at 768px wide, so a panel wider than that shows empty margins on either side of the conversation.

Updating JWT at Runtime

Use sendJwtToAGO() to update the JWT token after the widget has loaded. This is useful when the user logs in after the widget is already open, or when the JWT token is refreshed.
This updates the JWT in both the chat iframe and the notification iframe, so unread counts are fetched with the correct identity.

Updating Auth Token at Runtime

Use sendAuthTokenToAGO() to pass an external authentication token to the widget. This token is forwarded to agent tools (e.g., HTTP request tool) as the X-Auth-Token header, allowing agents to call your authenticated APIs on behalf of the user.

Sending Metadata

Use the sendMetadataToAGO function to pass context from your application to the widget.

Metadata Fields Reference

Letting the agent use the metadata to answer

By default the metadata is only used for support tickets: it is mapped to labels in Settings → Integrations → Widget & SDK → Metadata Fields Mapping, and appears in the ticket’s private comment and prefilled fields. The AI agent does not see it. Turn on Send metadata to the agent on the same page to also include the metadata in the agent’s prompt. The agent can then answer using it — for example, replying about the right subscription tier without asking the visitor which plan they are on:
Good to know:
  • The whole metadata object is sent with every message, so the agent always sees the latest values — reassign it when your app’s state changes.
  • The metadata comes from the page embedding the widget, which means a visitor can edit it in their browser. Treat it as information, never as proof: use permissions or a JWT for anything that grants access.
  • Keep the payload small (under 10 KB). A larger one is dropped rather than sent to the agent.
  • For data the visitor must not be able to change, use an API Data Source instead: AGO fetches it from your API server-side and adds it to the same conversation.

Usage in React Native WebView


Widget to Parent Communication

Setting Up the Event Listener

The parent page should listen for messages from the widget:

Built-in Message Types

CLOSE_CHAT

Sent when the user clicks the close button or requests to minimize the widget.
Use Case: Hide the widget container or minimize to a button.

THREAD_CREATED

Sent when a new conversation thread is started.
Use Case: Track conversation starts in your analytics.

TICKET_CREATED

Sent when a support ticket is created from the conversation.
Use Case: Show confirmation or update your ticket tracking.
Sent when the widget requests navigation to a specific page.
Use Case: Handle in-app navigation from agent responses.

UNREAD_STAFF_COUNT

Sent periodically (every 30 seconds) by the notification frame to inform the parent page of unread staff messages. The notification frame is a hidden iframe that polls for unread messages. It only reports counts for users who have an existing widget session (i.e., a widget ID in localStorage from a previous chat interaction) — new visitors with no prior conversations will not trigger any polls. Enabling notifications: Set notifications: true in the window.AGO configuration object:
When enabled, the standard widget automatically displays a red badge on the chat button. If you build a custom integration, listen for the event yourself:
Use Case: Display an unread message badge on your chat button.
JWT authentication: If your widget uses JWT authentication, call sendJwtToAGO(token) whenever the token is refreshed. This updates both the chat iframe and the notification frame so that unread counts are fetched with the correct identity.

Complete Integration Examples

Basic Web Integration

React Integration


Ticket Integration

When tickets are created from conversations, metadata is automatically included and formatted for support agents.

HelpScout Integration

Metadata appears as formatted JSON in private comments:

Zendesk Integration

Metadata is added to custom ticket fields and internal notes, providing support agents with comprehensive context.

Security Considerations

Origin Validation

Always validate the message origin:

Sensitive Data

  • Do not send: Passwords, API keys, tokens, credit card numbers
  • Safe to send: User IDs, order IDs, plan names, page context, preferences

Content Security Policy

If using CSP, ensure your policy allows communication with the widget:

Troubleshooting

  1. Ensure the widget script has finished loading before calling sendMetadataToAGO
  2. Check browser console for errors
  3. Verify sendMetadataToAGO is available globally (it is defined by frame.js)
  1. Check origin validation in your event listener
  2. Ensure widget domain is correct
  3. Check browser console for blocked cross-origin messages
  1. Verify metadata was sent before ticket creation
  2. Check that metadata format is valid JSON
  3. Ensure ticketing integration is properly configured

Browser Compatibility

The postMessage API is supported in all modern browsers: No polyfills required.