Esempio n. 1
0
def smsdr(request, **options):

    def failure(code, text, msg=None):
        payload = {
            'status': 'error',
            'reason': text
        }
        if msg is not None:
            payload.update({'message_id': msg.suuid})
        return JsonResponse(payload, status=code)

    try:
        payload = jsonloads(request.body)['deliveryInfoNotification']
        msg = SMSMessage.record_dr_from_payload(payload)
    except:
        return failure(400, "Incorrect JSON payload")

    try:
        handle_smsdr(msg)
    except Exception as e:
        error_text = "Exception in SMS-DR processing #{}".format(msg.suuid)
        logger.error(error_text)
        logger.exception(e)
        return failure(500, error_text, msg)

    return JsonResponse({'status': 'success',
                         'message_id': msg.suuid}, status=200)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
def send_sms(to_addr, message,
             as_addr=get_config('default_sender_name'),
             db_save=get_config('use_db')):
    ''' SMS-MT shortcut function '''
    to_addr = cleaned_msisdn(to_addr)
    if not db_save:
        return submit_sms_mt(to_addr, message, as_addr)
    msg = SMSMessage.create_mt(to_addr, message,
                               as_addr, SMSMessage.PENDING)
    success = submit_sms_mt_request(msg.to_mt(), msg)
    msg.sending_status = msg.SENT if success else msg.FAILED_TO_SEND
    msg.save()
    return success, msg
Esempio n. 5
0
def smsdr(request, **options):

    payload = json.loads(request.body)['deliveryInfoNotification']

    msg = SMSMessage.record_dr_from_payload(payload)

    try:
        handle_smsdr(msg)
    except Exception as e:
        logger.error("Exception in SMS-DR processing #{}".format(msg.suuid))
        logger.exception(e)
        status = 301
    else:
        status = 200

    return JsonResponse({"UUID": msg.suuid}, status=status)
Esempio n. 6
0
def smsmo(request, **options):

    payload = json.loads(request.body)[
        'inboundSMSMessageNotification']['inboundSMSMessage']

    msg = SMSMessage.create_mo_from_payload(payload)

    try:
        handle_smsmo(msg)
    except Exception as e:
        logger.error("Exception in SMS-MO processing #{}".format(msg.suuid))
        logger.exception(e)
        status = 301
    else:
        status = 200

    return JsonResponse({"UUID": msg.suuid}, status=status)