bale group for orgs, and sms for each org

This commit is contained in:
javad committed 2026-09-13 20:47:47 +03:30
1 parent a18a68578f
commit 1ee83374fd
13 files changed
+262 -20

No files matched your search

+18
View File
@@ -5,6 +5,22 @@ from .models import NotificationJob,NotificationPolicy
def enqueue(channel,event_type,ticket,dedupe_key,payload=None,customer=None,staff_user=None):
return NotificationJob.objects.get_or_create(dedupe_key=dedupe_key,defaults={"channel":channel,"event_type":event_type,"ticket":ticket,"payload":payload or {},"customer":customer,"staff_user":staff_user,"next_attempt_at":timezone.now()})[0]
def enqueue_unit_supervisor_ticket_sms(ticket):
"""Queue one concise new-ticket SMS for each configured unit supervisor."""
unit = ticket.owning_unit
if not unit:
return []
return [
enqueue(
NotificationJob.Channel.SMS,
"UNIT_SUPERVISOR_NEW_TICKET",
ticket,
f"ticket:{ticket.pk}:unit-supervisor:{mobile}",
payload={"recipient_mobile": mobile},
)
for mobile in unit.supervisor_mobiles
]
def staff_reply_policy():
return NotificationPolicy.objects.get_or_create(key=NotificationPolicy.Key.STAFF_REPLY_SMS,defaults={"quiet_period_seconds":300})[0]
@@ -40,6 +56,8 @@ def cancel_staff_reply_sms_if_read(ticket,customer):
def schedule_customer_reply_bale(ticket,message):
"""Debounce consecutive customer chat messages into one Bale group alert."""
if not ticket.owning_unit_id or not ticket.owning_unit.bale_chat_id:
return None,False
policy=customer_reply_bale_policy()
if not policy.is_active: return None,False
due=timezone.now()+timedelta(seconds=policy.quiet_period_seconds)