notification client
This commit is contained in:
parent
0d59ac63fc
commit
f7da29a900
5 changed files with 39 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ from rest_framework.exceptions import APIException
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS
|
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS
|
||||||
|
from utils.notifications_client import notification_client
|
||||||
|
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
|
|
@ -169,7 +170,7 @@ class User(AbstractUser):
|
||||||
self.notify(sms_body)
|
self.notify(sms_body)
|
||||||
|
|
||||||
def notify(self, body, notification_type='sms'):
|
def notify(self, body, notification_type='sms'):
|
||||||
pass
|
notification_client.notify(phone_number=self.phone_number, body=body)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Deployment script
|
# Deployment script
|
||||||
sudo apt-get install libmariadbclient-dev
|
apt install libmysqlclient-dev
|
||||||
|
apt install libssl-dev
|
||||||
|
apt install libcrypto++-dev
|
||||||
|
apt install lsb-release
|
||||||
|
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
|
|
|
||||||
|
|
@ -153,3 +153,8 @@ MEDIA_URL = "/media/"
|
||||||
|
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
NOTIFICATIONS_SERVICE_URL = 'https://notifications.gooyal.com'
|
||||||
|
CLIENT_ID = 'wDGC6ZtKXxUvVMP0tUg8DYbtgAD0It8o3TCWjY05'
|
||||||
|
CLIENT_SECRET = 'NBmm8FCzKCYLhMIN3LQ7LoZ3nonnjLvQkVP96MYGAGc5LQSCmdOXbfWP8tdbPBihPOhqW3Fk96tpaQVM6NyJBQCS2qvigE9Vp2RaqKUPM6QhvGI3GT5itT6Rwv5iO4JX'
|
||||||
|
ACCESS_TOKEN = 'Px7WLUKoynua6qJq5IkIG8Fn5dPLXq'
|
||||||
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
28
utils/notifications_client.py
Normal file
28
utils/notifications_client.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import requests
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationClient():
|
||||||
|
def notify(self, phone_number, body):
|
||||||
|
data = {
|
||||||
|
'phone_number': phone_number,
|
||||||
|
'body': body
|
||||||
|
}
|
||||||
|
# data = json.dumps(data)
|
||||||
|
header = {
|
||||||
|
# "Content-Type": "application/json",
|
||||||
|
"charset": "utf-8"
|
||||||
|
}
|
||||||
|
header.setdefault("Authorization", f"Bearer {settings.ACCESS_TOKEN}", )
|
||||||
|
|
||||||
|
response = requests.request('post',
|
||||||
|
f'{settings.NOTIFICATIONS_SERVICE_URL}/notifications/',
|
||||||
|
headers=header,
|
||||||
|
json=data)
|
||||||
|
try:
|
||||||
|
return response.json()
|
||||||
|
except:
|
||||||
|
return response.text
|
||||||
|
|
||||||
|
|
||||||
|
notification_client = NotificationClient()
|
||||||
Loading…
Add table
Reference in a new issue