|
|
@ -12,7 +12,15 @@ __all__ = ("Receiver", "Sender")
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL = "https://api.sipgate.com/v2"
|
|
|
|
BASE_URL = "https://api.sipgate.com/v2"
|
|
|
|
|
|
|
|
|
|
|
|
auth = HTTPBasicAuth(
|
|
|
|
inbound_auth = HTTPBasicAuth(
|
|
|
|
|
|
|
|
settings.SMS_SETTINGS.get(
|
|
|
|
|
|
|
|
"sipgate_incoming_token_id", settings.SIPGATE_INCOMING_TOKEN_ID
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
settings.SMS_SETTINGS.get(
|
|
|
|
|
|
|
|
"sipgate_incoming_token", settings.SIPGATE_INCOMING_TOKEN
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
outbound_auth = HTTPBasicAuth(
|
|
|
|
settings.SMS_SETTINGS.get("sipgate_token_id", settings.SIPGATE_TOKEN_ID),
|
|
|
|
settings.SMS_SETTINGS.get("sipgate_token_id", settings.SIPGATE_TOKEN_ID),
|
|
|
|
settings.SMS_SETTINGS.get("sipgate_token", settings.SIPGATE_TOKEN),
|
|
|
|
settings.SMS_SETTINGS.get("sipgate_token", settings.SIPGATE_TOKEN),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -41,7 +49,9 @@ class Receiver(BaseReceiver):
|
|
|
|
total = 10
|
|
|
|
total = 10
|
|
|
|
while offset < total:
|
|
|
|
while offset < total:
|
|
|
|
r = requests.get(
|
|
|
|
r = requests.get(
|
|
|
|
f"{BASE_URL}/history", auth=auth, params=params | {"offset": offset}
|
|
|
|
f"{BASE_URL}/history",
|
|
|
|
|
|
|
|
auth=inbound_auth,
|
|
|
|
|
|
|
|
params=params | {"offset": offset},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
r.raise_for_status()
|
|
|
|
r.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +79,7 @@ class Sender(BaseSender):
|
|
|
|
for message in messages:
|
|
|
|
for message in messages:
|
|
|
|
r = requests.post(
|
|
|
|
r = requests.post(
|
|
|
|
f"{BASE_URL}/sessions/sms",
|
|
|
|
f"{BASE_URL}/sessions/sms",
|
|
|
|
auth=auth,
|
|
|
|
auth=outbound_auth,
|
|
|
|
json={
|
|
|
|
json={
|
|
|
|
"smsId": settings.SMS_SETTINGS.get(
|
|
|
|
"smsId": settings.SMS_SETTINGS.get(
|
|
|
|
"sipgate_sms_extension", settings.SIPGATE_SMS_EXTENSION
|
|
|
|
"sipgate_sms_extension", settings.SIPGATE_SMS_EXTENSION
|
|
|
|