def zesty(event, **kwargs): """Zesty event handler for Alexa skill webhook events https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference """ intent = kwargs.get('intent') if intent.get('name') == 'ZestyLunchIntent': #webhook_settings = event['webhook_settings'] #user_id = webhook_settings['user'] #from htk.apps.accounts.utils import get_user_by_id #user = get_user_by_id(user_id) # TODO: hardcoded from htk.apps.accounts.utils import get_user_by_username user = get_user_by_username('hacktoolkit') zesty_id = user.profile.get_attribute('zesty_id') if zesty_id is None: ssml = """<speak>Your account does not have a Zesty account id configured. Please check with your Alexa skills admin.</speak>""" else: from htk.lib.zesty.utils import get_zesty_lunch_menu_ssml dt = user.profile.get_local_time() ssml = get_zesty_lunch_menu_ssml(zesty_id, dt) else: ssml = """<speak>Sorry, I'm having difficulties processing that.</speak>""" payload = { 'version' : '1.0', 'response' : { 'outputSpeech' : { 'type' : 'SSML', 'ssml' : ssml, }, }, } return payload
def process_request(self, request): """Replace the authenticated `request.user` if properly emulating """ if is_allowed_to_emulate_users(request.user): from htk.apps.accounts.utils import get_user_by_id from htk.apps.accounts.utils import get_user_by_username user_id = request.COOKIES.get('emulate_user_id') username = request.COOKIES.get('emulate_user_username') is_attempting_to_emulate = user_id or username if is_attempting_to_emulate: if user_id: targeted_user = get_user_by_id(user_id) elif username: targeted_user = get_user_by_username(username) else: rollbar.report_message('Impossible case: attempting to emulate another user but not specified') if targeted_user is None: messages.error(request, 'Cannot Emulate: User does not exist', fail_silently=True) else: if is_allowed_to_emulate(request.user, targeted_user): request.original_user = request.user request.user = targeted_user else: messages.error(request, 'Cannot Emulate: Not allowed to emulate that user', fail_silently=True) else: # not attempting to emulate pass else: # is not allowed or is not attempting to emulate users pass
def process_request(self, request): if self._can_emulate_another_user(request): from htk.apps.accounts.utils import get_user_by_id from htk.apps.accounts.utils import get_user_by_username user_id = request.COOKIES.get('emulate_user_id') username = request.COOKIES.get('emulate_user_username') if user_id or username: if user_id: emulated_user = get_user_by_id(user_id) elif username: emulated_user = get_user_by_username(username) if emulated_user: request.original_user = request.user request.user = emulated_user
def process_request(self, request): """Replace the authenticated `request.user` if properly emulating """ if is_allowed_to_emulate_users(request.user): from htk.apps.accounts.utils import get_user_by_id from htk.apps.accounts.utils import get_user_by_username user_id = request.COOKIES.get('emulate_user_id') username = request.COOKIES.get('emulate_user_username') is_attempting_to_emulate = user_id or username if is_attempting_to_emulate: if user_id: targeted_user = get_user_by_id(user_id) elif username: targeted_user = get_user_by_username(username) else: rollbar.report_message( 'Impossible case: attempting to emulate another user but not specified' ) if targeted_user is None: messages.error(request, 'Cannot Emulate: User does not exist', fail_silently=True) else: if is_allowed_to_emulate(request.user, targeted_user): request.original_user = request.user request.user = targeted_user else: messages.error( request, 'Cannot Emulate: Not allowed to emulate that user', fail_silently=True) else: # not attempting to emulate pass else: # is not allowed or is not attempting to emulate users pass