Trigger with payload after show chat not working
# 🤝help
s
Hi I tried to implement a trigger with ["UI.OPENED"] or ["LIFECYCLE.READY"] after show my chatbot but isn't working, the chatbot itself doesn't render. Here is the example what I'm trying to do: // Opens up the Chatbot by default // This lets users start chatting with the Chatbot without needing to click any buttons or menus. window.botpressWebChat.onEvent( function () { console.log("Triggering chat ✅"); window.botpressWebChat.sendEvent({ type: "show" }); }, ["LIFECYCLE.LOADED"] ); window.botpressWebChat.onEvent( function () { console.log("Triggering Payload ✅"); window.botpressWebChat.sendPayload({ type: "trigger", payload: { mode: "cachao", }, }); console.log("Successfully Payload ✅"); }, ["LIFECYCLE.READY"] );
Hi @User could you please help me?
a
help me replicate this, @stale-alligator-73884 ,
f
What is the point of this?
function () { console.log("Triggering Payload ✅"); window.botpressWebChat.sendPayload({ type: "trigger", payload: { mode: "cachao", }, }); console.log("Successfully Payload ✅"); }, ["LIFECYCLE.READY"] );
s
Hi guys, I really appreciate your help. Basically the idea is to thanks to a query parameter, add context data using the payload trigger to the chatbot after show the webchat. The idea is like to share "secret codes", and then with this secret code the user can access to a specific flows, but without the user write it. you can access to the chatbot here https://app.weklimax.com/ URI with query parameter: https://app.weklimax.com/?mode=test Sorry for my bad english
f
So you want to send a payload from the website to the bot, when the bot is ready to be used?
And then this payload will contain something secret?
And your English is perfectly fine 🙂
s
Yes exactly mate!
Yes the data is encoded, and inside the chatbot I decode the data, I already do this 😄
I prepare a diagram to explain my idea better
f
window.botpressWebChat.onEvent( function (event) { if (event.type === 'LIFECYCLE.LOADED') { window.botpressWebChat.sendEvent({ type: 'show' }) window.botpressWebChat.sendPayload({ type: 'trigger', payload: { myCustomProperty: 'hello', }, }) } }, ['LIFECYCLE.LOADED'] ) I think this would work
This will send the payload to the bot as soon as the chatbot is ready and loaded
I haven't tested this
That is amazing!
What are you using to do it
s
The diagram? 😄
f
Yea
s
Figma -> using Figjam
f
Thank you
s
They have a template ready for diagram architecture so you can have a quick start
I will try thanks for your help @fresh-fireman-491
f
Thank you too, and let me know how it goes
s
Hi @fresh-fireman-491 I tried but it doesn't work 😦 I read before you can't send a payload when the lifecycle is loading, I tried to separate the event in two parts validating the different event.type LIFECYCLE.LOADED and LIFECYCLE.READY ; however for some reason this block the thread and the event's doesn't work. So I tried creating two different window.botpressWebChat.onEvent with two different functions, it doesn't work too. Checking:

https://www.youtube.com/watch?v=FKH3b9NlyaI

I notice that the example is presented there work with buttons, he trigger and send the payload without validate the lifecyle with a button. So the only way I made this work was separating the two parts and using a timer to show the chat. Hope work for someone in the future 👍 //Send Payload when lifecycle is ready (loaded can't receive payload) window.botpressWebChat.onEvent( function (event) { if (event.type === "LIFECYCLE.READY") { window.botpressWebChat.sendPayload({ type: "trigger", payload: { mode: "cachao", }, }); } }, ["LIFECYCLE.READY"] ); // After is ready send show event function displayChat() { setTimeout(function () { window.botpressWebChat.sendEvent({ type: "show", }); }, 1000); // 1000 milliseconds = 1 seconds } displayChat();
f
Right yes I do remember that now, sorry. We had a similar problem in another post a while back. Nice to see that you found a solution, I can try and see if I can find the old post tomorrow. I think it had a better solution than a timer, but I am not sure
s
That could be amazing 😄
f
2 Views