diff --git a/shiftregister/app/tasks.py b/shiftregister/app/tasks.py index 02dce9e..cc7e88a 100644 --- a/shiftregister/app/tasks.py +++ b/shiftregister/app/tasks.py @@ -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()