Files
gameno-api/utils/senders/baleBotSender.js
T
kavehhn 72be01fee3 feat: add messaging toggles, password reset SMS, and payment discounts
Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
2026-08-16 06:58:08 +03:30

39 lines
1.3 KiB
JavaScript

// /utils/senders/baleBotSender.js
const axios = require('axios');
const config = require('../../config/config');
const logger = require('../logger');
const { isMessagingChannelEnabled } = require('../../components/settings/messagingFlags');
const sendBaleMessage = async ({ chatId, body }) => {
try {
const targetChatId = chatId || 'default_channel';
if (!(await isMessagingChannelEnabled('bot'))) {
logger.info(`[BaleBotSender] Skipped (channel disabled) → ${targetChatId}`);
return { skipped: true, reason: 'channel_disabled' };
}
if (config.BALE_BOT_TOKEN === 'mock_bale_bot_token') {
logger.info(`[BaleBotSender MOCK] ChatID: ${targetChatId} | Message: "${body}"`);
return { success: true, messageId: `bale_mock_${Date.now()}` };
}
const url = `https://tapi.bale.ai/bot${config.BALE_BOT_TOKEN}/sendMessage`;
const response = await axios.post(url, {
chat_id: targetChatId,
text: body
}, { timeout: 5000 });
logger.info(`[BaleBotSender] Sent message to ${targetChatId}`);
return { success: true, messageId: response.data?.result?.message_id || `bale_${Date.now()}` };
} catch (error) {
logger.error(`[BaleBotSender ERROR] Failed to send Bale message: ${error.message}`);
throw error;
}
};
module.exports = {
sendBaleMessage
};