feat(job-completion): add message and photo upload to job completion

This commit is contained in:
2026-01-13 11:41:21 +01:00
parent e104a9d377
commit 97d8f12fc0
14 changed files with 265 additions and 25 deletions

View File

@@ -1,18 +1,37 @@
export async function sendNotification(webhookUrl: string | null, message: string) {
export async function sendNotification(webhookUrl: string | null, message: string, imageUrl?: string) {
if (!webhookUrl) return;
try {
const payload: any = {
content: message,
text: message
}
// For Discord: use embed if image exists
if (imageUrl && webhookUrl.includes("discord")) {
payload.embeds = [{
image: {
url: imageUrl
}
}]
}
// For generic webhooks, just append URL to text if not Discord, or leave as is?
// Let's create a simpler payload if image exists but not discord?
// Actually, if we just send JSON, most won't render it unless specific format.
// Let's just append the image URL to the message if it's not a Discord webhook, so it's clickable.
if (imageUrl && !webhookUrl.includes("discord")) {
payload.content += `\n${imageUrl}`;
payload.text += `\n${imageUrl}`;
}
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
}),
body: JSON.stringify(payload),
});
if (!response.ok) {
console.error(`[Notification] Webhook failed with status ${response.status}`);
@@ -25,12 +44,12 @@ export async function sendNotification(webhookUrl: string | null, message: strin
import { sendPushNotification } from "./push";
import prisma from "@/lib/prisma";
export async function sendPlanNotification(planId: string, message: string, webhookUrl?: string | null) {
export async function sendPlanNotification(planId: string, message: string, webhookUrl?: string | null, imageUrl?: string) {
// Parallelize sending
const promises: Promise<any>[] = [];
if (webhookUrl) {
promises.push(sendNotification(webhookUrl, message));
promises.push(sendNotification(webhookUrl, message, imageUrl));
}
try {
@@ -40,13 +59,11 @@ export async function sendPlanNotification(planId: string, message: string, webh
if (subscriptions.length > 0) {
console.log(`[Push] Found ${subscriptions.length} subscriptions for plan ${planId}`);
const payload = {
const payload: any = {
title: "Cat Sitting Planner",
body: message,
url: `/`
// We could pass specific URL if needed, but for now root is okay or dashboard?
// The service worker opens the URL.
// Ideally, we want to open `/dashboard/[planId]`.
url: `/`,
image: imageUrl
};
// Refine URL in payload