// /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 };