Skip to content

Web component

The widget is a custom element with tag name <chatbot-widget>. The bundled script (/chatbot/widget.js) registers it on load. Both the tag name and the attribute/method surface listed here are part of the public contract.

Mounting

The @chatbot Blade directive emits:

html
<script type="module" src="/chatbot/widget.js"></script>
<chatbot-widget channel="default" signed-context="..."></chatbot-widget>

You can mount manually for advanced cases:

html
<chatbot-widget
    channel="support"
    position="bottom-left"
    title="Need help?"
    signed-context="{{ $signedContext }}"
></chatbot-widget>

signed-context must come from Chatbot::renderWidget() (or equivalent server-side mint). Do not hand-craft it.

Attributes

AttributeTypeDefaultDescription
channelstringdefaultThe channel name. Used for theming ([channel="..."] selectors) and for the server's envelope verification.
positionbottom-right | bottom-left | inlinebottom-rightWhere the launcher sits. inline removes the floating positioning.
titlestring(localised default)Title shown in the panel header.
signed-contextstringThe signed envelope from the server. Required.

Methods

Call these on the element after it's in the DOM.

registerClientExtractor(name, fn, options)

Register a client extractor that runs at user-message send-time.

ts
chatbotWidget.registerClientExtractor(
  name: string,
  fn: () => string | Promise<string>,
  options?: { description?: string },
): void
ParameterTypeDescription
namestringMust match a name in the channel's signed allowed_extractors allowlist.
fn() => string | Promise<string>The extractor body. Returns the string to forward ('' to skip this turn). May be async; awaited up to extractor_timeout_ms.
options.descriptionstringHuman-readable description shown in the transparency chip (e.g., "Read from page: Checkout form fields").

Calling registerClientExtractor with a name not in the envelope's allowlist throws synchronously — fail-loud at boot rather than failing silently at send time.

CSS API

See Theming for the full custom-property and CSS-part reference.

Events

The widget does not currently dispatch custom DOM events on the host page. If you need observability, listen to the SSE response yourself (see SSE events) or subscribe to the PHP events fired server-side (Events reference).

Released under the MIT License.