Skip to main content

Smart Bot Snippet

Integration

The installation of the Smart Bot solution on the customer's site is done by integrating a snippet of javascript code within the desired page.

JS

The JavaScript snippet must be inserted immediately before the closing </body> tag. This is essential: the Smart Tribune script must be loaded as late as possible in the script loading chain to avoid any conflicts with third-party scripts present on the client page.

The client shall be solely responsible for any deviation from this instruction. Smart Tribune cannot be held liable for malfunctions, script conflicts or performance issues resulting from non-compliant integration.

<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
e.detail.init({
kbId: 0,
locale: 'en',
cookieOptin: false,
relativeRestPath: 'xxx',
});
});
</script>
<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/bot.main.js"
></script>

The integration of the code snippet above is sufficient to allow the partial display of the BOT within the page. You must also communicate your domain name to your Smart Tribune contact point so that we allow the product to be displayed completely on your environment.

Please note, the link to bot.main.js is a demonstration of the product, the smart-tribune folder in the url will be replaced by the one that will be communicated to you. The url changes completely during the transition from pre-production (public) to production. The complete url is communicated by your Smart Tribune contact point in charge of your account.

info

The domains calling on the specified knowledge base must be declared beforehand directly in the knowledge base configuration in Smart Dashboard by your Account Manager.

Validation environment

caution

This url differs depending on the environment on which the solution is to be installed at the customer site. It is customary to use PUBLIC for pre-production and to use PRODUCTION for production at the customer site. All this information is communicated by Smart Tribune after the development phase.

PRODUCTION script

<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/bot.main.js"
></script>

PRE-PRODUCTION script

<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/public/bot.main.js"
></script>

Variables list

VariableTypeConditionExampleDescription
kbIdintrequiredkbId : 0Variable specific to each customer, it corresponds to the identifier (system identifier) of the knowledge base to be used. This is available in Smart Dashboard, the content administration interface. You can find your kbId on the Dashboard home page in the "Select a knowledge base" then "system identifier" box.
localestringrequiredlocale : "en"It allows the customer to specify in which language the solution should be displayed. This only applies to multilingual knowledge bases.
relativeRestPathstringrequiredrelativeRestPath: "path/xx/..."This configuration variable allows you to specify the path to connect the bot. It will be given by the Account Manager in charge of your project.
cookieOptinbooloptionalcookieOptin : falseIt allows you to prevent or not the activation of the analytics cookie (possible value: true or false). By disabling this functionality, it will no longer be possible to send information in the analytics provider for your FAQ. The default value is false.
filtersobjectoptionalfilters: { tags: ["tag-1"] }Restricts the content the bot is allowed to serve. See Filtering the content below.
extraobjectoptionalextra: { myGroup: { plan: "premium" } }Additional context forwarded to the dialogue, so the bot can branch on data known by your page. It must be an object of objects whose leaf values are strings, numbers or booleans.
caution

kbId, locale and relativeRestPath are required. Every parameter is validated when init() is called: a missing required parameter or a wrong type throws an error prefixed with [Initialization Validator] in the browser console, and the Smart Bot is not displayed. Note that kbId is a number, not a string.

Filtering the content

The optional filters parameter restricts the questions and answers the bot may use, in the same way as the Smart FAQ contextualization.

PropertyTypeDescription
thematicsstring[]Only serve content associated with these categories.
tagsstring[]Only serve content associated with all of these tags (AND operator).
tagsOrstring[]Only serve content associated with at least one of these tags (OR operator).
<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
e.detail.init({
kbId: 0,
locale: 'en',
cookieOptin: false,
relativeRestPath: 'xxx',
filters: {
thematics: ['category-1'],
tags: ['tag-1', 'tag-2'],
},
});
});
</script>
caution

tags and tagsOr cannot be used at the same time: passing values in both throws an error and the Smart Bot is not displayed. Empty arrays are simply ignored.

The optional functions

Use the show() function

The show() function will allow you to open the box.

From a...Description
buttonJust call the show() function on your button.
<button onclick="window.stBot.show()">Btn</button>
From a...Description
timerPlace a setTimeout in a <script> tag after initializing Smart Bot.
<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
var stBot = e.detail;
stBot.init({
kbId: 0,
locale: 'en',
cookieOptin: false,
relativeRestPath: 'xxx',
});
setTimeout(() => {
stBot.show();
}, 3000);
});
</script>
<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/bot.main.js"
></script>
From a...Description
scrollPlace a headset after initializing Smart Bot.
<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
var stBot = e.detail;
stBot.init({
kbId: 0,
locale: 'en',
cookieOptin: false,
relativeRestPath: 'xxx',
});
window.addEventListener(
'scroll',
function (e) {
stBot.show();
},
false,
);
});
</script>
<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/bot.main.js"
></script>

If you need to use these functions outside the script (on a button by example), you will need to store stBot inside window which is a global variable :

<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
window.stBot = e.detail;
window.stBot.init({
kbId: 0,
locale: 'en',
cookieOptin: false,
relativeRestPath: 'xxx',
});
});
</script>
<script
type="text/javascript"
async
src="https://assets.app.smart-tribune.com/smart-tribune/BOT/bot.main.js"
></script>

Use the hide() function

The hide() function will allow you to close the box.

From a...Description
buttonJust call the hide() function on your button.
<button onclick="window.stBot.hide()">Btn</button>

Use the off() function

The off() function will allow you to make the box disappear from the page.

From a...Description
buttonJust call the off() function on your button.
<button onclick="window.stBot.off()">Btn</button>

Use the on() function

The on() function will allow you to make the box appear on the page.

From a...Description
boutonJust call the on() function on your button.
<button onclick="window.stBot.on()">Btn</button>

Use the send() function

The send() function will allow you to send a message or trigger an intent on behalf of the visitor, for example to open the bot directly on a given topic depending on the page.

Called with...Description
a stringSent as a visitor message. send("Hello") is a shortcut for send({ message: "Hello" }).
{ message: "..." }Sent as a visitor message.
{ intent: "..." }Triggers the given intent of the dialogue, without displaying any visitor message.
{ intent: "...", message: "..." }Triggers the given intent and displays message as the visitor message in the conversation.
<button onclick="window.stBot.send('I want to track my order')">Track my order</button>
<button onclick="window.stBot.send({ intent: 'delivery_tracking' })">Track my order</button>
caution

Calling send() without a message nor an intent throws an error. The Smart Bot must have been initialized beforehand.

Use the reset() function

The reset() function will allow you to clear the current conversation and start a new one.

From a...Description
buttonJust call the reset() function on your button.
<button onclick="window.stBot.reset()">Restart the conversation</button>

Use the read() function

The read() function returns a copy of the parameters the Smart Bot was initialized with, or undefined when init() has not been called yet. It is mostly useful to check an integration from the browser console.

<script type="text/javascript">
var config = window.stBot.read();
console.log(config);
</script>

Events

The Smart Bot emits custom events that you can listen to:

STBOTLoaded

Triggered when the Smart Bot script is loaded and ready to be initialized. Its detail is the object carrying init(), show(), hide(), on(), off(), send(), reset() and read().

<script type="text/javascript">
window.addEventListener('STBOTLoaded', function (e) {
console.log('Smart Bot loaded', e.detail);
});
</script>
info

This event is dispatched once per page load. Register your listener before the bot.main.js script tag, otherwise it may already have been dispatched when your listener is attached.

STBOTInitialized

Triggered each time init() completes successfully. Its detail contains the validated initialization parameters.

<script type="text/javascript">
window.addEventListener('STBOTInitialized', function (e) {
console.log('Smart Bot initialized', e.detail);
});
</script>