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
def handle_request(active_form, form): if active_form == 'smsmt': success, msg = send_sms( to_addr=form.cleaned_data.get('destination_address'), message=form.cleaned_data.get('content'), as_addr=form.cleaned_data.get('sender_name') or get_config('default_sender_name')) handle_smsmt(msg) return success, "Sent {}".format(msg) elif active_form == 'fsmsmt': msg = SMSMessage.create_mt( destination_address=form.cleaned_data.get( 'destination_address'), content=form.cleaned_data.get('content'), sender_address=form.cleaned_data.get('sender_address'), sending_status=form.cleaned_data.get('status')) handle_smsmo(msg) return True, "Sent {}".format(msg) elif active_form == 'fsmsmo': msg = SMSMessage.create_mo_from_payload({ 'senderAddress': "tel:{}".format( form.cleaned_data.get('sender_address')), 'destinationAddress': form.cleaned_data.get( 'destination_address'), 'messageId': form.cleaned_data.get('message_id') or None, 'message': form.cleaned_data.get('content'), 'dateTime': datetime_to_iso( form.cleaned_data.get('created_on')) }) handle_smsmo(msg) return True, "Received {}".format(msg) elif active_form == 'fsmsdr': msg = SMSMessage.record_dr_from_payload({ 'callbackData': form.cleaned_data.get('uuid'), 'delivery_status_on': datetime_to_iso( form.cleaned_data.get('delivery_on')), 'deliveryInfo': { 'deliveryStatus': form.cleaned_data.get('status') } }) return True, "Updated {}".format(msg) else: return False, "Unknown action `{}`".format(active_form)
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