Sandy
Sandy

Reputation: 51

On button click open the chat window for Salesforce customer chat support

I am using Salesforce live customer chat support for my website. Now what I want on click of any custom button, let say contact, I want to open the chat window. Please help me for this.

<style type='text/css'>
  .embeddedServiceHelpButton .helpButton .uiButton {
    background-color: #005290;
    font-family: "Arial", sans-serif;
  }

  .embeddedServiceHelpButton .helpButton .uiButton:focus {
    outline: 1px solid #005290;
  }
</style>

<script type='text/javascript' src='https://service.force.com/embeddedservice/5.0/esw.min.js'></script>
<script type='text/javascript'>
  var initESW = function(gslbBaseURL) {
    embedded_svc.settings.displayHelpButton = true; //Eller
    embedded_svc.settings.enabledFeatures = ['LiveAgent'];
    embedded_svc.settings.entryFeature = 'LiveAgent';

    embedded_svc.init('https://eu26.salesforce.com', 'https:

      //elsewhere.force.com

      /
      liveAgentSetupFlow ',gslbBaseURL,'
      0x xxxxxx ','
      Chatteam ',

      {
        baseLiveAgentContentURL: 'https://c.la1-c2-fra.salesforceliveagent.com

          /
          content ',deploymentId: '
        5 xxx ',buttonId: '
        5 xxx ',baseLiveAgentURL: 

        'https://d.la1-c2-fra.salesforceliveagent.com/chat',
        eswLiveAgentDevName:

          'Chatteam',
        isOfflineSupportEnabled: true
      });
  };

  if (!window.embedded_svc) {
    var s =

      document.createElement('script');
    s.setAttribute('src',

      'https://eu26.salesforce.com/embeddedservice/5.0/esw.min.js');
    s.onload =

      function() {
        initESW(null);
      };
    document.body.appendChild(s);
  } else

  {
    initESW('https://service.force.com');
  }
</script>

I have integrated the customer chat using the above code. Click to see image for better understanding.

Upvotes: 1

Views: 7658

Answers (2)

user2866086
user2866086

Reputation: 23

embedded_svc.settings.displayHelpButton = false; //

    <input type="button" name="button" value="OpenChat" onclick="startChat()">
    
    function startChat() {
            embedded_svc.liveAgentAPI.startChat({
                directToButtonRouting: {
                    buttonId: "xxxxxxxx",
                    // userId: “”,
                    fallback: true
                },
                extraPrechatInfo: [],
                extraPrechatFormDetails: []
            });
        }

Upvotes: -1

Sandy
Sandy

Reputation: 51

I have found the solution by using some simple jQuery, please find code below:

$("Your_button_class").click(function(){
    $('.helpButtonEnabled').trigger("click");
});

.helpButtonEnabled it is the class of the Salesforce button. It works absolutely perfect for me.

Upvotes: 3

Related Questions