Skip to navigation

Returns a Hono app that serves the gateway at /: POST / for the four browser methods (start, chat, log, end) and OPTIONS / for the CORS preflight. Mount it with agent.mount(gateway.router(), { prefix: '/chat' }), or with app.route() on any Hono app.

A chat reply is streamed through without buffering. The service pads slow turns with keepalive whitespace so proxies don’t close the connection, and collecting the body here would hold that padding back. A newly created handle is returned in the X-Chat-Handle response header, which is why it can be sent before the body.

CORS headers go to origins the gateway allows, and X-Chat-Handle is exposed to them. A request body over 64 KiB is answered with 413 and { error: 'request too large' } without being parsed. See ChatGateway for the methods, bodies, and status codes.

Parameters

None.

Returns

Hono — the app. hono is installed with @signalwire/sdk.

Examples

Mount the gateway on an agent, with the handoff routes at the same prefix:

import { AgentBase, ChatGateway, HandoffRouter } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'dispatch', route: '/dispatch' });
const gateway = new ChatGateway({
configUrl: 'https://bayview-taxi.example.com/dispatch',
key: '<YOUR_PUBLISHABLE_KEY>',
allowedOrigins: ['https://bayviewtaxi.example.com'],
});
agent.mount(gateway.router(), { prefix: '/chat' });
// Optional: let the widget move a conversation to a phone call and back.
const handoff = new HandoffRouter({ gateway });
agent.mount(handoff.router(), { prefix: '/chat' });
await agent.serve();

Mount it on a Hono app you already run:

import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { ChatGateway } from '@signalwire/sdk';
const gateway = new ChatGateway({
configUrl: 'https://bayview-taxi.example.com/dispatch',
key: '<YOUR_PUBLISHABLE_KEY>',
allowedOrigins: ['https://bayviewtaxi.example.com'],
});
const app = new Hono();
app.route('/chat', gateway.router());
serve({ fetch: app.fetch, port: 3000 });

To let the widget move a conversation to a phone call and back, mount a HandoffRouter at the same prefix.