def verify_identity(intent_request): """ Handler for the verifying identity :param intent_request: :return: """ session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') current_intent = helper.get_attribute(intent_request, 'currentIntent') slots = helper.get_attribute(current_intent, 'slots') user = helper.lookup_user(session_attributes) zipcode_input = helper.get_attribute(slots, SLOT_ZIPCODE, None) if zipcode_input == user.zip_code: logger.info('zip code match!') user_local_tz = pytz.timezone(user.timezone) today = datetime.now(tz=timezone.utc).astimezone(user_local_tz) session_attributes['NextBot'] = get_next_survey_bot(user.uid, today) session_attributes[AUTH_RESULT_ATTR] = 'AuthSuccess' msg = verify_success_msg(user) return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=msg, message_type='PlainText') else: logger.info('zip code mismatch!') msg = msg_strings.get('ZIP_CODE_MISMATCH').format(zipcode_input) attempt_count = int( helper.get_attribute(session_attributes, ATTEMPT_COUNT_ATTR, "1")) if attempt_count >= MAX_RETRY: msg += msg_strings.get('ZIP_CODE_GOODBYE') logger.info( f'attempt count ({attempt_count}) reached max retry count. failed authentication.' ) session_attributes[AUTH_RESULT_ATTR] = 'AuthFail' return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=helper.wrap_ssml_tag(msg), message_type='SSML') else: session_attributes[ATTEMPT_COUNT_ATTR] = attempt_count + 1 msg += msg_strings.get('ZIP_CODE_RETRY') logger.info( f'attempt count ({attempt_count}) less than max retry count {MAX_RETRY}.' ) return helper.elicit_slot( session_attributes, INTENT_VERIFY_IDENTITY, slots, SLOT_ZIPCODE, message_content=helper.wrap_ssml_tag(msg), message_type='SSML')
def no_symptom(intent_request): session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') symptoms = helper.get_list_from_session(session_attributes, SYMPTOM_ATTR) current_intent = helper.get_attribute(intent_request, 'currentIntent') slots = helper.get_attribute(current_intent, 'slots') confirmation_status = helper.get_attribute(current_intent, 'confirmationStatus') intent_name = helper.get_attribute(current_intent, 'name') if confirmation_status == helper.ConfirmationStatus.NONE.value: if len(symptoms) == 0: # add confirmation for no symptoms return helper.confirm_intent(session_attributes, intent_name, slots, message_content=msg_strings.get('NO_SYMPTOM_CONFIRM')) elif confirmation_status == helper.ConfirmationStatus.DENIED.value: return helper.elicit_slot(session_attributes, INTENT_REPORT_SYMPTOM, slots, SLOT_SYMPTOM_ONE, message_content=msg_strings.get('ASK_SYMPTOM_DETAIL')) # ready to log symptoms user = helper.lookup_user(session_attributes) local_time_reported = get_current_time_for_user(user) unknown_symptoms = helper.get_list_from_session(session_attributes, UNKNOWN_SYMPTOM_ATTR) symptom_reporter.report(user.uid, local_time_reported, symptoms, unknown_symptoms) update_survey_completion(user.uid, local_time_reported, BOT_SYMPTOM_NAME) session_attributes['NextBot'] = get_next_survey_bot(user.uid, local_time_reported) return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=msg_strings.get('FINISH_SYMPTOM_REPORT'))
def medication_time(intent_request): """ Handler for the medication time intent :param intent_request: lex intent request :return: """ session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') current_intent = helper.get_attribute(intent_request, 'currentIntent') slots = helper.get_attribute(current_intent, 'slots') slot_details = helper.get_attribute(current_intent, 'slotDetails') intent_name = helper.get_attribute(current_intent, 'name') if helper.is_validation_request(intent_request): return validate_medication_time(intent_name, session_attributes, slot_details, slots) med_taken_time = slots[SLOT_MED_TIME] hh = int(med_taken_time.split(':')[0]) mm = int(med_taken_time.split(':')[1]) user = helper.lookup_user(session_attributes) local_time_reported = get_current_time_for_user(user) now_with_no_timezone = datetime.now() med_taken_datetime = now_with_no_timezone.replace(hour=hh, minute=mm, second=0) local_med_time = pytz.timezone(user.timezone).localize(med_taken_datetime) # TODO: for production, handle cases when user reported the same info multiple times. med_diary.log_med(user.uid, time_reported=local_time_reported, med_taken=True, time_taken=local_med_time) update_survey_completion(user.uid, local_time_reported, BOT_MEDICATION_NAME) session_attributes['NextBot'] = get_next_survey_bot( user.uid, local_time_reported) return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=msg_strings.get('FINISH_MED_DIARY'))
def no_med(intent_request): session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') user = helper.lookup_user(session_attributes) current_time = get_current_time_for_user(user) if user.caretaker_num: logger.info( f'Will send notification to care taker: {user.caretaker_num}') time_str = format_only_time_to_str(current_time) msg = CARETAKER_MED_MISSING_MESSAGE.format(user.uid, time_str) send_sms(user.caretaker_num, msg) else: logger.info('No caretaker to notify.') med_diary.log_med(user.uid, time_reported=current_time, med_taken=False) update_survey_completion(user.uid, current_time, BOT_MEDICATION_NAME) session_attributes['NextBot'] = get_next_survey_bot(user.uid, current_time) return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=msg_strings.get('DID_NOT_TAKE_MED'))
def no_later(intent_request): session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') return helper.close(session_attributes, helper.FulfillmentState.FULFILLED, message_content=msg_strings.get('AFTER_USER_DENY_TIME'))
def not_supported_intent_handler(intent_request): session_attributes = helper.get_attribute(intent_request, 'sessionAttributes') return helper.close(session_attributes, helper.FulfillmentState.FAILED, message_content=msg_strings.get('NOT_SUPPORTED'))