示例#1
0
    def record_dr_from_payload(cls, payload):
        # no DR support in non-DB mode
        if not get_config('use_db'):
            return

        uuid = payload.get('callbackData')
        msg = cls.get_or_none(uuid)
        if msg is None:
            raise ValueError(
                "SMS-DR reference unreachable SMS-MT `{uuid}`".format(
                    uuid=uuid))
        kwargs = {
            'sms_type':
            cls.DR,
            'delivery_status_on':
            aware_datetime_from_iso(
                payload.get('delivery_status_on',
                            datetime_to_iso(timezone.now()))),
            'status':
            cls.DELIVERY_STATUS_MATRIX.get(
                payload.get('deliveryInfo', {}).get('deliveryStatus',
                                                    cls.NOT_DELIVERED))
        }
        msg.update(**kwargs)
        msg.save()
        return msg
示例#2
0
    def create_mo_from_payload(cls, payload):
        kwargs = {
            'direction': cls.INCOMING,
            'sms_type': cls.MO,
            'status': cls.RECEIVED,

            'sender_address': cls.clean_address(payload.get('senderAddress')),
            'destination_address':
                cls.clean_address(payload.get('destinationAddress')),
            'message_id': payload.get('messageId'),
            'content': payload.get('message'),
            'created_on': aware_datetime_from_iso(payload.get('dateTime'))
        }
        if not get_config('use_db'):
            return cls(**kwargs)
        return cls.objects.create(**kwargs)
示例#3
0
 def create_mo_from_payload(cls, payload):
     kwargs = {
         'direction':
         cls.INCOMING,
         'sms_type':
         cls.MO,
         'status':
         cls.RECEIVED,
         'sender_address':
         cls.clean_address(payload.get('senderAddress')),
         'destination_address':
         cls.clean_address(payload.get('destinationAddress')),
         'message_id':
         payload.get('messageId'),
         'content':
         payload.get('message'),
         'created_on':
         aware_datetime_from_iso(payload.get('dateTime'))
     }
     if not get_config('use_db'):
         return cls(**kwargs)
     return cls.objects.create(**kwargs)
示例#4
0
    def record_dr_from_payload(cls, payload):
        # no DR support in non-DB mode
        if not get_config('use_db'):
            return

        uuid = payload.get('callbackData')
        msg = cls.get_or_none(uuid)
        if msg is None:
            raise ValueError("SMS-DR reference unreachable SMS-MT `{uuid}`"
                             .format(uuid=uuid))
        kwargs = {
            'sms_type': cls.DR,
            'delivery_status_on': aware_datetime_from_iso(
                payload.get('delivery_status_on',
                            datetime_to_iso(timezone.now()))),
            'status': cls.DELIVERY_STATUS_MATRIX.get(
                payload.get('deliveryInfo', {})
                       .get('deliveryStatus', cls.NOT_DELIVERED))
        }
        msg.update(**kwargs)
        msg.save()
        return msg