Documentation Index
Fetch the complete documentation index at: https://docs.hacktionbase.com/llms.txt
Use this file to discover all available pages before exploring further.
Hacktionbase.onTrigger(handler)
Hacktionbase.onTrigger(key, handler)
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
Optional. Scope the handler to a single trigger key. Omit to receive every executed trigger.
handler
(event: TriggerEvent) => void
required
Called once per matched execution. The event payload is described below.
Event shape
interface TriggerEvent {
id: string; // Trigger document ID
key: string; // Stable trigger key (e.g. "create_project")
data: Record<string, any>; // Fields extracted from the user message
executionEventId: string; // Unique ID for this execution (dedupe)
userId: string | null; // Set if the user is identified
anonymousId: string | null; // Set for anonymous sessions
occurredAt: string; // ISO timestamp
}
Examples
Listen for a single trigger
const unsubscribe = Hacktionbase.onTrigger('open_billing', (event) => {
window.location.href = '/billing';
});
// Later, when you no longer need the handler
unsubscribe();
Hacktionbase.onTrigger('create_project', (event) => {
const { name, plan } = event.data;
document.querySelector('#project-name').value = name ?? '';
document.querySelector('#project-plan').value = plan ?? 'starter';
Hacktionbase.close();
});
Catch every trigger (e.g. for analytics)
Hacktionbase.onTrigger((event) => {
analytics.track('chat_trigger_fired', {
key: event.key,
executionEventId: event.executionEventId
});
});
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).