Files
gutscheintracker/lib/telegram.ts
T

13 lines
534 B
TypeScript

import { getTelegramSettings } from "./integration-settings";
export async function sendTelegram(chatId: string, text: string): Promise<void> {
const { botToken } = await getTelegramSettings();
if (!botToken) throw new Error("TELEGRAM_BOT_TOKEN fehlt");
const res = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ chat_id: chatId, text }),
});
if (!res.ok) throw new Error(`Telegram ${res.status}`);
}