24 lines
783 B
TypeScript
24 lines
783 B
TypeScript
export async function sendNotification(webhookUrl: string | null, message: string) {
|
|
if (!webhookUrl) return;
|
|
|
|
try {
|
|
const response = await fetch(webhookUrl, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"User-Agent": "CatSittingPlanner/1.0"
|
|
},
|
|
// Works for Discord (content) and generic Telegram Webhook bridges (text)
|
|
body: JSON.stringify({
|
|
content: message,
|
|
text: message
|
|
}),
|
|
});
|
|
if (!response.ok) {
|
|
console.error(`[Notification] Webhook failed with status ${response.status}`);
|
|
}
|
|
} catch (error) {
|
|
console.error("Failed to send notification:", error);
|
|
}
|
|
}
|