Repository navigation
Being notified if this node (or NodeRED) gets updated #474
PeterHunt
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello,
Just want to share my latest creation. Sometimes I discover that I missed some updates and started looking for an automated notification. Every config can be different, but in my case I added 2 exec nodes, which are calling :
node -e "fetch('https://registry.npmjs.org/node-red-contrib-telegrambot/latest').then(r=>r.json()).then(j=>console.log(j.version))"
node -e "fetch('https://registry.npmjs.org/node-red/latest').then(r=>r.json()).then(j=>console.log(j.version))"
They output only the version number. Both nodes enter the same function node. To make life a bit easy, I switch upon the main version number to decide if we are checking NodeRED or node-red-contrib-telegrambot :
`const vNew = (msg.payload || "").trim();
const major = parseInt(vNew.split(".")[0], 10);
const component = (major >= 18) ? "npmTelegram" : "npmNodeRED";
const comp_name = (major >= 18) ? "TelegramBOT" : "NodeRED";
const vCurrent = flow.get(component, "storeInFile");
const chatID = 1234567890;
// First time? Just save
if (!vCurrent)
{
flow.set(component, vNew, "storeInFile");
return null;
}
// No new version available
if (vCurrent === vNew)
return null;
// Found new version, let's save it
flow.set(component, vNew, "storeInFile");
msg.payload = {
chatId: chatID,
type: "message",
content:
📦 <b><u>Update available</u></b>\n\n+<b>${comp_name}</b>\n\n+Available: <b>${vNew}</b>\n+Current version: <b>${vCurrent}</b>,options: { parse_mode: "HTML" }
};
return msg;`
Also I have 2 similar exec nodes and a similar function which check for actual updating in NodeRED upon the startup-trigger to send a notification to a group, informing some other guys that either NodeRED or the BOT has been updated.
Not sure whether this helps anyone, but it's just a free usable share ;)
Kind regards,
Peter Hunt.
All reactions