|
|
|
@ -2,9 +2,13 @@ import json
|
|
|
|
|
from ast import literal_eval
|
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
|
|
|
|
from clicksend_client import ApiClient
|
|
|
|
|
from clicksend_client import Configuration as BaseConfiguration
|
|
|
|
|
from clicksend_client import SMSApi, SmsMessage, SmsMessageCollection
|
|
|
|
|
from clicksend_client import (
|
|
|
|
|
ApiClient,
|
|
|
|
|
Configuration,
|
|
|
|
|
SMSApi,
|
|
|
|
|
SmsMessage,
|
|
|
|
|
SmsMessageCollection,
|
|
|
|
|
)
|
|
|
|
|
from clicksend_client.rest import ApiException
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
@ -19,29 +23,6 @@ __all__ = ("Receiver", "Sender")
|
|
|
|
|
MAX_BATCH_SIZE = 1000 # see https://developers.clicksend.com/docs/rest/v3/#how-many-messages-can-i-send
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Configuration(BaseConfiguration):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
for setting in (
|
|
|
|
|
"clicksend_password",
|
|
|
|
|
"clicksend_sender_id",
|
|
|
|
|
"clicksend_username",
|
|
|
|
|
):
|
|
|
|
|
try:
|
|
|
|
|
settings.SMS_SETTINGS[setting]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
|
f"'{setting}' must be set in SMS_SETTINGS for ClickSend backend"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.username = settings.SMS_SETTINGS["clicksend_username"]
|
|
|
|
|
self.password = settings.SMS_SETTINGS["clicksend_password"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = ApiClient(Configuration())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Receiver(BaseReceiver):
|
|
|
|
|
fetch = None
|
|
|
|
|
|
|
|
|
@ -66,11 +47,30 @@ class Receiver(BaseReceiver):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Sender(BaseSender):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
for setting in (
|
|
|
|
|
"clicksend_password",
|
|
|
|
|
"clicksend_sender_id",
|
|
|
|
|
"clicksend_username",
|
|
|
|
|
):
|
|
|
|
|
try:
|
|
|
|
|
settings.SMS_SETTINGS[setting]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
|
f"'{setting}' must be set in SMS_SETTINGS for ClickSend backend"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
config = Configuration()
|
|
|
|
|
config.username = settings.SMS_SETTINGS["clicksend_username"]
|
|
|
|
|
config.password = settings.SMS_SETTINGS["clicksend_password"]
|
|
|
|
|
|
|
|
|
|
self.client = ApiClient(config)
|
|
|
|
|
|
|
|
|
|
def send(self, messages):
|
|
|
|
|
messages = messages[:MAX_BATCH_SIZE]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
response = SMSApi(client).sms_send_post(
|
|
|
|
|
response = SMSApi(self.client).sms_send_post(
|
|
|
|
|
SmsMessageCollection(
|
|
|
|
|
messages=[
|
|
|
|
|
SmsMessage(
|
|
|
|
|