How to set a user variable during init?
# 🤝help
I have created a user variable called VIP (user.VIP) in my flow. I want to set this using window.botpressWebChat.init however I can't seem to get the syntax correct. Please can someone provide an example? Thanks1
I have tried adding userData: { "user.VIP": "1" } to window.botpressWebChat.init({ });
Hey @miniature-book-74584 there are two parts to this: 1. Send info from the webpage to the bot 2. Catch this info in the bot and do something with it For the first part, you can look at our documentation here and use code like this in your website:
Copy code
  document.addEventListener("LIFECYCLE.READY", () => {
      type: 'trigger',
      payload: {
        myCustomProperty: 'hello',
Then, inside your bot you can catch this with a trigger and use an execute code card to save the info to a user variable
Copy code
if(event.payload.myCustomProperty && event.payload.myCustomProperty == "myValue"){
  user.var = event.payload.myCustomProperty
Ahha, ok thanks Gordy let me try that!
You'll need to use a custom trigger to catch it

ok, so have added
document.addEventListener("LIFECYCLE.READY", () => { window.botpressWebChat.sendPayload({ type: 'trigger', payload: { myCustomProperty: 'vip', }, }); });
In to a on the page...
Then added a trigger block
Do I add this code...
if(event.payload.myCustomProperty && event.payload.myCustomProperty == "vip"){ user.VIP = "1" }
To the trigger itself?
Or Do I need to add to "execute code" section?
add the execute code section after the trigger
Seems my page is not reporting LIFECYCLE.READY ... I can see LIFECYCLE.LOADED but then I receive [webchat] Cannot send data until the webchat is ready... any ideas?
ok so now payload sending... 🙂
However can't seem to get variable to stick 😦
Tried, event.session.vip_state ... but won't show in {{}} or {{event.session.vip_state}} in a card..
I can see trigger acticating in log...
Is there any way to view variables being set?
Ok got it working following the approach on your video here, thanks!