Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// /utils/senders/smsSender.js
|
||||
'use strict';
|
||||
|
||||
const logger = require('../logger');
|
||||
const { sendSingleSms } = require('./sms.base');
|
||||
const {
|
||||
sendAccountCreatedSms,
|
||||
sendClassRegisteredSms,
|
||||
sendClassReminderSms,
|
||||
} = require('./smsMessages');
|
||||
|
||||
/**
|
||||
* Generic notification-path SMS. sms.ir verify API is template-based,
|
||||
* so free-text body sends are logged only unless a templateId is provided.
|
||||
*/
|
||||
const sendSMS = async ({ phoneNumber, body, templateId, parameters }) => {
|
||||
try {
|
||||
if (!phoneNumber) throw new Error('Phone number is required for SMS');
|
||||
|
||||
if (templateId) {
|
||||
return await sendSingleSms(phoneNumber, templateId, parameters || []);
|
||||
}
|
||||
|
||||
logger.info(`[SMSSender] Free-text SMS not sent via verify API to ${phoneNumber}: "${body}"`);
|
||||
return { success: true, skipped: true, reason: 'free_text_unsupported' };
|
||||
} catch (error) {
|
||||
logger.error(`[SMSSender ERROR] Failed to send SMS to ${phoneNumber}: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
sendSMS,
|
||||
sendAccountCreatedSms,
|
||||
sendClassRegisteredSms,
|
||||
sendClassReminderSms,
|
||||
};
|
||||
Reference in New Issue
Block a user