Proactive action issue

#1

hi all,
i added code in my website, it is working fine it will automatically pop up the bot
window.botpressWebChat.sendEvent({ type: ‘show’ })
window.botpressWebChat.sendEvent({
type: ‘proactive-trigger’,
channel: ‘web’,
payload: {
text: ‘smth’
}
})

but how to use payload “text:smith” and send that text to bot when chat bot triggers.
before that where exactly(in which file) should i add below code to work fine

if (event.type === 'proactive-trigger') {
  const payloads = await bp.cms.renderElement('builtin_text', { text: 'Hey there!', typing: true }, event.channel)
  bp.events.replyToEvent(event, payloads)
}
1 Like
#2

I’m also struggling to make ‘proactive-trigger’ triggers work on my bot, so what I’m about to advice you is not 100% true, but this is what I could find:

The ‘proactive-trigger’ strip of code should be added inside a new file, in the data/global/hooks folder.

Files inside the hooks folder:

  • are read in order of their name, that’s why you see 00_dialog… and 01_expire…;
  • that start with a “.” are files that are never read by the bot;

My issue with this is that my bot triggers a response, but it never delivers my message, instead the bot responds with the next conversation from my flow.

#3

yeah same issue im facing, lets wait for others to reply
if you got any solution reply here

1 Like
#4

As per last developer documentation

https://botpress.io/reference/modules/_botpress_sdk_.cms.html#renderelement

you must pass the event object to renderElement method
Also to get the payload value you have to get it by

event.payload.payload.payload.text;

example

“use strict”;

const setProactive = async () => {

if (event.type === ‘proactive-trigger’) {
bp.logger.warn( `Just received a postback event: ${event.target} ${event.payload.payload.payload.text}` );
// Sends a basic text message
const payloads = await bp.cms.renderElement(‘builtin_text’, {
text: event.payload.payload.payload.text,
typing: true
}, event);
await bp.events.replyToEvent(event, payloads);

}
};

return setProactive();