Skip to content

Chat widget ​

The chat widget puts one of your agents inside your own web app: streamed answers, file uploads, voice notes, live voice calls and conversation history. It is one script tag; there is nothing to build on your backend.

What you need ​

  • An agent in the environment you embed.
  • Your customers' sign-in in that environment.
  • A widget key for that environment, an API key of kind widget:
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/api-keys" \
  -H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
  -H "Content-Type: application/json" \
  -d '{"name": "Website chat", "kind": "widget"}'

1. Allow your site ​

List each site the chat runs on, then prove it is yours:

bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/embed/origins" \
  -H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
  -H "Content-Type: application/json" -d '{"origin": "https://app.example.com"}'
  • An origin is a scheme, a host and an optional port: no path, no trailing slash, no wildcard. Plain http only for localhost.
  • The answer carries a DNS TXT record. Publish it, then call POST /v1/projects/{id}/embed/origins/{originID}/verify. The chat does not start on a site until it is verified. localhost and loopback addresses are verified at once.
  • Removing a site stops the widget there on the visitor's next page load.

2. Paste the code ​

GET /v1/projects/{id}/embed/install returns the exact snippet for the environment. It looks like this:

html
<div id="frege-chat" style="height: 520px"></div>
<script src="https://api.frege.io/v1/embed.js"></script>
<script>
  Frege.setApiKey('YOUR_WIDGET_KEY');
  Frege.mount({
    el: '#frege-chat',
    project: '<project id>',
    stage: 'live',
    agent: '<agent id>',
  });
</script>

The widget key sits in the page, where anyone can read it, and that is safe: it only starts the chat for a person who signed in through that browser, on your verified sites. Never put a secret key in a page.

The first time a visitor opens the chat, they are sent once through your sign-in and brought back; after that the widget remembers them in that browser.

Frege.mount options ​

OptionWhat it does
elThe element, or a selector for it. Required.
projectThe project's id. Required.
stagelive or staging.
agentThe agent's id. Required.
titleThe chat's title; the agent's name by default.
placeholderThe text in the empty message box.
theme'dark' for the dark theme.
accentYour accent colour, e.g. '#1fcf63'.
varsAny of the widget's CSS variables, e.g. { radius: '12px' } (written as --frege-radius).
onTurnA function called with each turn's result.

Frege.mount returns { reset, destroy, sessionId }: start a new conversation, remove the widget, or read the current conversation's id.

The environment's widget settings go further: PUT /v1/projects/{id}/widget-config (which features show: voice notes, calls), widget-theme (the brand) and widget-template (the widget's HTML). Voice notes and calls are off until turned on there, and calls need the environment's speech models.

What your customer can do ​

  • Chat with the agent, with answers streamed as they are written.
  • Attach files up to 8 MB; audio and video become their transcript.
  • Send voice notes, and start a live voice call.
  • Approve or decline writes when the write policy is ask ("always allow" lasts 30 days).
  • Reopen, delete or clear past conversations.

Content Security Policy ​

If your site sends a Content-Security-Policy, allow https://api.frege.io in script-src and connect-src. Live calls also load their library from cdn.jsdelivr.net and connect to the voice server over WebRTC; a page that blocks them still chats.

Limits ​

A customer can start two voice calls in a row and then one every 30 seconds, and transcribe five voice notes in a row and then one every five seconds.