Embed real-time text conversations into your application using WebSockets, with seamless handoff to live agents.
The Messaging API lets you embed real-time text conversations into your application. End users chat with a PolyAI agent, and the conversation can be handed off to a live human agent inside the same session when needed.Communication happens over a WebSocket connection after a short HTTP handshake. All messages are JSON-encoded events.
The Messaging API is a real-time, event-driven protocol. If you only need simple turn-based request/response (for example for SMS), use the Chat API instead. See Messaging API vs Chat API below.
Provisioned by PolyAI — contact your PolyAI representative to request one
Host identifier
The domain (e.g. https://www.yourcompany.com) or app namespace (e.g. com.yourcompany.app) registered against the connector token
Set when the token is provisioned. The server rejects requests where X-Host doesn’t match.
The self-serve Messaging → API Configuration page in Agent Studio is not fully built out yet. For now, your PolyAI representative will provision a connector token and register the host identifier on your behalf.
If you already have a PolyAI webchat widget configured, you can reuse its credentials:
Connector token: the value between the last / and .js in the widget embed script URL.
Host identifier: the same domain you set in the widget configuration.
Subdomains are matched against the registered host — for example, a connector registered to yourcompany.com accepts requests from app.yourcompany.com.
Send EVENT_TYPE_REQUEST_POLY_AGENT_JOIN to start the conversation.
5
Exchange messages
Send and receive events over the WebSocket.
The PolyAI agent does not join the session automatically. On a new session, after opening the WebSocket and receiving the session history, your client must explicitly send EVENT_TYPE_REQUEST_POLY_AGENT_JOIN to start the conversation. On a reconnect to an existing session, the agent has already joined — check the replayed history for EVENT_TYPE_POLY_AGENT_JOINED and skip the join request if present.