Persisting Session Data and Validation

dialogflow

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

            const validation = this.validate(schema);

            var isDate = false; 
            var isTime = false; 
            var isDuration = false;

            //Checks for required information in most recent input and session data. 
                //If new required input is saved in the session data bool indicator is... is made 'true'. 
                    //Otherwise user is reprompted

            //date 
            if (validation.failed('date'))
            {
                console.log("\n \n \n \n \n")
                console.log(this.$session.$data.date)
                console.log("\n \n \n \n \n")
                if (this.$session.$data.date)
                    isDate = true; 
            }
            else 
            {
                this.$session.$data.date = this.$inputs.date.value;
                console.log("\n \n \n \n \n")
                console.log(this.$session.$data.date)
                console.log("\n \n \n \n \n")
                isDate = true;
            }

            
            //time
            if (validation.failed('time'))
            {
                if (this.$session.$data.time)
                    isTime = true; 
            }
            else 
            {
                this.$session.$data.time = this.$inputs.time.value; 
                isTime = true;
            }
            
            //duration 
            if (validation.failed('duration'))
            {
                if (this.$session.$data.duration)
                    isDuration = true; 
            }
            else 
            {
                this.$session.$data.duration = this.$inputs.duration.value; 
                isDuration = true;
            }

            console.log("\n \n \n \n \n \n \n"); 
            console.log(isDate); 
            console.log(isTime);
            console.log(isDuration);
            console.log("\n \n \n \n \n \n \n"); 

            //Reprompts the user if they do not provide one of the required inputs
            if (!isDate)
            {
                return this.ask('Please tell me what day you want to reserve the room?');
            }
            if (!isTime)
            {
                return this.ask("Please tell me what time you want to reserve the room?"); 
            }
            if (!isDuration)
            {
                return this.ask("Please tell me for how long you want to reserve the room?"); 
            }

            return this.toIntent('InitializeIteratorIntent'); 
            
        }, 

Relevant Logs as shown in code above:
First prompt — date:

this.$session.$data.date:
December 16th 2018

isDate, isTime, isDuration:
true
false
false

Second prompt — time:

this.$session.$data.date
undefined

isDate, isTime, isDuration:
false
true
false

I don’t know why the session data date is disappearing between intent requests. Because of this the user gets stuck infinitely confirming the data and time. Any insights or suggestions?


#2

Do you use standalone Dialogflow as a platform? I tried to reproduce with a simple example, but it works as expected.

Can you show the logs for the first and second request?


#3

First Request to SpecificRoomReservationIntent: User is prompted for date:

Request for Date:
December 16th 2018

Request for Time:
undefined

Request for Duration:
undefined

true
false
false

Second Request to SpecificRoomReservationIntent: User is prompted for time:

Request for Date:
undefined

Request for TIme:
4:30 p.m.

Request for Duration:
undefined

false
true
false

Third Request to SpecificRoomReservationIntent: Because session data is ‘undefined’ user is prompted for data again:

Request for Date:
December 16th 2018

Request for Time:
undefined

Request for Duration:
undefined

true
false
false


#4

I have been testing exclusively with dialogflow for the past few weeks; however this application is also an Aexa application. The last time I tested this on Alexa, it worked, but it was on a different machine and the code was ever so slightly different: I switched things around to make it easier to read.


#5

Could you also share the language model data? I will try to reproduce with the same code.


#6

{
“name”: “SpecificRoomReservationIntent”,
“phrases”: [
“I would like to reserve a room {date} at {time} for {duration}”,
“I would like to reserve a room at {time} {date} for {duration}”,
“I would like to reserve a room at {time} for {duration} {date}”,
“I would like to reserve a room {date} for {duration} at {time}”,
“I would like to reserve a room for {duration} {date} at {time}”,
“I would like to reserve a room for {duration} at {time} {date}”,
“I would like to reserve a room {date} at {time}”,
“I would like to reserve a room at {time} {date}”,
“I would like to reserve a room at {time} for {duration}”,
"I would like to reserve a room for {duration} at {time} ",
“I would like to reserve a room {date} for {duration}”,
“I would like to reserve a room for {duration} {date}”,
“I would like to reserve a room {date}”,
“I would like to reserve a room at {time}”,
“I would like to reserve a room for {duration}”,

			"I want to reserve a room {date} at {time} for {duration}",
			"I want to reserve a room at {time} {date} for {duration}",
			"I want to reserve a room at {time} for {duration} {date}",
			"I want to reserve a room {date} for {duration} at {time}",
			"I want to reserve a room for {duration} {date} at {time}",
			"I want to reserve a room for {duration} at {time} {date}",
			"I want to reserve a room {date} at {time}",
			"I want to reserve a room at {time} {date}",
			"I want to reserve a room at {time} for {duration}",
			"I want to reserve a room for {duration} at {time} ",
			"I want to reserve a room {date} for {duration}",
			"I want to reserve a room for {duration} {date}",
			"I want to reserve a room {date}",
			"I want to reserve a room at {time}",
			"I want to reserve a room for {duration}",


			"to reserve a room {date} at {time} for {duration}",
			"to reserve a room at {time} {date} for {duration}",
			"to reserve a room at {time} for {duration} {date}",
			"to reserve a room {date} for {duration} at {time}",
			"to reserve a room for {duration} {date} at {time}",
			"to reserve a room for {duration} at {time} {date}",
			"to reserve a room {date} at {time}",
			"to reserve a room at {time} {date}",
			"to reserve a room at {time} for {duration}",
			"to reserve a room for {duration} at {time} ",
			"to reserve a room {date} for {duration}",
			"to reserve a room for {duration} {date}",
			"to reserve a room {date}",
			"to reserve a room at {time}",
			"to reserve a room for {duration}",


			"I would like to book a room {date} at {time} for {duration}",
			"I would like to book a room at {time} {date} for {duration}",
			"I would like to book a room at {time} for {duration} {date}",
			"I would like to book a room {date} for {duration} at {time}",
			"I would like to book a room for {duration} {date} at {time}",
			"I would like to book a room for {duration} at {time} {date}",
			"I would like to book a room {date} at {time}",
			"I would like to book a room at {time} {date}",
			"I would like to book a room at {time} for {duration}",
			"I would like to book a room for {duration} at {time} ",
			"I would like to book a room {date} for {duration}",
			"I would like to book a room for {duration} {date}",
			"I would like to book a room {date}",
			"I would like to book a room at {time}",
			"I would like to book a room for {duration}",


			"I want to book a room {date} at {time} for {duration}",
			"I want to book a room at {time} {date} for {duration}",
			"I want to book a room at {time} for {duration} {date}",
			"I want to book a room {date} for {duration} at {time}",
			"I want to book a room for {duration} {date} at {time}",
			"I want to book a room for {duration} at {time} {date}",
			"I want to book a room {date} at {time}",
			"I want to book a room at {time} {date}",
			"I want to book a room at {time} for {duration}",
			"I want to book a room for {duration} at {time} ",
			"I want to book a room {date} for {duration}",
			"I want to book a room for {duration} {date}",
			"I want to book a room {date}",
			"I want to book a room at {time}",
			"I want to book a room for {duration}",


			"to book a room {date} at {time} for {duration}",
			"to book a room at {time} {date} for {duration}",
			"to book a room at {time} for {duration} {date}",
			"to book a room {date} for {duration} at {time}",
			"to book a room for {duration} {date} at {time}",
			"to book a room for {duration} at {time} {date}",
			"to book a room {date} at {time}",
			"to book a room at {time} {date}",
			"to book a room at {time} for {duration}",
			"to book a room for {duration} at {time} ",
			"to book a room {date} for {duration}",
			"to book a room for {duration} {date}",
			"to book a room {date}",
			"to book a room at {time}",
			"to book a room for {duration}",


			"{date} at {time} for {duration}",
			"at {time} {date} for {duration}",
			"at {time} for {duration} {date}",
			"{date} for {duration} at {time}",
			"for {duration} {date} at {time}",
			"for {duration} at {time} {date}", 
			"{date} at {time}",
			"at {time} {date}",
			"at {time} for {duration}",
			"for {duration} at {time} ",
			"{date} for {duration}",
			"for {duration} {date}",
			"{date}",
			"at {time}",
			"for {duration}", 
			"{date}",
			"{time}",
			"{duration}" 
			

		], 
		"inputs": [
			{
				"name": "date", 
				"type": {
					"alexa": "AMAZON.DATE", 
					"dialogflow": "@sys.date"
				}
			}, 
			{
				"name": "time", 
				"type": {
					"alexa": "AMAZON.TIME", 
					"dialogflow": "@sys.time"
				}
			},
			{
				"name": "duration", 
				"type": {
					"alexa": "AMAZON.DURATION", 
					"dialogflow": "@sys.duration"
				}
			}
		]
	},

#7

UPDATE: I started testing with alexa, and the session data seems to be working as expected. I’m kind of at a loss.


#8

Found it. It’s a naming collision. We merge the session data from the context data in the request.

After typing/saying 4:30 p.m. Dialogflow date is empty and overrides the session data.

Will need to fix it, but for now you can rename your session variables.


#9

Changing the session data variable names allowed me to get all the input from the user. I really appreciate the help! I did, however, subsequently run into a new problem I think is related, the system entries @sys.date, @sys.time, and @sys.duration are suppose to return in ISO-8601 format according to the dialogflow docs. However, the input is stored into session data as normal phrases.

data:
December 16th 2018
4:30 p.m.
40 minutes


#10

Glad it worked.
this.$inputs.date is an object. this.$inputs.date.key will return the ISO-8601 value. Should be the same for the other inputs.