Struggling to use botpressWebchat event
# 🤝help
w
Hi 🙂 I try to trigger when a message is sent, or received in my page with this javascript code:
Copy code
window.botpressWebChat.onEvent(
    (event) => {
      if (event.type === 'MESSAGE.SENT') {
        console.log('Message sent:')
      } else if (event.type === 'MESSAGE.RECEIVED') {
        console.log('Message received:')
      } else if (event.type === 'MESSAGE.SELECTED') {
        console.log('Message selected:')
      }
    },
    ['MESSAGE.SENT', 'MESSAGE.RECEIVED', 'MESSAGE.SELECTED']
  )
but I don't receive anything and I get an error message in my browser console :
typeError: Cannot read properties of undefined (reading 'onEvent')
If anyone has any idea ^^
a
What are you trying to trigger like why are you using the trigger
w
Just testing the feature in order to know when a certain message is sent
Basically idk if I missed something , if there is anything to add to my code in order to use the botpresswebchat event
c
I'm not sure what you want to do here, but maybe you could try by using [@botpress/webchat](https://botpress.com/docs/developers/webchat-v2/javascript-client/) + React/Vue/Svelte/Other instead.
w
actually I just wanted to use simple javascript like it is explained here https://botpress.com/docs/developers/webchat/controlling-webchat-using-js/#listening-to-widget-events , and it seems to require no particular import
c
I meant that @square-energy-41150/webchat node package is so much better, since it performs better and allows you to handle messages in the same way, but way more confortably. https://cdn.discordapp.com/attachments/1247951955846762497/1248257664258019419/image.png?ex=6663020a&is=6661b08a&hm=aaf55e8b914f005a93f530173d8870e6c1af2cd74a9a521f8ec7ac1e49131bb6&
w
Okay thank you 😉
61 Views