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 = ExpectedCallback.by_domain_recipient_date(
                    reminder.domain,
                    recipient.get_id,
                    reminder.event_initiation_timestamp
                )
                if not event:
                    continue
                if event.status == CALLBACK_RECEIVED:
                    continue
                if Call.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 = ExpectedCallback.objects.create(
                domain=reminder.domain,
                date=reminder.event_initiation_timestamp,
                couch_recipient_doc_type=recipient.doc_type,
                couch_recipient=recipient.get_id,
                status=CALLBACK_PENDING,
            )

        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,
                            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 = ExpectedCallback.by_domain_recipient_date(
                    reminder.domain, recipient.get_id,
                    reminder.event_initiation_timestamp)
                if not event:
                    continue
                if event.status == CALLBACK_RECEIVED:
                    continue
                if Call.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 = ExpectedCallback.objects.create(
                domain=reminder.domain,
                date=reminder.event_initiation_timestamp,
                couch_recipient_doc_type=recipient.doc_type,
                couch_recipient=recipient.get_id,
                status=CALLBACK_PENDING,
            )

        if send_message:
            fire_sms_event(reminder,
                           handler, [recipient],
                           verified_numbers,
                           logged_event,
                           workflow=WORKFLOW_CALLBACK)