How to use the africastalking.Service.validate_phone function in africastalking

To help you get started, we’ve selected a few africastalking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AfricasTalkingLtd / africastalking-python / africastalking / Voice.py View on Github external
def call(self, source, destination, callback=None):

        phone_numbers = destination.split(',')

        for index, phone_number in enumerate(phone_numbers):
            phone_number = phone_number.replace(' ', '')

            if not validate_phone(phone_number):
                raise ValueError(
                    f'Invalid destination phone number: {phone_number}')

            phone_numbers[index] = phone_number

        destination = ','.join(phone_numbers)

        url = self._make_url('/call')
        data = {
            'username': self._username,
            'from': source,
            'to': destination,
        }
        return self._make_request(url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / SMS.py View on Github external
def create_subscription(self, short_code, keyword, phone_number, checkout_token, callback=None):

        if not validate_phone(phone_number):
            raise ValueError('Invalid phone number')

        url = self._make_url('/subscription/create', content=True)
        data = {
            'username': self._username,
            'shortCode': short_code,
            'keyword': keyword,
            'phoneNumber': phone_number,
            'checkoutToken': checkout_token,
        }

        return self._make_request(url, 'POST', headers=self._headers, data=data, params=None, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / Payment.py View on Github external
                'phoneNumber': And(str, lambda s: validate_phone(s)),
                'currencyCode': And(str, lambda s: len(s) == 3),
github AfricasTalkingLtd / africastalking-python / africastalking / Payment.py View on Github external
            'phoneNumber': And(str, lambda s: validate_phone(s)),
            'quantity': And(lambda f: float(f) > 0),
github AfricasTalkingLtd / africastalking-python / africastalking / SMS.py View on Github external
def delete_subscription(self, short_code, keyword, phone_number, callback=None):

        if not validate_phone(phone_number):
            raise ValueError('Invalid phone number')

        url = self._make_url('/subscription/delete', content=True)
        data = {
            'username': self._username,
            'shortCode': short_code,
            'keyword': keyword,
            'phoneNumber': phone_number
        }

        return self._make_request(url, 'POST', headers=self._headers, data=data, params=None, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / Airtime.py View on Github external
def value_validator(phoneNumber, amount, currency_code):
            if not validate_phone(phoneNumber):
                return 'Invalid phone number'
            elif not validate_amount(amount):
                return 'Invalid amount' 
            elif not validate_currency(currency_code):
                return 'Invalid currency code'
            else:
                return False
github AfricasTalkingLtd / africastalking-python / africastalking / SMS.py View on Github external
def send(self, message, recipients, sender_id=None, enqueue=False, callback=None):

        for phone in recipients:
            if not validate_phone(phone):
                raise ValueError('Invalid phone number: ' + phone)

        url = self._make_url('/messaging')
        data = {
            'username': self._username,
            'to': ','.join(recipients),
            'message': message,
            'bulkSMSMode': 1,
        }

        if sender_id is not None:
            data['from'] = sender_id

        if enqueue:
            data['enqueue'] = 1
github AfricasTalkingLtd / africastalking-python / africastalking / Voice.py View on Github external
def media_upload(self, phone_number, url, callback=None):

        if not validate_phone(phone_number):
            raise ValueError('Invalid phone number')

        call_url = self._make_url('/mediaUpload')
        data = {
            'username': self._username,
            'phoneNumber': phone_number,
            'url': url,
        }
        return self._make_request(call_url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / Voice.py View on Github external
def fetch_queued_calls(self, phone_number, callback=None):

        if not validate_phone(phone_number):
            raise ValueError('Invalid phone number')

        url = self._make_url('/queueStatus')
        data = {
            'username': self._username,
            'phoneNumbers': phone_number,
        }
        return self._make_request(url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / Token.py View on Github external
def create_checkout_token(self, phone_number, callback=None):

        if not validate_phone(phone_number):
            raise ValueError('Invalid phone number')

        url = self._make_url('/checkout/token/create')
        headers = dict(self._headers)
        data = {'phoneNumber': phone_number}

        return self._make_request(url, 'POST', headers, data=data, params=None, callback=callback)