Реализована интеграция с СМС провайдером

This commit is contained in:
mi
2026-07-23 11:49:15 +03:00
parent cc0163eb94
commit b1ed714d5b
89 changed files with 5934 additions and 202 deletions
@@ -0,0 +1,108 @@
"""Seed versioned technical settings and OTP template placeholder.
Revision ID: 0002_seed
"""
import uuid
import sqlalchemy as sa
from alembic import op
revision = "0002_seed"
down_revision = "0001_initial"
branch_labels = None
depends_on = None
TEMPLATE_ID = uuid.UUID("5ac2a77e-590c-4b24-87d8-baa0f1240cd1")
def upgrade() -> None:
bind = op.get_bind()
bind.execute(
sa.text(
"""
INSERT INTO sms.sms_template (
id, code, channel, locale, version, body_template, placeholders,
sender_name, max_parts, is_active, approved_at, created_by
) VALUES (
:id, 'auth_otp', 'SMS', 'ru', 1,
'Код входа в HAN Chat: {code}. Действителен {ttl_min} мин.',
'["code","ttl_min"]'::jsonb, NULL, 1, true, NULL, 'migration'
)
ON CONFLICT (code, channel, locale, version) DO NOTHING
"""
),
{"id": TEMPLATE_ID},
)
settings = (
(
"provider.idgtl.default_sender_name",
'"__SET_ME_AFTER_PROVIDER_APPROVAL__"',
"string",
"Provider-approved default sender name",
),
(
"provider.idgtl.connect_timeout_ms",
"3000",
"integer",
"Direct connection timeout in milliseconds",
),
(
"provider.idgtl.request_timeout_ms",
"70000",
"integer",
"Direct total request timeout in milliseconds",
),
(
"provider.idgtl.callback_enabled",
"true",
"boolean",
"Include delivery callback in provider requests",
),
(
"worker.poll_interval_ms",
"500",
"integer",
"Queue polling interval in milliseconds",
),
(
"worker.lease_seconds",
"90",
"integer",
"Exclusive provider-call lease duration",
),
)
for key, value, value_type, description in settings:
bind.execute(
sa.text(
"""
INSERT INTO sms.sms_setting (
setting_key, setting_value, value_type, description
) VALUES (:key, CAST(:value AS jsonb), :value_type, :description)
ON CONFLICT (setting_key) DO NOTHING
"""
),
{
"key": key,
"value": value,
"value_type": value_type,
"description": description,
},
)
def downgrade() -> None:
op.execute(sa.text("DELETE FROM sms.sms_template WHERE id = :id").bindparams(id=TEMPLATE_ID))
op.execute(
"""
DELETE FROM sms.sms_setting
WHERE setting_key IN (
'provider.idgtl.default_sender_name',
'provider.idgtl.connect_timeout_ms',
'provider.idgtl.request_timeout_ms',
'provider.idgtl.callback_enabled',
'worker.poll_interval_ms',
'worker.lease_seconds'
)
"""
)