APIs & Integrations

Not applicable

Trigger Live Chat through JS/JQuery

Hi,

I have a button on my homepage. This button needs to simulate if a user clicks on the live chat button.

Is there a way that I can make the live chat expand on a button click?

Thanks!
Toby

0 Upvotes
2 Replies 2
yaroinfo
Participant

Trigger Live Chat through JS/JQuery

Hello everyone!

We have found a very easy solution. Watch the video to see the solution.

You can use the Javascript code below:

// logo-btn is ID for the element assigned with click event to show Hubspot chat window

// jQuery (ES6)
$('#logo-btn').on('click', () => {
  // check if Hubspot chat is installed
  if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
    window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
  } else {
    console.log('Please install HubSpot WordPress plugin');
  }
});

// VanillaJs (ES5)
document.getElementById('logo-btn').addEventListener('click', function(event) {
  // removef if it is no need to prevent default event such as url redirect in the <a> element
  event.preventDefault(true);
  // check if Hubspot chat is installed
  if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
    window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
  } else {
    console.log('Please install HubSpot WordPress plugin');
  }
});
Not applicable

Trigger Live Chat through JS/JQuery

Looks like they don't have any public APIs for the live chat widget at the moment.

Hi @batjaa, There isn't currently any public API for the HubSpot chat tool. If you have the inclination, I would encourage you to check out the Ideas Forum on the HubSpot Community. There, you can create a post including your use case that product and other customers can see.