Files
gameno-api/components/settings/smsTemplates.js
T
kavehhn 3160f07873 feat: send account and invoice SMS from stored template IDs
Move sms.ir template IDs out of env into settings so SuperAdmin can manage them, and record every outbound SMS status in notifications.
2026-08-15 18:37:44 +03:30

51 lines
1.1 KiB
JavaScript

'use strict';
const SMS_TEMPLATE_DEFS = [
{
key: 'accountCreated',
label: 'ایجاد حساب کاربری',
variables: ['user', 'password'],
envKey: 'SMS_TEMPLATE_ACCOUNT_CREATED'
},
{
key: 'classRegistered',
label: 'ثبت‌نام در کلاس',
variables: ['className'],
envKey: 'SMS_TEMPLATE_CLASS_REGISTERED'
},
{
key: 'classReminder',
label: 'یادآوری کلاس',
variables: ['className', 'time', 'place'],
envKey: 'SMS_TEMPLATE_CLASS_REMINDER'
},
{
key: 'invoiceCreated',
label: 'ایجاد صورتحساب',
variables: ['amount'],
envKey: 'SMS_TEMPLATE_INVOICE_CREATED'
}
];
const SMS_TEMPLATE_KEYS = SMS_TEMPLATE_DEFS.map((def) => def.key);
const envFallbackFor = (def) => {
if (!def?.envKey) return '';
return String(process.env[def.envKey] || '').trim();
};
const sanitizeTemplateId = (value) => {
if (value == null) return '';
const digits = String(value).trim();
if (!digits) return '';
if (!/^\d{1,20}$/.test(digits)) return null;
return digits;
};
module.exports = {
SMS_TEMPLATE_DEFS,
SMS_TEMPLATE_KEYS,
envFallbackFor,
sanitizeTemplateId
};