Create a gist now

Instantly share code, notes, and snippets.

Embed
class Conversation {
//...
//Intent user_data
actionUserData() {
if (this.dialogflowApp.isPermissionGranted()) {
const userName = this.dialogflowApp.getUserName();
if (userName) {
this.userManager.saveAssistantUserName(this._getCurrentUserId(), userName);
const deviceLocation = this.dialogflowApp.getDeviceLocation();
if (deviceLocation) {
return this._setupUserTimezoneAndFinish(deviceLocation);
} else {
return this._askForUserPreciseLocation(userName.givenName)
}
} else {
this._finishWithUnexpectedProblems();
}
} else {
this._finishWithPermissionsDenied();
}
return Promise.resolve(true);
}
_setupUserTimezoneAndFinish(deviceLocation) {
const timezone = this.timeManager.getTimeZoneFromCoordinates(deviceLocation.coordinates);
return this.timeManager.saveAssistantUserTimezone(this._getCurrentUserId(), timezone).then(() => {
this.dialogflowApp.tell(Str.SETTINGS_UPDATE);
});
}
_askForUserPreciseLocation(userName) {
const permission = this.dialogflowApp.SupportedPermissions.DEVICE_PRECISE_LOCATION;
return this.timeManager.getPlatformTime().then(platformTime => {
this.dialogflowApp.askForPermission(
util.format(Str.PERMISSIONS_ASK_FOR_LOCATION, userName, platformTime),
permission
);
})
}
_finishWithUnexpectedProblems() {
this.dialogflowApp.tell(Str.PERMISSIONS_UNEXPECTED_ISSUES);
}
_finishWithPermissionsDenied() {
this.dialogflowApp.tell(Str.PERMISSIONS_DENIED);
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment