How to invoke Embedded Service Chat on click of a button in Salesforce Force.com Site?

How to invoke Embedded Service Chat on click of a button in Salesforce Force.com Site?

embedded_svc.liveAgentAPI.startChat() can be used to invoke Embedded Service Chat on click of a button in Salesforce.

For custom website(not force.com site), check the following link.

https://www.infallibletechie.com/2021/08/how-to-invoke-embedded-service-chat-on.html

1. Create a Visualforce Page with Embedded Service Deployment Code Snippet.

<apex:page >

    <input type="button" value="Start Chat" onclick="startChat();"/><br/><br/><br/>
    <input type="button" value="Clear Chat Session" onclick="clearSession();"/><br/>
    
    <!-- Paste your Embedded Service Snippet code here -->
    
    <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>
</apex:page>

2. Create a force.com site. Use the VF page created in step 1 as the home page.

3. Make the site public. Give access to the VF page created in step 1.

4. Activate the page. Test it.

Leave a Reply