0
私の約束は未定義の値を返します。 node.jsページでこの機能を正しく実行する方法がわかりません。私のコンテキストでジオコーディングした後、すべての値を適切に返すために、これを手伝ってください。ありがとうございます
Node.js Wit.ai約束返却関数
merge_location({
entities,
context,
message,
sessionId
}) {
return new Promise(function(resolve, reject) {
var location = firstEntityValue(entities, 'location');
if (location) {
geocoder.geocode(location).then(function(res) {
console.log(res);
context.location = location;
context.lat = res[0].latitude;
context.lng = res[0].longitude;
delete context.MissingLocation;
}).catch(function(err) {
context.MissingLocation = true;
delete context.location;
delete context.lat;
delete context.lng;
console.log("Il n'y a pas de ville ");
});
} else {
context.MissingLocation = true;
delete context.location;
delete context.lat;
delete context.lng;
console.log("Il n'y a pas de ville ");
}
console.log("I want to return this" + context.location + ' ' + context.lat + ' ' + context.lng);
return resolve(context);
});
}