Add sendMessage function for Discord notifications

This commit is contained in:
Norbert Maciaszek
2025-11-15 20:06:29 +01:00
parent a3114d9f49
commit beb1cf7bdc

View File

@@ -18,6 +18,12 @@ const priceSelectors = {
const excludePage = ["allegro", "homla.com.pl", "home-you.com"];
function sendMessage(message) {
axios.post(discordWebhook, {
content: message,
});
}
async function compareAndSave(productsPrice) {
const productsPriceJson =
fs.readFileSync("productsPrice.json", "utf8") || "[]";
@@ -41,15 +47,13 @@ async function compareAndSave(productsPrice) {
}
for (const product of diffProducts) {
await axios.post(discordWebhook, {
content: `Zmiana ceny **${product.name}**:\nCena: ${product.oldPrice} -> ${product.newPrice}\nLink: ${product.link}`,
});
sendMessage(
`Zmiana ceny **${product.name}**:\nCena: ${product.oldPrice} -> ${product.newPrice}\nLink: ${product.link}`
);
}
if (diffProducts.length === 0) {
await axios.post(discordWebhook, {
content: "Brak zmian w cenach",
});
sendMessage("Brak zmian w cenach");
}
fs.writeFileSync(
@@ -137,6 +141,7 @@ async function init() {
console.log("Done! Check productsPrice.json");
}
sendMessage("Zaczynam monitoring cen");
cron.schedule("* */3 * * *", async () => {
await init();
});