Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
266 lines (181 sloc) 5.48 KB

Chat Widget API

Hooks

onBeforeLoad

Callback function invoked when widget code is loaded but chat window is not rendered yet. You can return false to stop the widget initialization.

window.BE_API = window.BE_API || {};

window.BE_API.onBeforeLoad = function () {
    // return false
};

onLoad

Callback function invoked when widget code is loaded and chat window is rendered.

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    // ...
};

onCreate

Callback function invoked after create() API method call.

window.BE_API = window.BE_API || {};

window.BE_API.onCreate = function () {
    // ...
};

onDestroy

Callback function invoked after destroy() API method call.

window.BE_API = window.BE_API || {};

window.BE_API.onDestroy = function () {
    // ...
};

onChatWindowOpen

Callback function invoked when the chat window is opened.

window.BE_API = window.BE_API || {};

window.BE_API.onChatWindowOpen = function () {
    // ...
};

onChatWindowClose

Callback function invoked when the chat window is closed.

window.BE_API = window.BE_API || {};

window.BE_API.onChatWindowClose = function () {
    // ...
};

onMessage

Callback function invoked after query result.

window.BE_API = window.BE_API || {};

window.BE_API.onMessage = function (result) {
    console.log(result)
};

onStartConversation

Callback function invoked after the conversation starts.

window.BE_API = window.BE_API || {};

window.BE_API.onStartConversation = function () {
    // ...
};

Methods

create

Create chat widget if does not exist

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    window.BE_API.create();
};

destroy

Destroy chat widget if exist

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    window.BE_API.destroy();
};

resetSession

Reset current session and recreate widget.

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    window.BE_API.resetSession();
};

openChat

Open the chat window, should be used only inside window.BE_API.onLoad callback

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    window.BE_API.openChat();
};

closeChat

Close the chat window, should be used only inside window.BE_API.onLoad callback

window.BE_API = window.BE_API || {};

window.BE_API.onLoad = function () {
    window.BE_API.closeChat();
};

setCustomParameters

Set your custom parameters that will be sent to the query. Each method call will overwrite existing parameters. Read more about parameters here: https://www.botengine.ai/docs/talk-with-bot#parameters

Payload

parameter type description
Object Object( Entry Object(1, 99) ) required Object with entries

Entry Object

parameter type description
key String(1, 128) Parameter name
value String(1, 1024) Parameter value
window.BE_API = window.BE_API || {};

window.BE_API.onLoad = () => {
    window.BE_API.setCustomParameters({
        email: 'support@botengine.ai',
        name: 'Botengine Support'
    })
}

sendMessage

Send a message as visitor.

Payload
parameter type description
payload.message String(1, 256) required Message
payload.postback String(1, 256) Postback
window.BE_API = window.BE_API || {};

window.BE_API.onLoad = () => {
    window.BE_API.sendMessage({
        message: 'message',
        postback: 'postback'
    })
}

sendTrigger

Trigger the specific interaction.

Payload

parameter type description
payload String(1, 50) required Trigger name
window.BE_API = window.BE_API || {};

window.BE_API.onLoad = () => {
    window.BE_API.sendTrigger('custom_trigger')
}