Chat Widget
There is no packaged, npm install chat widget (an embed script or web component like <vai-avatar> is for voice and avatar). What exists is a complete, working reference implementation you can read and adapt.
Try it: play.wetel.dev/tools/chat-widget/ is a running chat UI wired to a live agent, not a mockup. It is one HTML file with no build step and no framework; most integrators copy it and restyle the markup rather than writing the mutation and subscription wiring from scratch.
What the file does
Section titled “What the file does”The widget runs the SDK flow of the Core API Flow from the browser:
- Configure. A panel takes the GraphQL HTTP and WebSocket endpoints, an API key and a numeric agent id.
?agentId=and?apiKey=in the page URL pre-fill the fields. - Start.
sdkStart(input: { agentId })with theX-Api-Keyheader returnssessionIdandavatarToken. Every later call sendsAuthorization: Bearer <avatarToken>instead of the key. - Listen. It opens one WebSocket with the
graphql-transport-wsprotocol, passingx-huat-platform: customerand theAuthorizationheader inconnectionParams, and subscribes tosessionEvents(sessionId). The subscription selects each event type it renders by name (AiResponseEvent,NodeExecutingEvent,NodeFailedEvent,SessionWillEndEvent,SessionEndedEvent), because a union member that is not selected never arrives. See Events & Subscriptions. - Send. Each user turn is
sdkSendMessage(input: { sessionId, text }). The reply arrives on the subscription, not in the mutation’s response;NodeExecutingEvents show as small progress chips while the workflow runs, and the bubble is finished when anAiResponseEventhasisFinal: true. - End. On
SessionEndedEventthe input is disabled and the stored session is cleared.
Resuming on the same device
Section titled “Resuming on the same device”The widget stores sessionId and avatarToken in localStorage under one key per agent id, so a reload continues the same session. A resumed chat starts with an empty window: the query that returns a session’s message history needs a dashboard login, which a browser holding only an avatarToken does not have. If the stored session has expired, the widget starts a fresh one.
Before you ship it
Section titled “Before you ship it”The demo calls sdkStart from the browser with the API key typed into the page. In production, your server calls sdkStart and hands only sessionId and avatarToken to the browser; the API key never reaches client code. See Authentication.
See also: Live Demos for every running example on this site, Getting Started, Agents.