How do I trigger a Custom Bot on clicking a link?

Avatar

By Jitta

updated 2 months ago

You can trigger a Custom Bot conversation when your visitors click a link using #GistLink. This is particularly useful to trigger Bot conversations when a button or link is clicked on your website, app, or even links within your email campaigns.

The #GistLink can be enabled under the Settings section of the Bot Editor.

Important Note: Make sure to give your Custom Bot a GistLink, and that it's set to live.

var GIST_BUTTON_SELECTOR = 'gist-open-bot'; // Replace this with the ID of the button that triggers the bot.
var GIST_LINK = "#testbot123"; // Replace testbot123 text with your bot's Gist Link.
window.onload= function () {
  document.addEventListener('gistChatReady', function () {
    const button = document.getElementById(GIST_BUTTON_SELECTOR);
    button.addEventListener('click', function(e) {
      var url_obj = new URL(window.location.href);
      url_obj.hash = GIST_LINK; 
      window.location.replace(url_obj.href);
      e.preventDefault();
    });
  });
}

And make sure the button or link that you want to trigger the bot has the "gist-open-bot" ID.

<button type="button" id="gist-open-bot">Click Me!</button>

To learn more about this and other JavaScript API methods, here's a detailed guide.


Need Help?

If you have any further questions, please start a Live Chat. Just "Click" on the Chat Icon in the lower right corner to talk with our support team.


Did this answer your question?