From 09947b85cd473d5661bb8c2e25a27d86ab69d644 Mon Sep 17 00:00:00 2001 From: Suraj B M Date: Thu, 6 Aug 2026 17:37:29 +0530 Subject: [PATCH] fix: improve configuration handling for ntfy notifications --- index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 408434c..92278e1 100644 --- a/index.ts +++ b/index.ts @@ -1,24 +1,26 @@ -import { $ } from "bun" import cron from "node-cron" import dayjs from "dayjs" import "dayjs/locale/es" import { getUSD, getUsage, getWeather } from "./fx" import { EventSource } from "eventsource" -const TOPIC = "daily-digest" +const NTFY_URL = process.env.NTFY_URL +const TOPIC = process.env.NTFY_TOPIC const TOKEN = process.env.NTFY_TOKEN -if (!TOKEN) { - console.error("ntfy token not set") +if (!TOKEN || !NTFY_URL || !TOPIC) { + console.error("ntfy token, url or topic not set") process.exit(1) } async function main() { - const usd = await getUSD() - const usage = await getUsage() - const weather = await getWeather() + const [usd, usage, weather] = await Promise.all([ + getUSD(), + getUsage(), + getWeather() + ]) const message = `Good Morning, SilicoFlare! @@ -34,7 +36,7 @@ ${usage} Have a great day!` const ntfy = await fetch( - `https://ntfy.hy-pr.link/${TOPIC}`, + `${NTFY_URL}/${TOPIC}`, { method: "POST", headers: { @@ -60,7 +62,7 @@ async function runMain() { } catch (err) { console.error(err) fetch( - `https://ntfy.hy-pr.link/${TOPIC}`, + `${NTFY_URL}/${TOPIC}`, { method: "POST", headers: { @@ -83,7 +85,7 @@ cron.schedule("0 7 * * *", () => { }) -const es = new EventSource("https://ntfy.hy-pr.link/daily-digest/sse", { +const es = new EventSource(`${NTFY_URL}/${TOPIC}/sse`, { fetch: (input, init) => fetch(input, { ...init,