A full list of the available methods and events is located at Talk JavaScript API.
Prerequisites
Firstly, ensure that the Talk messenger widget is turned ON in Ortto, via Settings> Talk messenger.
Add Talk messenger methods to your website’s JavaScript
Any of the available Talk methods and events can be added to your website’s JavaScript.
The Talk messenger widget loads asynchronously, so you may wish to use the talk.ready flag to check whether it is already loaded:
javascript
//talk.ready flag
window.ap3c.talk.ready;
//print to notify when ready
const notifyWhenReady = () => {
console.log('ready');
};
then, to be notified, listen for the ready event:
javascript
//notify when ready
window.ap3c.talk.addEventListener('ready', notifyWhenReady);
//stop notifying
window.ap3c.talk.removeEventListener('ready', notifyWhenReady);
When the widget is ready, you can add any of the following methods to your site’s JavaScript to modify the widget’s behavior:
javascript
//open the widget
window.ap3c.talk.execute('open');
//close the widget
window.ap3c.talk.execute('close');
//hide the widget
window.ap3c.talk.execute('hide');
//show the widget
window.ap3c.talk.execute('show');
Start a Talk conversation with an initial message
You can configure the Talk messenger widget to start a conversation using a predefined message sent by the customer or visitor.
For example, you might want to have website visitors click a button which requests a call from your Sales or Support team. In this example, the button text says “Call me”. You can bind a click handler to the button to call the following command:
When a customer or visitor clicks on the “Call me” button, it will start a conversation where the initial message is “Call me”. From there, your Sales or Support agent can carry on the conversation as usual.
Example showing what a new conversation looks like using the start-conversation method
Add Talk messenger commands to your tracking code
If you are using commands that include ap3c.talk.execute, e.g. window.ap3c.talk.execute('show');, you may want to run those commands in your tracking code instead. This might be necessary if the Talk messenger widget is loading slowly on your website and ap3c.talk.execute() is not yet available (undefined).
Adding commands to the tracking code will ensure that your commands are called when our capture script (and therefore the Talk messenger widget) is loaded, and avoids calling non-existent Talk methods.
You can add commands to the push method of the ap3c.cmd array of the tracking code.
For example, you want to change the chat icon to have a seasonal theme. You can add a set:style command to ap3c.cmd.push, similar this: