Find the answer you are looking for

Postmessage back button

This feature allows you to return to the virtual assistant from an external chat embedded in the core window, thus delegating control.

To apply it, the following javascript code ⬇ must be added in 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();

👉 Minified 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(); 

Method return: with the PostMessage object correctly initialized, you can execute the method that returns to the virtual assistant as follows ⬇.

pm.back()

This code can be used to perform the action after a condition is met, such as logging out of the external chat, either by javascript or in a simple html⬇ button.

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

The URL's to which it is derived must be correctly defined with their protocol, HTTP or HTTPS. Also note 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.