2
0
Fork 0

Actually send SMS if sipgate credentials are set

This commit is contained in:
Luca 2022-04-29 02:14:14 +02:00
parent 826c3a1a7a
commit 3647ecc77a
1 changed files with 11 additions and 2 deletions

View File

@ -1,11 +1,20 @@
from celery import shared_task
from .models import Message, ShiftRegistration
from django.conf import settings
from django.db import transaction
from django.utils import timezone
from dynamic_preferences.registries import global_preferences_registry
from .sipgate.sms import send as send_sms
global_preferences = global_preferences_registry.manager()
def send(msg):
if not (settings.SIPGATE_SMS_EXTENSION and settings.SIPGATE_TOKEN and settings.SIPGATE_TOKEN_ID):
print(f"would send message to {msg.to.phone}\n---\n{msg.text}")
return
send_sms(msg.to.phone, msg.text)
# cron task to send normal messages(reminders,changes) in batches
@shared_task
def send_messages():
@ -16,7 +25,7 @@ def send_messages():
for msg in Message.objects.select_for_update().filter(sent_at__isnull=True):
if msg.sent_at:
continue
print(f"TODO: send message @{msg.to.phone} {msg.text}")
send(msg)
msg.sent_at = timezone.now()
msg.save()
@ -33,7 +42,7 @@ def send_message(msgid):
msg = Message.objects.select_for_update().get(pk=msgid)
if msg.sent_at:
return
print(f"TODO: send message @{msg.to.phone} {msg.text}")
send(msg)
msg.sent_at = timezone.now()
msg.save()