Example #1
0
def send_message_task(to_number, text, media, priority):
    sms = SMS()

    try:
        receiver = PhoneReceiver.objects.get(number=to_number)
    except PhoneReceiver.DoesNotExist:
        service_number = sms.get_service_number()
        receiver = PhoneReceiver.objects.create(number=to_number,
                                                service_number=service_number)

    obj = PhoneSent()
    obj.receiver = receiver
    obj.text = six.text_type(clean_text(text))
    obj.media_raw = media
    obj.status = PhoneSent.STATUS_QUEUED

    if receiver.is_blocked:
        obj.status = PhoneSent.STATUS_FAILED
        obj.save()
        return

    obj.save()

    data = {
        "from_phone": obj.receiver.service_number,
        "priority": priority,
        "message": obj,
    }
    PhonePendingMessages.objects.create(**data)
Example #2
0
    def send(self):
        if self.status not in [PhoneSent.STATUS_QUEUED, PhoneSent.STATUS_PENDING]:
            return

        from universal_notifications.backends.sms.base import SMS
        sms = SMS()
        sms.send(self)
Example #3
0
 def save(self, *args, **kwargs):
     created = not self.id
     self.from_phone = format_phone(self.from_phone)
     ret = super(PhonePendingMessages, self).save(*args, **kwargs)
     if created:
         from universal_notifications.backends.sms.base import SMS
         sms = SMS()
         sms.add_to_queue(self)
     return ret
    def parse_received_message_task(message_id):
        try:
            raw = PhoneReceivedRaw.objects.get(id=message_id, status=PhoneReceivedRaw.STATUS_PENDING)
        except PhoneReceivedRaw.DoesNotExist:
            return

        try:
            sms = SMS()
            if sms.parse_received(raw):
                raw.status = PhoneReceivedRaw.STATUS_PASS
                raw.save()
        except Exception:
            raw.status = PhoneReceivedRaw.STATUS_FAIL
            raw.exception = traceback.format_exc()
            raw.save()