How to invoke Embedded Service Chat on click of a button in Salesforce?

embedded_svc.bootstrapEmbeddedService() can be used. Check the following article for additional information.  
 
Sample Code in VF Page:
<apex:commandButton value="Start Chat" onclick="embedded_svc.bootstrapEmbeddedService();" reRender="chatDetails"/> 

Sample code in HTML:
<html>
    <input type="button" value="Start Chat" onclick="startChat();"/><br/><br/><br/>
    <input type="button" value="Clear Chat Session" onclick="clearSession();"/><br/>
    
    <!--
        Snipped Code from Embedded Service Deployment
    -->
    
    <script>
        function startChat() {
            
            console.log( 'Inside Start Chat' );
            embedded_svc.liveAgentAPI.startChat({
                directToAgentRouting: {
                buttonId: "5735f000000Tpl7",
                fallback: true
            },
            extraPrechatInfo: [],
            extraPrechatFormDetails: []
            });
            
        }
        
        function clearSession() {
            
            console.log( 'Inside Start Chat' );
            embedded_svc.liveAgentAPI.clearSession();
            
        }
    </script>
</html>

Output:
 

No comments:

Post a Comment