I have trouble getting stringReply
value into my app.post
(using Express).
For what I know I think is that the code has completely executed before the promise is resolved, thus giving me a undefined value when I tried to log stringReply
.
fetch(osURL, setting)
.then(loadRes)
.then(logger)
function loadRes (res){
return res.json();
}
async function logger (reply){
let stringReply = await reply.answer;
sendingReply(stringReply);
return stringReply
}
function sendingReply(stringReply){
let response = {
"fulfillmentMessages": [
{
"text": {
"text": [
stringReply
]
}
}
]//fulfillmentMessageObj
};//response3
console.log(stringReply); //I can still get the value I wanted here
return response
}
app.post('/', function( req, res){
console.log(stringReply);
//obtain value here before posting the value to other place
}