breezy-smartphone-98830
08/30/2023, 10:34 AMacceptable-kangaroo-64719
08/30/2023, 10:40 AMjs
var detail;
var botLoaded = false;
var botReady = false;
var submitted = false;
function showBot(){
console.log("Showing bot....")
window.botpressWebChat.sendEvent({type:'show'})
}
function sendFormInfo(info){
console.log("Triggering bot with payload...")
window.botpressWebChat.sendPayload({ type: 'trigger', payload:info })
}
document.getElementById('myButton').addEventListener('click', function(event) {
event.preventDefault();
// collect details from the webpage if you want to do this
detail ={
name: event.target.name.value,
email: event.target.email.value,
linkedin: event.target.catster.value,
message: event.target.message.value,
}
detail['position'] = 'Cat Wrangler'
showBot()
console.log("Submitting....")
submitted=true;
});
window.botpressWebChat.onEvent( function (event) {
console.log(event)
if(event.type === 'LIFECYCLE.LOADED'){
botLoaded = true;
}
else if(event.type === 'LIFECYCLE.READY'){
botReady = true;
if(botLoaded && botReady && submitted){
sendFormInfo(detail)
}
}
},['LIFECYCLE.LOADED', 'LIFECYCLE.READY']
)
breezy-smartphone-98830
08/30/2023, 10:41 AMacceptable-kangaroo-64719
08/30/2023, 10:45 AM