Last active
November 5, 2017 13:32
-
-
Save frogermcs/cf3e64e7cfc98b2b4c0f3b70f587cacf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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