Saving Session Data


#1

The docs intimate that one can store data which will subsist over the course of a session.

this.$session.$data.key = value;

I need to store three variables. I thought ‘key’ was a placeholder for any variable name, but It appears that this is not the case. How would I use this feature to make three inputs subsist for a session? Is this the right feature to use?


#2

Yes, this should work with the key placeholder. Do you see session attributes within the next request data? Can you output the logs from your local server?


#3

const schema = {
date: new IsRequiredValidator(),
time: new IsRequiredValidator(),
duration: new IsRequiredValidator()
};

    const validation = this.validate(schema);

//Time
if (this.$session.$data.time == undefined)
{
if (validation.failed(‘time’))
{
return this.ask(“Please tell me when you want to reserve the room?”);
}
else
{
console.log(’\n’ +’\n’ +’\n’ + ‘Made It Before’ +’\n’ +’\n’ +’\n’);
this.$session.$data.time = this.$input.time.value;
console.log(’\n’ +’\n’ +’\n’ + ‘Made It After’ +’\n’ +’\n’ +’\n’);
}
}

When input is given, I save it to a session variable. The user is then re-prompted. The same intent is triggered, but the input the user has already given remains as it is part of the session. Eventually, the user has given all the input I need and, it has all been stored in session variables… Or at least, that is supposed to be how it works.

Instead, on this line:

            this.$session.$data.time = this.$input.time.value; 

I get a “Cannot read property ‘time’ of undefined” error message. This makes sense because the session variable ‘time’ is undefined. However, i do not know how to define ‘time’. I apologize if this is a dumb question, I am still figuring out JS.

Thanks in advance.


#4

To answer your question, it does not let me get to a new request. It throws the error as soon as I try to store the input into a session variable.


#5

Figured it out. It was not the session data that was the issue. I was doing

this.input...

instead of

this.inputs...

lol. Sorry for the bother!


#6

Great, thanks for clarifying! Closing this now


closed #7