Move sms.ir template IDs out of env into settings so SuperAdmin can manage them, and record every outbound SMS status in notifications.
51 lines
1.1 KiB
JavaScript
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
|
|
};
|