fix: clarify why SMS delivery is skipped when a channel gate is off

Surface env vs dashboard disable reasons in SMS logs so password reset and other sends are easier to diagnose when only one layer is enabled.
This commit is contained in:
2026-08-16 13:30:51 +03:30
parent 7d59448991
commit 4ad5630cb7
2 changed files with 44 additions and 11 deletions
+31 -5
View File
@@ -4,7 +4,7 @@ const config = require('../../config/config');
const logger = require('../../utils/logger');
const { Setting, SETTINGS_KEY } = require('./settingModel');
const {
isChannelEnabled,
isDbChannelEnabled,
isEnvChannelEnabled,
toPublicMessaging
} = require('../../utils/messagingChannels');
@@ -35,20 +35,46 @@ const invalidateMessagingCache = () => {
cacheAt = 0;
};
const isMessagingChannelEnabled = async (channel) => {
if (!isEnvChannelEnabled(channel, config)) return false;
const getMessagingChannelState = async (channel) => {
const envEnabled = isEnvChannelEnabled(channel, config);
if (!envEnabled) {
return {
enabled: false,
envEnabled: false,
dbEnabled: null,
blockReason: 'env_disabled'
};
}
try {
const db = await getDbMessagingFlags();
return isChannelEnabled(channel, { env: config, db });
const dbEnabled = isDbChannelEnabled(channel, db);
return {
enabled: dbEnabled,
envEnabled: true,
dbEnabled,
blockReason: dbEnabled ? null : 'dashboard_disabled'
};
} catch (err) {
logger.warn(`[Messaging] Failed to read settings for ${channel}, using env only: ${err.message}`);
return true;
return {
enabled: true,
envEnabled: true,
dbEnabled: null,
blockReason: null
};
}
};
const isMessagingChannelEnabled = async (channel) => {
const state = await getMessagingChannelState(channel);
return state.enabled;
};
const getPublicMessaging = (doc) => toPublicMessaging(readDbFlags(doc), config);
module.exports = {
getMessagingChannelState,
isMessagingChannelEnabled,
invalidateMessagingCache,
getPublicMessaging,
+13 -6
View File
@@ -4,7 +4,7 @@
const axios = require('axios');
const config = require('../../config/config');
const logger = require('../logger');
const { isMessagingChannelEnabled } = require('../../components/settings/messagingFlags');
const { getMessagingChannelState } = require('../../components/settings/messagingFlags');
const toBoolean = (value) => {
if (typeof value === 'boolean') return value;
@@ -22,16 +22,23 @@ const redactSmsParams = (params = []) => (
);
const sendSingleSms = async (mobile, templateId, params = []) => {
console.log('[SMS] About to send notification:', {
const channelState = await getMessagingChannelState('sms');
logger.info('[SMS] About to send notification:', {
mobile,
templateId,
params: redactSmsParams(params),
SMS_ENABLED: config.SMS_ENABLED,
SMS_ENABLED: channelState.envEnabled,
dashboardEnabled: channelState.dbEnabled,
});
if (!(await isMessagingChannelEnabled('sms'))) {
logger.info(`[SMS] Skipped (channel disabled) → ${mobile} template=${templateId}`);
return { skipped: true, reason: 'channel_disabled' };
if (!channelState.enabled) {
const reason = channelState.blockReason || 'channel_disabled';
const detail = reason === 'dashboard_disabled'
? 'dashboard smsEnabled=false'
: 'SMS_ENABLED env flag is false';
logger.info(`[SMS] Skipped (${detail}) → ${mobile} template=${templateId}`);
return { skipped: true, reason };
}
if (!templateId) {