User variables
# 🤝help
f
Hi! How can we use user variables to store some information from api calling for a user and then use that same info again in other session, rather than calling the app again and again? I see user variables in chat settings, but unable to use them within the bot
a
Hey @flat-nail-33989 we just updated our documentation on variables here https://botpress.com/docs/cloud/studio/variables/ Session variables might also be helpful for you too
f
Thank you so much for your response @acceptable-kangaroo-64719! Will check this out
h
@acceptable-kangaroo-64719 The documentation explains how to create a User Variable but nothing about how to populate it. For example how do I save a users name so that it can be used throught the conversation today, and tomorrow when they return. Can you explain pls.
a
hi londibob 👋 take a look at this vid. should have what you're looking for:

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

h
Thanks for sharing the video. As I understand the process is this : Step 1 : In Settings, create User Variable stype "string". eg. personsname Step 2 : Add users name to variable via capture card eg. John Step 3 : Output name @user.personsname The part that is not explained in neither the knowldegebase document or the video is Step 2, how to save a person name in the User Variable. In the capture card it wont let me add the User Variable to save the persons name. Not sure if Im doing something completely wrong or its a bug.
a
hey @acceptable-kangaroo-64719, any insight on how to get this done?
a
For step 2, use a code card. It can be as simple as
Copy code
js
user.uservar = event.preview
To capture the exact thing that the user said.
h
@acceptable-kangaroo-64719 Many thanks that worked, you're a star! For a "no-code" app there's still many things that we need code for, and that perhaps a simple thing like this could easily be added as its own type of card called "add workflow variable to user variable". 🙂
a
That would make a great addition to #1111026806254993459 !
2 Views