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.

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.

//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 and example for using ready to notify when the widget is loaded:

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