Make the Bot Initiate Conversation When Button is ...
# 👀feature-requests
f
Hey Guys I'm having some issues trying to connect my bot with my website. I have a CTA button with the id of "startCalculation1" where I want the bot activate the trigger. I tried to following code for my website based on a mix of chatGPT and @straight-musician-77995 code. However I have no luck, they bot just completely disappeared haha. How can I fix this? The code I tried
Copy code
<script src="https://cdn.botpress.cloud/webchat/v0/inject.js"></script>

<script>
  window.botpressWebChat.init({
       // bot configuration
       <script src="https://mediafiles.botpress.cloud/c7353314-2f42-47e8-a8ca-138ba5e0db89/webchat/config.js" defer></script>

  });

// executes when the button is clicked
  document.getElementById('startCalculation1').addEventListener('click', function() {
    // open the chatbot because the trigger doesn't work if the chatbot isn't open
    window.botpressWebChat.sendEvent({ type: "show" });

    // workaround using 'Timeout' cause the 'onEvent(function(), ["LIFECYCLE.LOADED"])' doesn't work and we need to trigger this only after the chatbot is loaded
    setTimeout(function() {
      window.botpressWebChat.sendPayload({
        type: "trigger",
        payload: {}
      });
    }, 3500); // 3.5 seconds, not too short to let it load, not to long to have a message too delayed
  });
</script>
96 Views