Help Center

PostMessage Back Button

Description

This feature allows the user to go back to the virtual assistant from an external chat which has been embedded into the main window, giving over control. 

The code in the external chat

To support this feature, the following javascript code must be added to the external chat:

function PostMessage () {

    var originHost = '';

    var source;

    function handleMessage (event) {

        var data = event.data;

        originHost = event.origin;

        source = event.source;

        if (event.data.message) {

            processMessage(event.data.message);

        }

    }

    function processMessage (message) {

        if (message === 'postmessage_support') {

            var params = {'message' : 'postmessage_supported'};

            source.postMessage(params, originHost);

        }

    }

    this.back = function () {

        if (source) {

            source.postMessage({'message' : 'back_to_agentbot'}, originHost);

            return true;

        } else {

            return false;

        }

    }

 

    window.addEventListener('message', handleMessage, false);

};

var pm = new PostMessage();

Reduced version

function PostMessage(){var a,t="";this.back=function(){return!!a&&(a.postMessage({message:"back_to_agentbot"},t),!0)},window.addEventListener("message",function(s){s.data,t=s.origin,a=s.source,s.data.message&&(e=s.data.message,"postmessage_support"===e&&a.postMessage({message:"postmessage_supported"},t));var e},!1)}var pm = new PostMessage();

Return method

With the PostMessage object correctly initialized, the return to virtual assistant method can be executed in the following way:

pm.back()

This code can be user to carry out the action after meeting a condition, which can be closing the external chat using Javascript, or a simple html button: 

<button onclick="pm.back()">Back to agentbot</button>

The URL’s used for the transfer must be defined correctly in your protocol, HTTP or HTTPS. Also keep in mind that if the website is HTTPS, the external chat must also support the same protocol

This website stores cookies on your computer. These cookies are used to collect information about how you interact with our website and allow us to remember you. We use this information in order to improve and customize your browsing experience and for analytics and metrics about our visitors both on this website and other media. To find out more about the cookies we use, see our Privacy Policy.

If you decline, your information won’t be tracked when you visit this website. A single cookie will be used in your browser to remember your preference not to be tracked.