Skip to main content

Bot Actions

Overview

An item of a Choice step in your bot can carry one or more actions. When a visitor clicks such an item, the Smart Bot emits a browser event for each action attached to it. Your own JavaScript on the page listens to these events and runs whatever you need — for example open a third-party livechat, close the bot, or forward data to another tool.

This keeps the integration generic: nothing Smart Tribune-specific lives on your side beyond the event listeners, and the actions (their names and parameters) are configured on the bot, not hard-coded on your page.

The action event

For each action, the widget calls window.dispatchEvent with a CustomEvent:

  • Event name: STSmartBotAction:<action_name>, where <action_name> is the name of the action configured on the bot (for example launch_salesforce_livechat). There is one event per action, named after it — you listen only to the action names your bot emits.
  • Event detail: an object { name, parameters }.
FieldTypeDescription
detail.namestringThe action name (same value as the <action_name> suffix of the event).
detail.parametersobjectThe action parameters, already parsed from JSON. You receive a plain object, never a raw string.
info

The action parameters are provided as a ready-to-use object. If an action was configured with invalid JSON parameters, the action is skipped and no event is emitted — your listeners never receive malformed data.

caution

Actions are transient: they are not stored in the conversation history and are never re-emitted when the bot is reloaded. An action therefore fires at most once, on the click that triggered it.

Listening to an action

Add the listener alongside your Smart Bot integration snippet (see Getting started). A minimal listener:

<script type="text/javascript">
window.addEventListener('STSmartBotAction:launch_salesforce_livechat', function (e) {
var name = e.detail.name;
var parameters = e.detail.parameters;
console.log('Bot action received:', name, parameters);
});
</script>

Full example: launch_salesforce_livechat

This example listens to a launch_salesforce_livechat action, maps its parameters to a third-party livechat tool, then closes the Smart Bot box.

<script type="text/javascript">
window.addEventListener('STSmartBotAction:launch_salesforce_livechat', function (e) {
var params = e.detail.parameters; // e.g. { org, queue, conversation_id, history }

// 1. Map the Smart Tribune payload to your third-party tool.
startSalesforceLiveChat({
organizationId: params.org,
queue: params.queue,
conversationId: params.conversation_id,
transcript: params.history,
});

// 2. Close the Smart Bot box now that the conversation moves to the livechat.
window._ST.SmartBot.hide();
});
</script>

A few things to note:

  • window._ST.SmartBot is the Smart Bot API registered globally once the widget has loaded. It exposes the same methods you use elsewhere (show(), hide(), …). See Getting started for the full list.
  • The parameters you receive are whatever was configured for that action on the bot; the example fields above (org, queue, conversation_id, history) are illustrative — read the values your own action provides.
  • You can attach several listeners, one per action name your bot emits (for example a close_bot action that simply calls window._ST.SmartBot.hide()).