Botpress chatbot send events to React or JS Vanill...
# 🤝help
s
I am using React and I have a Botpress chatbot embedded, is it possible from the chatbot to fire events that I can use in react or Javascript? For example, that if a customer does some action in the chatbot, emit an event in react where I can for example emit a confetti animation.
q
Chatbot asks the user what color buttons they prefer, and based on the answer, button colors change on the website.
Two variables, workflow.color and workflow.payload. Execute code card
Copy code
js
workflow.payload = JSON.stringify({ "color": workflow.color })
Send Custon Event card
Website code
Copy code
html
<html>
<head>
  <style>
    body {
      background-color: black;
      color: white;
    }
    button {
      background-color: blue;
      color: white;
      padding: 10px;
      border: none;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <h1>
    Change the button color
  </h1>
    <h1>
    with Chatbot
  </h1>
<script src="https://cdn.botpress.cloud/webchat/v1/inject.js"></script>
<script>
  window.botpressWebChat.init({
  // ADD YOUR BOTPRESS CONFIGURABLE WEBCHAT CODE HERE
  });
</script>

  <button id="timeButton">BUTTON</button>

  <script>
    window.botpressWebChat.onEvent(
      function(event) {
          document.getElementById('timeButton').style.backgroundColor = event.value.color;
          console.log(event)
      },
      ['TRIGGER']
    );
  </script>
</body>
</html>
s
Omg amazing! thank you so much let me try it thank you so much @quick-musician-29561!