in Node/core/src/dialogs/retrieve-facebook-location-dialog.ts [12:49]
function createDialog(apiKey: string) {
return [
(session: Session, args: any) => {
session.dialogData.args = args;
session.beginDialog('facebook-location-resolve-dialog', { prompt: args.prompt });
},
(session: Session, results: IDialogResult<any>, next: (results?: IDialogResult<any>) => void) => {
if (session.dialogData.args.reverseGeocode && results.response && results.response.place) {
locationService.getLocationByPoint(apiKey, results.response.place.point.coordinates[0], results.response.place.point.coordinates[1])
.then(locations => {
let place: RawLocation;
if (locations.length && locations[0].address) {
// We don't trust reverse geo-coder on the street address level.
// So, copy all fields except it.
let address: Address = {
addressLine : undefined,
formattedAddress: undefined,
adminDistrict : locations[0].address.adminDistrict,
adminDistrict2 : locations[0].address.adminDistrict2,
countryRegion : locations[0].address.countryRegion,
locality : locations[0].address.locality,
postalCode : locations[0].address.postalCode
};
place = { address: address, bbox: locations[0].bbox, confidence: locations[0].confidence, entityType: locations[0].entityType, name: locations[0].name, point: locations[0].point };
} else {
place = results.response.place;
}
session.endDialogWithResult({ response: { place: place } });
})
.catch(error => session.error(error));;
}
else {
next(results);
}
}
];
}