Talk JavaScript API

This page provides a list of the available JavaScript methods and events available from Ortto’s API for controlling Ortto’s Talk messenger widget programmatically.

The methods and events described on this page can be configured in your website’s JavaScript or in your website’s tracking code, depending on your needs. Learn more at Talk messenger methods.


set:style/reset:style

The set:style and reset:style methods enable you to set/reset custom styling for the widget icon container.

The following example shows a custom background color and border for the widget icon container.

javascript

window.ap3c.talk.execute('set:style', { container: { backgroundColor: 'red', border: '1px solid blue', }, }); window.ap3c.talk.execute('reset:style');

open/close/hide/show

There are 4 available methods to open/close and show/hide the widget, as shown below.

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');

ready

The Talk messenger widget loads asynchronously, so the ready event enables you to check whether the widget is already loaded.

The following shows an example for using ready to notify when the widget is loaded:

javascript

//talk.ready flag window.ap3c.talk.ready; //print to notify when ready const notifyWhenReady = () => { console.log('ready'); }; //notify when ready window.ap3c.talk.addEventListener('ready', notifyWhenReady); //stop notifying window.ap3c.talk.removeEventListener('ready', notifyWhenReady);

start-conversation

The start-conversation command enables you to start a conversation containing a predefined message sent by the customer or visitor. 

The following shows an example for a conversation starting with the initial message "Call me":

javascript

ap3c.talk.execute('start-conversation', {initialMessage: 'Call me'})