Beispiel #1
0
    def test_send_pattern(self):
        http_client = Mock()

        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "bulk_id": 70671101
            }
        }
        '''))

        sms = Client("", http_client)
        bulk_id = sms.send_pattern("6gr7ngjmhi", "9810001", "+98912xxxxxxx",
                                   {"name": "IPPanel"})

        http_client.post.assert_called_once_with(
            "/v1/messages/patterns/send", {
                "pattern_code": "6gr7ngjmhi",
                "originator": "9810001",
                "recipient": "+98912xxxxxxx",
                "values": {
                    "name": "IPPanel"
                },
            })

        self.assertEqual(bulk_id, 70671101)
Beispiel #2
0
class Sms:
    def __init__(self):
        self.phone = "+9810009589"
        self.api_key = "w-_o3HD2Uz5D-UtibVcGj4q5R4_POJhpVeXrZC2NjZE="
        self.pattern_code = "e06081mqm5"
        self.client = Client(self.api_key)

    def send_code(self, verify_code, recipient_number):
        pattern_val = {'verify': str(verify_code)}
        try:
            resp = self.client.send_pattern(self.pattern_code, self.phone,
                                            recipient_number, pattern_val)
            return True, resp
        except Error as e:
            return ('error: {}'.format(e))
Beispiel #3
0
class SMS:
    def __init__(self):
        api_key = "YMQm7ifbEWxFEcStuyBA7yppiRJFgLjBioWOxdU8P1c="
        self.sms = Client(api_key)

    def send(self, phone):
        code = opt_generator(5)

        pattern_values = {"code": code}
        bulk_id = self.sms.send_pattern(
            "4tprjx5g44",  # pattern code
            "+982000505",  # originator
            phone,  # recipient
            pattern_values,  # pattern values
        )
        print('Sent ', bulk_id)
        return code
Beispiel #4
0
def send_sms(phoneNumber, code):
	client = Client(config.IPPANEL_API_KEY)

	pattern_values = {"code": code}
	try:
		bulk_id = client.send_pattern(
			config.SMS_PATTERN_CODE,	# pattern code
			config.SMS_ORIGINATOR,	  # originator
			phoneNumber,  # recipient
			pattern_values,  # pattern values
		)
		return(bulk_id)
	except Error as e:
		print("Error handled => code: %s, message: %s" % (e.code, e.message))
		if e.code == ResponseCode.ErrUnprocessableEntity.value:
			for field in e.message:
				print("Field: %s , Errors: %s" % (field, e.message[field]))
	except HTTPError as e:
		print("Error handled => code: %s" % (e))
	return (None)