Skip to content

Web chat

Put a chat with your agents on your site, or share a hosted chat page.

Updated

The web chat lets a visitor of your site talk to the agents of a front door. The visitor needs no account and no token. A Cloudflare Turnstile check keeps bots out. The chat streams the replies as the agent writes them.

Set up

  1. Add channels.web to a door, with the origins of the pages that show the chat. Push.

    name: Acme support
    entry: support/desk
    channels:
      web:
        origins: [https://www.acme.com]
        greeting: Hello. How can we help?
  2. Create an embed key. You need the admin role. Open the door in the console and select Embed, or:

    rakerun embed create --door support/support --label Website

    The answer shows the key (rek_...) and the snippets.

  3. Add the snippet to your page.

Add the chat to a page

Script tag

<script src="https://acme.cloudraker.run/_chat/assets/run-embed.js" defer></script>

<cloudraker-chat
  base-url="https://acme.cloudraker.run"
  embed-key="rek_ABCDEFGHJKMNPQRSTVWXYZ23"
></cloudraker-chat>

The script path /_chat/assets/run-embed.js on your org host stays the same when the platform updates. It always serves the current version of the chat.

The element dispatches the event cloudraker-chat:item for each output item.

React

npm install @cloudraker/run-embed
import { RunChat } from '@cloudraker/run-embed/react'

export function Support() {
  return <RunChat baseUrl="https://acme.cloudraker.run" embedKey="rek_ABCDEFGHJKMNPQRSTVWXYZ23" lang="fr" />
}

JavaScript

import { mountChat } from '@cloudraker/run-embed'

const chat = mountChat(document.getElementById('chat')!, {
  baseUrl: 'https://acme.cloudraker.run',
  embedKey: 'rek_ABCDEFGHJKMNPQRSTVWXYZ23',
  lang: 'en',
  variables: { simple: true },
  onItem: (item) => {
    if (item.type === 'event' && item.name === 'booking_confirmed') showBooking(item.data)
  },
})

chat.setVariable('simple', false)
chat.end()
Option Type Rule
baseUrl string Required. https://{org}.cloudraker.run.
embedKey string Required. The rek_ key.
lang string Must be in the door languages.
variables object Session values. Each one must be a variable of the door, with a value of its type.
theme object Theme tokens. They merge over the door theme, with the same rules.
onItem function Gets each output item. event items come only here.
storage Storage or null Where the session token stays. Default sessionStorage. null keeps it in memory.

The handle has send(text), setVariable(name, value), end() and destroy().

The package has no runtime dependency. It is MIT licensed.

Embed keys

An embed key is public. It is safe in your page source. It binds one door, and it starts conversations only from the origins of that door.

  • A door can have many keys, for example one per site. Each key has an optional label.
  • rakerun embed list --door support/support lists the keys.
  • rakerun embed revoke rek_... revokes a key. Its open conversations end with reason channel, and their session tokens stop at once.
  • The key format is rek_ and 24 characters.

Hosted page

A key with hosted: true turns on a full page chat at https://{org}.cloudraker.run/_chat/{repo}/{name}. Share the link, or put it in an iframe of a page in the door origins.

rakerun embed create --door support/support --hosted --label "Hosted page"

A door has at most one hosted key. The page title is the door name. Its language is the first door language. Without a hosted key, the URL answers 404.

Use the hosted page on the org host {org}.cloudraker.run. On a custom hostname of the org, the security check refuses the page.

Origins

channels.web.origins lists the pages that can start a chat:

  • https://www.acme.com: one host. A port is allowed: https://localhost:5173.
  • https://*.acme.com: every subdomain of acme.com.

An origin has no path. A wildcard on a shared host suffix fails lint, for example *.vercel.app or *.github.io. Anyone can get a subdomain there. Read the list in the doors.yml reference.

The gateway checks the Origin header on every request. A page that is not in the list gets no CORS answer, and the session token of a conversation works only from its start origin.

Start a conversation

The chat does these steps for you:

  1. GET /_cv/door/{embed_key} reads the public door config: the name, the languages, the variables, the theme, the gate, the greeting and the file setting. Guards, agents and limits never leave the server.
  2. When the door has a gate, the visitor reads it and accepts.
  3. A hidden iframe loads GET /_cv/challenge/{embed_key}?origin={page origin}. It runs the Turnstile check and posts the token to your page only.
  4. POST /_cv/start/{embed_key} sends the token. The gateway checks it with Cloudflare. It answers the conversation id and a session token.
  5. The chat gets a one-time socket ticket and opens the WebSocket. It gets a new ticket for each reconnect. After 3 failed tries, it uses HTTP and SSE.

Read Conversations for the routes and the protocol.

Start error Cause
403 turnstile_failed The Turnstile check failed.
403 origin_forbidden The page origin is not in channels.web.origins.
404 embed_key_invalid The key does not exist or is revoked.
404 door_not_found The door of the key is not live, or has no channels.web.
429 rate_limited Too many starts from this IP address.
429 at_capacity A door limit is reached. The body has the door message.
503 door_unavailable The kill switch is on. The body has the door message.
503 turnstile_unavailable The check service is not available. Try again later.

Look and feel

channels.web.theme sets the colors, the corner radius and the font:

channels:
  web:
    origins: [https://www.acme.com]
    theme:
      background: '#ffffff'
      foreground: '#111113'
      accent: '#5361c1'
      accent_foreground: '#ffffff'
      muted: '#f2f2f2'
      border: '#d9d9dd'
      radius: 12px
      font: system

Colors are hex values. radius is 0 to 32px, or 0 to 2rem. font is system, serif or mono. The chat renders in a shadow root, so your page styles do not change it. It sets the CSS variables --run-*.

Gate

A gate shows a notice before the first message. The visitor must accept it. Use it for a disclaimer or a consent text.

channels:
  web:
    origins: [https://www.acme.com]
    gate:
      title: Before you start
      body: |
        This chat is an automated assistant. It can make mistakes.
        **Do not send personal health details.**
      accept: I understand
      links:
        - { label: Privacy policy, url: https://www.acme.com/privacy }

Greeting

channels.web.greeting shows a first message before the visitor writes. It is not a model call and costs nothing.

Files

Set channels.web.files: true to show the upload control. Each file is at most 5 MB over HTTP and 768 KB over the WebSocket, and 25 MB per conversation. A door with guards.input also needs guards.files: allow, because the checks do not read files.

Custom events

channels.web.events lists the custom events (event.{name}) that your page gets as event items. The chat does not show them. Read them in onItem, or in the cloudraker-chat:item event. Other custom events never reach the browser.

What the chat shows

Item In the chat
message Markdown: paragraphs, emphasis, code, lists, links, headings and tables. Links open in a new tab, HTTPS only. Images never load. Raw HTML never renders.
question One button per choice. A select above 10 choices.
activity One line per tool call, for example “Searching knowledge”.
ui A known component, else its fallback text.
file A download link.
handoff, language A short notice.
blocked The door message, next to the refused text.
ended The end message. The composer goes away.

The composer is off from send until the agent answers, so one message is in flight at a time.

Accessibility

The chat targets WCAG 2.2 AA:

  • The transcript is a role="log" region. Screen readers announce finished messages, not each streamed piece.
  • The input has a label. Keyboard focus shows a visible ring. The focus order is the composer, then the choices.
  • The gate is a modal dialog that holds the focus until the visitor accepts. Nothing else traps the focus.
  • Targets are at least 24 pixels. The default theme has a contrast of at least 4.5:1.
  • The chat honors prefers-reduced-motion.

When you set a theme, check the contrast of your colors.

Privacy

  • A visitor is anonymous. Each conversation gets its own metadata.end_user, so two visitors never share Structured Memory records.
  • Rate limits use the IP address. The platform stores only a keyed hash of it.
  • A message that an input check refuses is never kept.
  • The door session.retention deletes the conversation and its runs after the end.
  • Logs and traces never hold the text of a message or a session token. The socket request carries a one-time ticket, never the session token. The platform request log keeps the socket URL with its ticket, but the server spends the ticket before it checks the request, so a logged ticket cannot open a socket.

Type to search…

↑↓ navigate↵ selectEsc close