Live Chat API

Use our powerful API to automate some of your chat activities and get the most out of our service!

For example, you can get visitor information, set the chat widget language, or maximize the chat widget by calling a JavaScript function from your website.

The JavaScript code must be placed just below the chat widget code as shown on the right.





    <script type='text/javascript'>
        ... onWebChat widget code ...
    </script>
    <script type='text/javascript'>
        ... API functions goes here ...
    </script>



Set Visitor Information

You can set visitor information easily. For example, you can set the visitor's name so that you can see your visitor's names on the 'Visitor List' in the admin interface.

You can set the visitor's name, email, phone, and notes for each visitor of your website with the following API functions:



    onWebChat.set("name","John");
    onWebChat.set("email","john@mail.com");
    onWebChat.set("phone","1234567890");
    onWebChat.set("notes","notes for visitor ..");
                        
                        

Get Visitor Information

You can also get visitor information (set by API, PreChat form, or saved by an agent).

These functions should be called after the chat widget has been loaded. You can call it like this:
onWebChat.set("onWebChatLoaded", function() { console.log("visitor name: " + onWebChat.get("name")); });



    onWebChat.get("name");
    onWebChat.get("email");
    onWebChat.get("phone");
    onWebChat.get("notes");

Set Widget Language

You can set the widget language by choosing from the two languages saved in the admin interface (Widget Settings):

Use l1 as the parameter to use your local language, or l2 to use the other language texts (for visitors from other countries).





    onWebChat.set("language","l1");




Set Widget Appearance

You can control some basic aspects of the widget's appearance:

Use the max parameter with a value of 0 to minimize the chat widget or 1 to maximize it. For example, to maximize the chat widget:

If you want to hide the chat widget, use the set function with the show parameter followed by 0. In the same way, use 1 to show it.





    onWebChat.set("max",1);

    onWebChat.set("show",0);




Get Widget Status

To get the status of the onWebChat widget, just call the following function:

This will return "online" or "offline" depending on the current status.

This function should be called after the chat widget has been loaded. You can call it like this:
onWebChat.set("onWebChatLoaded", function() { console.log("chat status: " + onWebChat.get("status")); });






    onWebChat.get("status");





Callback functions

You can execute a callback function when a particular event occurs:

onClick callback is executed when a visitor clicks on the chat widget

onMaximize callback is executed when the chat widget is maximized

onMinimized callback is executed when the chat widget is minimized

onTrigger callback is executed when a trigger is activated

onStartWriting callback is executed when a visitor starts to write

onWebChatLoaded callback is executed when the chat widget is loaded




    onWebChat.set("onClick",function(){ alert('chat widget is clicked'); });

    onWebChat.set("onMaximize",function(){ alert('chat maximized'); });

    onWebChat.set("onMinimize",function(){ alert('chat maximized'); });

    onWebChat.set("onTrigger",function(){ alert('trigger activated'); });

    onWebChat.set("onStartWriting",function(){ alert('visitor is writing'); });

    onWebChat.set("onWebChatLoaded",function(){ alert('chat widget is loaded'); });


We use cookies to ensure that we give you the best experience on our website.