Making the bot speak first

I don’t quite understand how to implement the code for making the bot speak first before the user accesses chat.

I’ve placed the code:

  type: 'proactive-trigger',
  channel: 'web',
  payload: {
    text: 'fake message'

into my html page (right below the botpress initialization code) and still within script tags and have saved botspeakfirst.js hook

if (event.type === 'proactive-trigger') {
  // We only want to trigger a proactive message when the session is new,
  // otherwise the conversation will progress everytime the page is refreshed.
  if (event.state.session.lastMessages.length) {
    // This will tell the dialog engine to skip the processing of this event.
    event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)

into botpress/data/global/hooks/before_incoming_middleware

and the bot does not speak when I click on the botpress webchat button.

What am I doing wrong/missing?

Hi @av_botpress,

I’ve just updated the proactive docs in this PR. It will be merged soon.

In your case, its most likely that the chat didn’t load fast enough to send the event. The updated docs make mention of this. Try to set a timeout before sending the event (like in the new docs).

Let me know how it goes!

I added the timeout code in the same way you did in the update, however, still do not receive a message as soon as the web chat is accessed. Also, not sure if this effects anything, but the website is being hosted locally.

  • Is the botId property correct in your window.botpressWebChat.init() ?
  • If you type window.botpressWebChat in your browser console, do you see a result?
  • Maybe try setting a longer timeout (if you’re on a low spec computer)

Can you paste the content of your <script> tag in your index.html?

  1. Yes it is correct.
  2. It returns :
    {init: ƒ} init: ƒ init(config) __proto__: Object
  3. I also get an error now. Not sure how, since it was working before, but chrome returns (aka bot widget button does not show up in the bottom right corner anymore)
<script src="http://localhost:3000/assets/modules/channel-web/inject.js"></script>
        host: 'http://localhost:3000', 
        botId: 'test-bot',

        setTimeout(function() {
        type: 'proactive-trigger',
        channel: 'web',
        payload: { text: 'fake message' }
    }, 1500)

What version are you on? It think you might have one of the binary that had a regression.

Try to download the latest 11.9.3 version, just replace your binary with the new one and make sure you backup before starting botpress.

Let me know if it works.

One of the binary was built with an unstable version in development by mistake. I’m pretty sure you’re running on it because the webchat changed quite a bit.

I just installed the newest version that was updated today and it’s giving me the same error.

1 Like

Any new updates on this?