OmegaBaSMS/telegram.js
2026-05-28 09:38:42 +03:00

27 lines
864 B
JavaScript

const config = require('./config');
const tg = config.telegram;
if (!tg || !tg.botToken) {
module.exports = { sendTelegramMessage: async () => {}, sendTelegramPhoto: async () => {} };
} else {
const base = `https://api.telegram.org/bot${tg.botToken}`;
async function sendTelegramMessage(text) {
await fetch(`${base}/sendMessage`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: tg.chatId, text }),
});
}
async function sendTelegramPhoto(buffer, caption) {
const form = new FormData();
form.append('chat_id', tg.chatId);
form.append('photo', new Blob([buffer]), 'qr.png');
if (caption) form.append('caption', caption);
await fetch(`${base}/sendPhoto`, { method: 'POST', body: form });
}
module.exports = { sendTelegramMessage, sendTelegramPhoto };
}