add retry sms manually

This commit is contained in:
javad committed 2026-09-23 18:23:18 +03:30
1 parent 33930e972c
commit cb92abbb41
42 files changed
+1628 -1484

No files matched your search

+37 -37
View File
@@ -1,37 +1,37 @@
# Generated by Django 5.1.1 on 2026-09-05 07:03
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('tickets', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='NotificationJob',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('channel', models.CharField(choices=[('SMS', 'پیامک'), ('BALE', 'بله')], max_length=10)),
('event_type', models.CharField(max_length=50)),
('payload', models.JSONField(default=dict)),
('status', models.CharField(choices=[('PENDING', 'در صف'), ('PROCESSING', 'در حال ارسال'), ('SENT', 'ارسال\u200cشده'), ('FAILED', 'ناموفق')], db_index=True, default='PENDING', max_length=15)),
('attempts', models.PositiveSmallIntegerField(default=0)),
('next_attempt_at', models.DateTimeField(db_index=True)),
('last_error', models.TextField(blank=True)),
('dedupe_key', models.CharField(max_length=200, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('sent_at', models.DateTimeField(blank=True, null=True)),
('customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='customer_notifications', to=settings.AUTH_USER_MODEL)),
('staff_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='staff_notifications', to=settings.AUTH_USER_MODEL)),
('ticket', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tickets.ticket')),
],
),
]
# Generated by Django 5.1.1 on 2026-09-05 07:03
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('tickets', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='NotificationJob',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('channel', models.CharField(choices=[('SMS', 'پیامک'), ('BALE', 'بله')], max_length=10)),
('event_type', models.CharField(max_length=50)),
('payload', models.JSONField(default=dict)),
('status', models.CharField(choices=[('PENDING', 'در صف'), ('PROCESSING', 'در حال ارسال'), ('SENT', 'ارسال\u200cشده'), ('FAILED', 'ناموفق')], db_index=True, default='PENDING', max_length=15)),
('attempts', models.PositiveSmallIntegerField(default=0)),
('next_attempt_at', models.DateTimeField(db_index=True)),
('last_error', models.TextField(blank=True)),
('dedupe_key', models.CharField(max_length=200, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('sent_at', models.DateTimeField(blank=True, null=True)),
('customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='customer_notifications', to=settings.AUTH_USER_MODEL)),
('staff_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='staff_notifications', to=settings.AUTH_USER_MODEL)),
('ticket', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tickets.ticket')),
],
),
]
@@ -1,6 +1,6 @@
# Generated by Django 5.1.1 on 2026-09-07 04:56
import apps.core.models
# Generated by Django 5.1.1 on 2026-09-07 04:56
import apps.core.models
from django.db import migrations, models
TAGS=["magic_link","first_name","last_name","ticket_number","subject","province","city","expert_name"]
@@ -14,26 +14,26 @@ def seed_sms_templates(apps,schema_editor):
for event,(title,body) in DEFAULTS.items(): model.objects.get_or_create(event_type=event,defaults={"title":title,"body":body,"allowed_tags":TAGS})
def remove_sms_templates(apps,schema_editor):
apps.get_model("notifications","SMSTemplate").objects.filter(event_type__in=DEFAULTS).delete()
class Migration(migrations.Migration):
dependencies = [
('notifications', '0001_initial'),
]
operations = [
class Migration(migrations.Migration):
dependencies = [
('notifications', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='SMSTemplate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('event_type', models.CharField(choices=[('CUSTOMER_TICKET_CREATED', 'ثبت تیکت توسط مشتری'), ('STAFF_TICKET_CREATED', 'ثبت تیکت توسط کارشناس'), ('STAFF_REPLY', 'پاسخ کارشناس')], max_length=50, unique=True)),
('title', models.CharField(max_length=120)),
('body', models.TextField(help_text='تگ\u200cها را مانند {magic_link} در متن قرار دهید.')),
('allowed_tags', models.JSONField(blank=True, default=list)),
('is_active', models.BooleanField(default=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
name='SMSTemplate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('event_type', models.CharField(choices=[('CUSTOMER_TICKET_CREATED', 'ثبت تیکت توسط مشتری'), ('STAFF_TICKET_CREATED', 'ثبت تیکت توسط کارشناس'), ('STAFF_REPLY', 'پاسخ کارشناس')], max_length=50, unique=True)),
('title', models.CharField(max_length=120)),
('body', models.TextField(help_text='تگ\u200cها را مانند {magic_link} در متن قرار دهید.')),
('allowed_tags', models.JSONField(blank=True, default=list)),
('is_active', models.BooleanField(default=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
bases=(apps.core.models.PersianTextNormalizationMixin, models.Model),
),
migrations.RunPython(seed_sms_templates,remove_sms_templates),
@@ -1,33 +1,33 @@
# Generated by Django 5.1.1 on 2026-09-08 09:57
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0004_customer_reply_bale_policy'),
('staff', '0004_organizationalunit_staffprofile_primary_unit_and_more'),
]
operations = [
migrations.AddField(
model_name='smstemplate',
name='unit',
field=models.ForeignKey(blank=True, help_text='خالی یعنی الگوی عمومی و fallback.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='sms_templates', to='staff.organizationalunit'),
),
migrations.AlterField(
model_name='smstemplate',
name='event_type',
field=models.CharField(choices=[('CUSTOMER_TICKET_CREATED', 'ثبت تیکت توسط مشتری'), ('STAFF_TICKET_CREATED', 'ثبت تیکت توسط کارشناس'), ('STAFF_REPLY', 'پاسخ کارشناس')], max_length=50),
),
migrations.AddConstraint(
model_name='smstemplate',
constraint=models.UniqueConstraint(fields=('unit', 'event_type'), name='unique_sms_template_per_unit'),
),
migrations.AddConstraint(
model_name='smstemplate',
constraint=models.UniqueConstraint(condition=models.Q(('unit__isnull', True)), fields=('event_type',), name='unique_global_sms_template_event'),
),
]
# Generated by Django 5.1.1 on 2026-09-08 09:57
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0004_customer_reply_bale_policy'),
('staff', '0004_organizationalunit_staffprofile_primary_unit_and_more'),
]
operations = [
migrations.AddField(
model_name='smstemplate',
name='unit',
field=models.ForeignKey(blank=True, help_text='خالی یعنی الگوی عمومی و fallback.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='sms_templates', to='staff.organizationalunit'),
),
migrations.AlterField(
model_name='smstemplate',
name='event_type',
field=models.CharField(choices=[('CUSTOMER_TICKET_CREATED', 'ثبت تیکت توسط مشتری'), ('STAFF_TICKET_CREATED', 'ثبت تیکت توسط کارشناس'), ('STAFF_REPLY', 'پاسخ کارشناس')], max_length=50),
),
migrations.AddConstraint(
model_name='smstemplate',
constraint=models.UniqueConstraint(fields=('unit', 'event_type'), name='unique_sms_template_per_unit'),
),
migrations.AddConstraint(
model_name='smstemplate',
constraint=models.UniqueConstraint(condition=models.Q(('unit__isnull', True)), fields=('event_type',), name='unique_global_sms_template_event'),
),
]
@@ -1,6 +1,6 @@
# Generated by Django 5.1.1 on 2026-09-08 10:05
import apps.notifications.models
# Generated by Django 5.1.1 on 2026-09-08 10:05
import apps.notifications.models
from django.db import migrations, models
TAGS = ["magic_link", "first_name", "last_name", "recipient_name", "unit_name", "company_name", "ticket_number", "subject", "province", "city", "expert_name"]
@@ -14,15 +14,15 @@ def add_supported_tags(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('notifications', '0005_smstemplate_unit_alter_smstemplate_event_type_and_more'),
]
operations = [
dependencies = [
('notifications', '0005_smstemplate_unit_alter_smstemplate_event_type_and_more'),
]
operations = [
migrations.AlterField(
model_name='smstemplate',
name='allowed_tags',
model_name='smstemplate',
name='allowed_tags',
field=models.JSONField(blank=True, default=apps.notifications.models.sms_template_tags),
),
migrations.RunPython(add_supported_tags, migrations.RunPython.noop),
@@ -1,24 +1,24 @@
# Generated by Django 5.1.1 on 2026-09-08 15:32
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0006_alter_smstemplate_allowed_tags'),
('tickets', '0006_assign_legacy_contacts_to_sales'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddIndex(
model_name='notificationjob',
index=models.Index(fields=['status', 'next_attempt_at'], name='notif_due_idx'),
),
migrations.AddIndex(
model_name='notificationjob',
index=models.Index(fields=['ticket', 'channel', 'status'], name='notif_ticket_chan_idx'),
),
]
# Generated by Django 5.1.1 on 2026-09-08 15:32
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0006_alter_smstemplate_allowed_tags'),
('tickets', '0006_assign_legacy_contacts_to_sales'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddIndex(
model_name='notificationjob',
index=models.Index(fields=['status', 'next_attempt_at'], name='notif_due_idx'),
),
migrations.AddIndex(
model_name='notificationjob',
index=models.Index(fields=['ticket', 'channel', 'status'], name='notif_ticket_chan_idx'),
),
]
@@ -1,18 +1,18 @@
# Generated by Django 5.1.1 on 2026-09-08 15:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0007_notificationjob_notif_due_idx_and_more'),
]
operations = [
migrations.AddField(
model_name='notificationjob',
name='provider_message_id',
field=models.CharField(blank=True, max_length=500),
),
]
# Generated by Django 5.1.1 on 2026-09-08 15:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notifications', '0007_notificationjob_notif_due_idx_and_more'),
]
operations = [
migrations.AddField(
model_name='notificationjob',
name='provider_message_id',
field=models.CharField(blank=True, max_length=500),
),
]