Acting Proactively
You may wish to make your bot act proactively on your website in response to some action. E.g., suggest they buy the product they are viewing after a set time or ask them for feedback on services they were using.
With Botpress this is simple:
- First you need to open the bot-window and then trigger a custom action-type (
proactive-trigger
in the example below). These can be triggered by a javascript event such as a timeout.
window.botpressWebChat.sendEvent({ type: 'show' })
window.botpressWebChat.sendEvent({
type: 'proactive-trigger',
channel: 'web',
payload: {
text: 'smth'
}
})
- This trigger will be dispatched to the bot so you need to add a handler for it. This should be added as a Hook
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)
}
That's it! If you have your builtin renderers registered, the code above will work!