def fire_sms_callback_event(reminder, handler, recipients, verified_numbers, logged_event): current_event = reminder.current_event for recipient in recipients: send_message = False if reminder.callback_try_count > 0: if reminder.event_initiation_timestamp: event = ExpectedCallbackEventLog.view( "sms/expected_callback_event", key=[ reminder.domain, json_format_datetime( reminder.event_initiation_timestamp), recipient.get_id ], include_docs=True, limit=1).one() if not event: continue if event.status == CALLBACK_RECEIVED: continue if CallLog.inbound_entry_exists( recipient.doc_type, recipient.get_id, reminder.event_initiation_timestamp): event.status = CALLBACK_RECEIVED event.save() continue else: continue if (reminder.callback_try_count >= len( current_event.callback_timeout_intervals)): # On the last callback timeout, instead of sending the SMS # again, log the missed callback if event: event.status = CALLBACK_MISSED event.save() else: send_message = True else: # It's the first time sending the sms, so create an expected # callback event send_message = True event = ExpectedCallbackEventLog( domain=reminder.domain, date=reminder.event_initiation_timestamp, couch_recipient_doc_type=recipient.doc_type, couch_recipient=recipient.get_id, status=CALLBACK_PENDING, ) event.save() if send_message: fire_sms_event(reminder, handler, [recipient], verified_numbers, logged_event, workflow=WORKFLOW_CALLBACK)
def fire_sms_callback_event(reminder, handler, recipients, verified_numbers): current_event = reminder.current_event if handler.recipient in [RECIPIENT_CASE, RECIPIENT_USER]: # If there are no recipients, just move to the next reminder event if len(recipients) == 0: return True # If the callback has been received, skip sending the next timeout message if reminder.callback_try_count > 0: # Lookup the expected callback event if reminder.event_initiation_timestamp is None: event = None else: event = ExpectedCallbackEventLog.view( "sms/expected_callback_event", key=[ reminder.domain, json_format_datetime( reminder.event_initiation_timestamp), recipients[0].get_id ], include_docs=True, limit=1).one() # NOTE: If last_fired is None, it means that the reminder fired for the first time on a timeout interval if reminder.last_fired is not None and CallLog.inbound_entry_exists( recipients[0].doc_type, recipients[0].get_id, reminder.last_fired): reminder.skip_remaining_timeouts = True if event is not None: event.status = CALLBACK_RECEIVED event.save() return True elif reminder.callback_try_count >= len( current_event.callback_timeout_intervals): # On the last callback timeout, instead of sending the SMS again, log the missed callback if event is not None: event.status = CALLBACK_MISSED event.save() return True else: # It's the first time sending the sms, so create an expected callback event event = ExpectedCallbackEventLog( domain=reminder.domain, date=reminder.event_initiation_timestamp, couch_recipient_doc_type=recipients[0].doc_type, couch_recipient=recipients[0].get_id, status=CALLBACK_PENDING, ) event.save() return fire_sms_event(reminder, handler, recipients, verified_numbers, workflow=WORKFLOW_CALLBACK) else: # TODO: Implement sms callback for RECIPIENT_OWNER and RECIPIENT_SURVEY_SAMPLE return False
def fire_sms_callback_event(reminder, handler, recipients, verified_numbers): current_event = reminder.current_event for recipient in recipients: send_message = False if reminder.callback_try_count > 0: if reminder.event_initiation_timestamp: event = ExpectedCallbackEventLog.view("sms/expected_callback_event", key=[reminder.domain, json_format_datetime(reminder.event_initiation_timestamp), recipient.get_id], include_docs=True, limit=1).one() if not event: continue if event.status == CALLBACK_RECEIVED: continue if CallLog.inbound_entry_exists(recipient.doc_type, recipient.get_id, reminder.event_initiation_timestamp): event.status = CALLBACK_RECEIVED event.save() continue else: continue if (reminder.callback_try_count >= len(current_event.callback_timeout_intervals)): # On the last callback timeout, instead of sending the SMS # again, log the missed callback if event: event.status = CALLBACK_MISSED event.save() else: send_message = True else: # It's the first time sending the sms, so create an expected # callback event send_message = True event = ExpectedCallbackEventLog( domain=reminder.domain, date=reminder.event_initiation_timestamp, couch_recipient_doc_type=recipient.doc_type, couch_recipient=recipient.get_id, status=CALLBACK_PENDING, ) event.save() if send_message: fire_sms_event(reminder, handler, [recipient], verified_numbers, workflow=WORKFLOW_CALLBACK) return True
def fire_sms_callback_event(reminder, handler, recipients, verified_numbers): current_event = reminder.current_event if handler.recipient in [RECIPIENT_CASE, RECIPIENT_USER]: # If there are no recipients, just move to the next reminder event if len(recipients) == 0: return True # If the callback has been received, skip sending the next timeout message if reminder.callback_try_count > 0: # Lookup the expected callback event if reminder.event_initiation_timestamp is None: event = None else: event = ExpectedCallbackEventLog.view("sms/expected_callback_event", key=[reminder.domain, json_format_datetime(reminder.event_initiation_timestamp), recipients[0].get_id], include_docs=True, limit=1).one() # NOTE: If last_fired is None, it means that the reminder fired for the first time on a timeout interval if reminder.last_fired is not None and CallLog.inbound_entry_exists(recipients[0].doc_type, recipients[0].get_id, reminder.last_fired): reminder.skip_remaining_timeouts = True if event is not None: event.status = CALLBACK_RECEIVED event.save() return True elif reminder.callback_try_count >= len(current_event.callback_timeout_intervals): # On the last callback timeout, instead of sending the SMS again, log the missed callback if event is not None: event.status = CALLBACK_MISSED event.save() return True else: # It's the first time sending the sms, so create an expected callback event event = ExpectedCallbackEventLog( domain = reminder.domain, date = reminder.event_initiation_timestamp, couch_recipient_doc_type = recipients[0].doc_type, couch_recipient = recipients[0].get_id, status = CALLBACK_PENDING, ) event.save() return fire_sms_event(reminder, handler, recipients, verified_numbers, workflow=WORKFLOW_CALLBACK) else: # TODO: Implement sms callback for RECIPIENT_OWNER and RECIPIENT_SURVEY_SAMPLE return False