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);
});
}