'use server'; const GOTIFY_URL = process.env.GOTIFY_URL; const GOTIFY_APP_TOKEN = process.env.GOTIFY_APP_TOKEN; export async function sendGotifyNotification(attempts: number, status: 'won' | 'lost', puzzleId: number) { try { const title = `Hördle #${puzzleId} ${status === 'won' ? 'Solved!' : 'Failed'}`; const message = status === 'won' ? `Puzzle #${puzzleId} was solved in ${attempts} attempt(s).` : `Puzzle #${puzzleId} was failed after ${attempts} attempt(s).`; const response = await fetch(`${GOTIFY_URL}/message?token=${GOTIFY_APP_TOKEN}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ title: title, message: message, priority: 5, }), }); if (!response.ok) { console.error('Failed to send Gotify notification:', await response.text()); } } catch (error) { console.error('Error sending Gotify notification:', error); } }