DoSoapCalc/backend/lib/telegram.js

31 lines
923 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lib/telegram.js
// Общая логика для отправки сообщений в Telegram
const streamifier = require('streamifier');
/**
* Отправляет сообщение в Telegram (с фото или без)
* @param {TelegramBot} bot - Экземпляр бота
* @param {number} chatId - ID чата
* @param {string} text - Текст сообщения
* @param {Buffer|null} photoBuffer - Буфер фото (опционально)
* @returns {Promise<void>}
*/
async function sendTelegramMessage(bot, chatId, text, photoBuffer = null) {
if (photoBuffer) {
const bufferStream = streamifier.createReadStream(photoBuffer);
await bot.sendPhoto(
Number(chatId),
bufferStream,
{ caption: text, parse_mode: 'HTML' }
);
} else {
await bot.sendMessage(Number(chatId), text, { parse_mode: 'HTML' });
}
}
module.exports = {
sendTelegramMessage,
};