accounts/apps/users/tasks.py
2022-09-02 12:12:14 +04:30

28 lines
942 B
Python

from celery import shared_task
from django.conf import settings
# from service_clients import Client, AccountsClient
# SCOPES = ['notifications.notification:submit']
# client = Client(client_id=settings.CLIENT_ID,
# client_secret=settings.CLIENT_SECRET,
# scopes=SCOPES,
# grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS)
@shared_task
def send_notification(phone_number=None,
title=None,
body=None,
user_uuid=None,
email=None,
notification_type=1):
data = {
'phone_number': phone_number,
"body": f'{title}:\n{body}'
}
try:
print(client.request(required_scopes=SCOPES, url=f'{settings.BASE_NOTIFICATION_URL}/notifications/', data=data,
method='post', timeout=5).text)
except Exception as e:
print(e)