diff --git a/.gitea/workflows/analytics-mailer.yml b/.gitea/workflows/analytics-mailer.yml index 56cea56..76f844a 100644 --- a/.gitea/workflows/analytics-mailer.yml +++ b/.gitea/workflows/analytics-mailer.yml @@ -33,6 +33,8 @@ jobs: SMTP_USER: ${{ secrets.SMTP_USER }} SMTP_PASS: ${{ secrets.SMTP_PASS }} SMTP_SENDER: ${{ secrets.SMTP_SENDER }} + GOTIFY_URL: ${{ secrets.GOTIFY_URL }} + GOTIFY_TOKEN: ${{ secrets.GOTIFY_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 diff --git a/apps/analytics-mailer/src/index.ts b/apps/analytics-mailer/src/index.ts index c0607b7..229c982 100644 --- a/apps/analytics-mailer/src/index.ts +++ b/apps/analytics-mailer/src/index.ts @@ -20,6 +20,9 @@ const SMTP_USER = process.env.SMTP_USER; const SMTP_PASS = process.env.SMTP_PASS; const SMTP_SENDER = process.env.SMTP_SENDER || "reports@mintel.me"; +const GOTIFY_URL = process.env.GOTIFY_URL; +const GOTIFY_TOKEN = process.env.GOTIFY_TOKEN; + interface ConfigClient { websiteId: string; domain: string; @@ -172,7 +175,20 @@ async function main() { console.log(`Successfully sent to ${client.clientEmail}`); } } catch (e: any) { - console.error(`Failed to process client ${client.domain}:`, e.response?.data || e.message); + const errorMsg = e.response?.data || e.message; + console.error(`Failed to process client ${client.domain}:`, errorMsg); + + if (GOTIFY_URL && GOTIFY_TOKEN) { + try { + await axios.post(`${GOTIFY_URL}/message?token=${GOTIFY_TOKEN}`, { + title: `❌ Analytics Mailer Error (${client.domain})`, + message: `Failed to generate or send report for ${client.domain}.\n\nError:\n${errorMsg}`, + priority: 8 + }); + } catch (gotifyErr: any) { + console.error("Failed to push to Gotify:", gotifyErr.message); + } + } } }