mobin sms client
This commit is contained in:
parent
b8a57a0ce4
commit
4b277bc95f
2 changed files with 36 additions and 1 deletions
|
|
@ -48,7 +48,7 @@ INSTALLED_APPS = [
|
||||||
'crispy_forms',
|
'crispy_forms',
|
||||||
'crispy_bootstrap5',
|
'crispy_bootstrap5',
|
||||||
'django_filters',
|
'django_filters',
|
||||||
'jalali_date',
|
# 'jalali_date',
|
||||||
'django_minio_backend.apps.DjangoMinioBackendConfig',
|
'django_minio_backend.apps.DjangoMinioBackendConfig',
|
||||||
|
|
||||||
# local apps
|
# local apps
|
||||||
|
|
@ -408,3 +408,4 @@ MINIO_PUBLIC_BUCKETS = [
|
||||||
MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = []
|
MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = []
|
||||||
MINIO_BUCKET_CHECK_ON_SAVE = True # Default: True // Creates bucket if missing, then save
|
MINIO_BUCKET_CHECK_ON_SAVE = True # Default: True // Creates bucket if missing, then save
|
||||||
|
|
||||||
|
MOBIN_SMS_TOKEN = config('MOBIN_SMS_TOKEN', default='')
|
||||||
34
utils/clients/mobin_sms/client.py
Normal file
34
utils/clients/mobin_sms/client.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import urllib.parse
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class MobinSMSClient:
|
||||||
|
access_token = settings.MOBIN_SMS_TOKEN
|
||||||
|
base_url = 'https://connect.mobinsms.com'
|
||||||
|
sender = '9890008050'
|
||||||
|
|
||||||
|
def send_sms(self, phone_number, message):
|
||||||
|
return self.send_sms_quick([phone_number], message)
|
||||||
|
|
||||||
|
def send_sms_quick(self, phone_number_list, message):
|
||||||
|
path = '/v1/send/quick'
|
||||||
|
url = urllib.parse.urljoin(self.base_url, path)
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"from": self.sender,
|
||||||
|
"to": phone_number_list,
|
||||||
|
"body": message,
|
||||||
|
"unique_id": "" # UDH (optional field)
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"X-API-Key": self.access_token,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, json=body, timeout=10)
|
||||||
|
print(response.text)
|
||||||
|
return response.json()
|
||||||
Loading…
Add table
Reference in a new issue