def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers): if handler.recipient == RECIPIENT_CASE: # If there are no recipients, just move to the next reminder event if len(recipients) == 0: return True # If last_fired is None, it means that the reminder fired for the first time on a timeout interval. So we can # skip the lookup for the answered call since no call went out yet. if reminder.last_fired is not None and reminder.callback_try_count > 0 and CallLog.answered_call_exists(recipients[0].doc_type, recipients[0].get_id, reminder.last_fired): reminder.skip_remaining_timeouts = True return True verified_number = verified_numbers[recipients[0].get_id] if verified_number is not None: if initiate_outbound_call(verified_number, reminder.current_event.form_unique_id, handler.submit_partial_forms, handler.include_case_side_effects, handler.max_question_retries): return True else: reminder = CaseReminder.get(reminder._id) reminder.error_retry_count += 1 if reminder.error_retry_count > getattr(settings, "IVR_OUTBOUND_RETRIES", DEFAULT_OUTBOUND_RETRIES): return True else: reminder.next_fire += timedelta(minutes=getattr(settings, "IVR_OUTBOUND_RETRY_INTERVAL", DEFAULT_OUTBOUND_RETRY_INTERVAL)) reminder.save() return False else: raise_error(reminder, ERROR_NO_VERIFIED_NUMBER) return False else: # TODO: Implement ivr survey for RECIPIENT_USER, RECIPIENT_OWNER, and RECIPIENT_SURVEY_SAMPLE return False
def initiate_outbound_call(*args, **kwargs): retry_num = kwargs.pop("retry_num", 0) try: if retry_num > 0: kwargs.pop("timestamp", None) result = api.initiate_outbound_call(*args, **kwargs) except Exception: notify_exception(None, message="Could not initiate outbound call") result = False if not result: if retry_num < OUTBOUND_RETRIES: kwargs["retry_num"] = retry_num + 1 initiate_outbound_call.apply_async(args=args, kwargs=kwargs, countdown=(60*OUTBOUND_RETRY_INTERVAL))
def initiate_outbound_call(*args, **kwargs): retry_num = kwargs.pop("retry_num", 0) try: if retry_num > 0: kwargs.pop("timestamp", None) result = api.initiate_outbound_call(*args, **kwargs) except Exception: notify_exception(None, message="Could not initiate outbound call") result = False if not result: if retry_num < OUTBOUND_RETRIES: kwargs["retry_num"] = retry_num + 1 initiate_outbound_call.apply_async( args=args, kwargs=kwargs, countdown=(60 * OUTBOUND_RETRY_INTERVAL))
def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers): if handler.recipient == RECIPIENT_CASE: # If there are no recipients, just move to the next reminder event if len(recipients) == 0: return True # If last_fired is None, it means that the reminder fired for the first time on a timeout interval. So we can # skip the lookup for the answered call since no call went out yet. if reminder.last_fired is not None and reminder.callback_try_count > 0 and CallLog.answered_call_exists( recipients[0].doc_type, recipients[0].get_id, reminder.last_fired): reminder.skip_remaining_timeouts = True return True verified_number = verified_numbers[recipients[0].get_id] if verified_number is not None: if initiate_outbound_call(verified_number, reminder.current_event.form_unique_id, handler.submit_partial_forms, handler.include_case_side_effects, handler.max_question_retries): return True else: reminder = CaseReminder.get(reminder._id) reminder.error_retry_count += 1 if reminder.error_retry_count > getattr( settings, "IVR_OUTBOUND_RETRIES", DEFAULT_OUTBOUND_RETRIES): return True else: reminder.next_fire += timedelta(minutes=getattr( settings, "IVR_OUTBOUND_RETRY_INTERVAL", DEFAULT_OUTBOUND_RETRY_INTERVAL)) reminder.save() return False else: raise_error(reminder, ERROR_NO_VERIFIED_NUMBER) return False else: # TODO: Implement ivr survey for RECIPIENT_USER, RECIPIENT_OWNER, and RECIPIENT_SURVEY_SAMPLE return False