Add sendMessage function for Discord notifications
This commit is contained in:
17
index.js
17
index.js
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user