diff --git a/apps/notification/utils.py b/apps/notification/utils.py index ddbc37b4..bc206a13 100644 --- a/apps/notification/utils.py +++ b/apps/notification/utils.py @@ -1,4 +1,7 @@ +from twilio.rest import Client + from django.core.mail import EmailMessage +from django.conf import settings from django.template.loader import get_template @@ -7,3 +10,8 @@ def send_email(subject, to_email, template_name, **kwargs): email = EmailMessage(subject, html, to=[to_email]) email.content_subtype = 'html' email.send() + + +def send_sms(message, phone): + client = Client(settings.TWILIO_ACCOUNT, settings.TWILIO_TOKEN) + client.messages.create(to=phone, from_=settings.TWILIO_FROM_PHONE, body=message) diff --git a/project/settings.py b/project/settings.py index 60a345a9..b9ca62a9 100644 --- a/project/settings.py +++ b/project/settings.py @@ -136,3 +136,11 @@ ANYMAIL = { } EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" DEFAULT_FROM_EMAIL = "postmaster@mail.9ev.ru" + + +# SMS +# https://github.com/twilio/twilio-python + +TWILIO_ACCOUNT = '' +TWILIO_TOKEN = '' +TWILIO_FROM_PHONE = '' diff --git a/requirements.txt b/requirements.txt index cf6e2289..48f9bdd2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django==2.0.1 django-anymail[mailgun]==1.2 -paymentwall-python==1.0.7 \ No newline at end of file +paymentwall-python==1.0.7 +twilio==6.10.0 \ No newline at end of file