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,32 @@
|
||||
// /utils/senders/baleBotSender.js
|
||||
|
||||
const axios = require('axios');
|
||||
const config = require('../../config/config');
|
||||
const logger = require('../logger');
|
||||
|
||||
const sendBaleMessage = async ({ chatId, body }) => {
|
||||
try {
|
||||
const targetChatId = chatId || 'default_channel';
|
||||
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user