Skip to main content
Subscribes to chat trigger events forwarded from the widget. Whenever a trigger is executed (the user clicked the CTA proposed by the chatbot), the handler runs in your host page with the extracted data. Returns an unsubscribe function. Call it to remove the listener.

Parameters

string
Optional. Scope the handler to a single trigger key. Omit to receive every executed trigger.
(event: TriggerEvent) => void
required
Called once per matched execution. The event payload is described below.

Event shape

The session is always identified by anonymousId. When the user has been identified via Hacktionbase.identify(), userId is also set; otherwise it is null. To distinguish an identified vs. anonymous session, check whether userId is non-null.

Examples

Listen for a single trigger

Prefill a form from extracted data

Catch every trigger (e.g. for analytics)

Security

  • Trigger events are scoped to the current session. Your handler will never receive an event from another user.
  • The same executionEventId is delivered to your backend webhook — use it to correlate the two, or to deduplicate retries.
  • For sensitive actions, prefer running the side effect in your backend webhook (where you can verify the HMAC signature) and use onTrigger only for UI side effects (redirect, prefill, toast).