Skip to content

Instantly share code, notes, and snippets.

@frogermcs
Last active November 5, 2017 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogermcs/cf3e64e7cfc98b2b4c0f3b70f587cacf to your computer and use it in GitHub Desktop.
Save frogermcs/cf3e64e7cfc98b2b4c0f3b70f587cacf to your computer and use it in GitHub Desktop.
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