Getting data into Botpress using Get User Data
# 🤝help
s
Hi everyone, I created a bot that will give advice on how to fix marketing campaigns based on user data. This data needs to come from the software so I assume it gets pulled in when the chat started. I added the Get User Data card but i'm getting an error in the testing environment, any suggestions?
f
Hey You can't use webchat cards in the emulator, you have to be on the website that sends the user data. If you want to test it you could set up a variable that would have some fictitious user data and then test it with that in the emulator.
m
I use a trigger to get user data
s
How would I add in those variables? I'm brand new to this platform haha
f
No worries. You can add an execute code card and a variable called workflow.userData In your execute code card you would have it like this: workflow.userData = what ever you would have in here. Make sure that the type of the variable matches the type of the data that you would send from your website.
s
Awesome, ill try that out and report back
f
Sounds good!
s
For the second part is it json?
f
I think so yea
You would have to check but I am pretty sure
s
Okay so looks like the script is running and the data is being assigned but im still getting an error in the execute stage
f
Seems like there is an issue with your variable
Do you still have the card called GetUserData on?
Because it shouldn't be there
When testing in the emulator
s
Ahh that would make sense
Yes i still have it in there
So i build this out using by setting the variables manually and then when I go to publish add in the get user data?
f
Yea
I would still test it while its in production on a website with the Get User Data card, just to make sure you aren't building something that won't work with it
s
Got it
Appreciate you taking the time!
f
Ofc, always happy to help
s
Hi! I am having a similar problem. I am not being able to capture the information using the Get User Data card
So, basically this part isn't working.
f
Hey there, sorry to hear that you are also having some issues. Have you read this post and tried everything mentioned in it?
s
Yep, think so
I'll attach screenshots
First get user Data, then the code, and then the info should appear in the chat
(this screenshot is in my website, not part of the emulator)
I don't know what else to do to be honest, do you notice anthing wrong?
Oh and this screenshot was missing
So it should be capturing the name "roberto" in the Get User Data, it should be extracted from the object in the code, leaving workflow.test2 === "roberto" and then it should show it in the chat. But instead, it's throwing an error.
I made a test, and if I leave the "Execute code" block in the disconnected node, then there is no error
The error only appears when executing the code.
Copy code
workflow.test2 =  workflow.test.userData.name;
Do you notice anything clearly wrong? @fresh-fireman-491
f
userData on your website should not have "" around it
Would look like this
window.botpressWebChat.init({ userData: { name: 'Jack Black', }, })
s
Doesn't seem like a problem because all my properties are between quotes, but will give it a go
f
Yea I can see that I got the same
s
Nop, still breaking
f
In the execute code card
Delete workflow.test2 = workflow.test.userData.name; and write console.log(workflow.test)
s
of course
f
Then republish your bot and try it in the webchat and look at the logs
s
Didn't know you could console.log in production
f
It will show up in the logs in the dashboard
s
Oh
Give me a second 🙂
They are taking a bit to appear in the logs tab
I guess it's line 755
Copy code
{}
Moved the code a little bit later (maybe was an async problem) and added other log to be easier to recognize
and still {}
Any clue? @fresh-fireman-491
f
Try console.log(workflow.test.userData)
This is what I get
window.botpressWebChat.init({ userData: { name: 'Jack Black', }, "composerPlaceholder": "Chat with bot", "botConversationDescription": "This chatbot was built surprisingly fast with Botpress",
s
Nope. Still not working. Made some modifications, noticed that my webhookId was wrong.
still same result
f
Have you tried it on the JSfiddle?
Try using your bot on the JSfiddle
And try and use my bot with your website code
Go through everything step by step and then try and see where it goes wrong.
s
Yep, doing exactly that right now
Thanks
I've tested it doing the same process as you, creating my bot from scratch and it worked
Will try to fix mine now, debugging with JSFiddle
Omg, now it's working in the JSFiddle
but, not in my website. I've checked and the code seems the same
f
Does it throw any errors? In the logs on Botpress or on your website?
s
No
Nothing
I kept testing
works in fiddle
Does not in production
I have the bot deployed in 2 different websites
doesn't work in any of them
when i inspect, i verify that the userData is correctly there
it just does not work
No errors at all, the object is just empty.
Is there anyone in the botpress tech team available? @crooked-van-25152
I literally copied the code from JSfiddle and pasted it in my website, and yet it works on fiddle but not on my website
Is there any other way to pass information from the website to the bot, besides userData? Maybe triggers or something like that ? @fresh-fireman-491
f
And the chatbot shows up right?
JavaScript needs around it to work in the html file
s
Hi @fresh-fireman-491! Sorry for the late response. I fixed the issue by using triggers to send the data. Thank you very much for all your help!
f
No worries at all Thanks a lot for letting me know about that!
c
Awesome work you two! @fresh-fireman-491 @steep-football-15739 🚀
s
❤️
l
Hey @steep-football-15739 can you tell me how you fixed this with triggers please. I am facing the same issue.
s
As soon as the bot is initiated, I send a tigger to the bot with some information.
And then, in the botpress studio there is a captura trigger which grabs that information and puts it inside a variable
14 Views