https://discord.gg/botpress logo
i am trying to create a custom trigger
# 💻developers
a
i am trying to create a custom trigger using sendEvent. What's with this error - Error: Botpress webchat is not initialized. Please call botpress.init() before sending events.
w
a
hey @white-nest-40686 thanks for this. I have a question -botpress.init() - is it compulsory for events to occur?
i am unable to get events initialised/triggered without it
w
The botpress.init() function is already called by the embed code. Your JavaScript should be placed after the Botpress code, and you need to ensure that the initialization is complete before executing your script. in this [tutorial](https://discord.com/channels/1108396290624213082/1272227414197669960/) there are some examples.
Copy code
html
    <script src="https://cdn.botpress.cloud/webchat/v2.2/inject.js"></script>
    <script src='https://files.bpcontent.cloud/yyyy/mm/dd/hh/yyyymmddhhnnss-XXXXXXXX.js'></script>
    <script>
      // Open webchat
      /* The 'webchat:ready' event sometimes doesn't seem to trigger. ╭∩╮ (︶︿︶) ╭∩╮ */
      window.botpress.on('webchat:ready', (conversationId) => { botpress.open(); });
      window.addEventListener('load', function() { botpress.open(); });
     </script>
replace
botpress.open();
with your code
a
Hey, thanks for the help. I found the issue: It's working after I set a timeout. looks like the botpress.init() took some time and the botpress.sendEvent was called before it.
2 Views