Exemple #1
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
Exemple #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)
Exemple #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)