cloudy-cyan•17mo ago
Ask User information Only once
How do I only get the bot to ask user information once?
So once they leave the browser and computer and come back to the bot it doesn't ask again.
33 Replies
To ensure that the bot only asks for user information once, you can use the built-in
{userid}
variable in Voiceflow. This variable allows you to identify and track users across different sessions.
Here's how you can do it:
1. When the user provides their information for the first time, store this information in a variable.
2. The next time the user interacts with the bot, check if the {userid}
variable exists and if the user's information is already stored. If it is, you can skip the steps of asking for the user's information.
Here's an example of how you can load the chat with the {userid}
variable:
In the code above, replace 'projectID'
with your project's ID, 'runtime.voiceflow.com'
with your runtime URL, 'production'
with your version ID, and 'string'
with the unique identifier for the user.
Remember, the {userid}
variable is set when you load the chat. It's used to track users and persist/continue sessions. This way, when a user leaves the browser or computer and comes back to the bot, their information is already stored and the bot won't ask for it again.
Please note that this approach requires some coding knowledge. If you're not comfortable with coding, you might want to ask for help from someone who is.cloudy-cyanOP•17mo ago
where do I put this code?
In the JS integration code, but you don't have to do that.
You can just set the info in a variable and then check to see if it has already been set. If it has, skip that question.
cloudy-cyanOP•17mo ago
I think I did that and it didn't work,
This is what I tried but I deleted it

You have to be careful.
It is not empty by default in the test mode
it is set to 0
you need to set the username to "" at the start of your bot.
cloudy-cyanOP•17mo ago
Ohh I see
Username to "" at the start
how would i do that
Using the set thing?
yep
cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago
Okay thanks
right after the start block
cloudy-cyanOP•17mo ago

yep
cloudy-cyanOP•17mo ago

yep
cloudy-cyanOP•17mo ago
thanks let me try this
you need to move that condition step
cloudy-cyanOP•17mo ago
Oh
it will now always be empty
cloudy-cyanOP•17mo ago
How will it recall the name from previous inputs?
Since I wanted to it be like this
1st visit
Username is empty ---> Ask Username ---> Store this information
2nd Visit
username is not empty ---> Welcome {username}
hmmm
ok, delete that set step
and change the condition
add OR username equals 0
you could also use a Javascript step
that will do it
cloudy-cyanOP•17mo ago
Ok thanks let me try that javascrpt
sorry for late reply
cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago

cloudy-cyanOP•17mo ago
Doesn't work yet
It works when i turn off
delete chat history
Is there a way to make it work even when chat history is deleted?
This will do nothing in test mode. only in production.
In test mode all variables reset everytime you run it.
cloudy-cyanOP•17mo ago
yea i tried it in production
it works in production
just only when i turn on this "delete chat history" so when they close the browser it deletes the chat
it doesn't recall
I integrated it into voiceglow
don't delete the history. just leave it on the default setting to remember the chat. Then you will be good to go.
cloudy-cyanOP•17mo ago
Ok thanks, it works. I appreciate the help. Much appreciated. Thank you very much.
deep-jade•17mo ago
Interesting that. So the userid will always be the same userid for a user as long as ‘delete chat history’ isn’t enabled? Does it get the userid from an IP address the or something? I’m making the assumption if someone used a different computer / device it wouldn’t regenerate the same userid then would it? Is that correct? Dumb question I know, but handy for me to clarify that as I previously thought the userID always populated with a different string from one new chat to the next even if same user. But I guess it makes sense, as it would just be working like it does when populated with the number when deployed through WhatsApp right?
The userID is stored in the browser's local storage.
You can also pass the userId, but I would not mess with that.
It gets a little messy