Initial commit: Cat Sitting Planner with PWA, SQLite, and Webhook Notifications
This commit is contained in:
23
lib/notifications.ts
Normal file
23
lib/notifications.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user