How to save session data within the answer then of a promise

amazon-alexa

#1

I need to save the result of a promise (value) within the object this.$user.$data.key(https://www.jovo.tech/docs/data/user). The value returned by the promise is correct but the assignment does not modify the local db db.json file (https://www.jovo.tech/docs/databases/file-db)

The code is similar like this:

//app.js

myIntent(){

var _this=this;

.then(function(value) { //value is the result of the promise
_this.$user$data.key=value; //does not modify db.json
console.log(value) //is correct
})
}

someone can suggest me some solution, please?


#2

Is this a copy-paste error or also a typo in your app.js? Because it’s missing a . between $user and $data


#3

Sorry, I forgot the .

this is how my code looks like:

myIntent(){

var _this=this;

.then(function(value) { //value is the result of the promise
_this.$user.$data.key=value; //does not modify db.json
console.log(value) //is correct
})
}


#4

What do you hav before the .then? Does it maybe make sense to switch to async/await? This sometimes makes the code more comprehensible.


#5

Thank you very much for the advice. I followed the tutorial and modified my promise function, now it works