How can I send a message through the hook

Hello,
I want to display for the user a message, through the hook ?
I tried with this:

bp.events.sendEvent(
      bp.IO.Event({
        botId,
        type: 'proactive-trigger',
        channel: 'web',
        direction: 'outgoing',
        payload: {
          text: 'la conversation est réinitialiser'
        },
        target: event.target
      })
    )

That doesn’t work.
I use the hook on before_session_timeout.
thanks,
@Maxime_Joannette

Hi @kevin21,

You should use type: ‘text’, proactive-trigger is not a supported type; it is used in that proactive example to be caught in the hook and send something else instead.

Tu voudras aussi corriger “réinitialisée” :wink:

Something else you can do is try out the hook in another entry point, for example before incoming middleware, just to have quicker feedback than waiting for the dialog timeout. Make also sure to introduce the await statements and wrap the hook in an async function, since these return Promises.

Cheers!

Mais quelle erreur! Vive la France! vive le Quebec et vive le Luxembourg.

I have found the solution for this:

const userId = event.target
    const botId = event.botId
    const channelId = event.channel
    const eventDestination = { target: userId, botId: botId, channel: channelId }
    bp.cms
      .renderElement(
        'builtin_text',
        { text: "Vous n'avez pas été actif, j'ai réinitialisée la conversation", typing: true },
        eventDestination
      )
      .then(payloads => {
        bp.events.replyToEvent(event, payloads)
      })

Thanks!

2 Likes

How do i send node specific hooks?