Website Change Alerts in Node-RED: Verified HTTP In Flow
Receive AyeWatch website change alerts in Node-RED. Tick Do not parse request body on the http in node, verify the HMAC in a function node, skip repeats and reply through http response.
By AyeWatch Team4 min read
Short answer: To receive website change alerts in Node-RED, add an http in node for POST /ayewatch with Do not parse request body ticked, then a function node that checks X-AyeWatch-Signature with crypto.timingSafeEqual and skips repeated update_id values, then an http response node. Node-RED must be reachable over public HTTPS, and the option needs version 4.1 or later.
The flow
Four nodes do the whole job:
- http in: Method POST, URL
/ayewatch, and Do not parse request body ticked. With that option on,msg.payloadis a Buffer holding the exact bytes AyeWatch sent. The option arrived in Node-RED 4.1. On older versions the node parses the JSON, and the signature cannot be checked against a parsed copy. - function "Verify AyeWatch": the code below, with Outputs set to 2 on its Setup tab.
- http response on output 1. It sends
msg.statusCodeandmsg.payloadback to AyeWatch. - Your action on output 2: an mqtt out node, a dashboard, a notification or anything else.
Let function nodes use crypto
Function nodes cannot call require. The documented way to hand them a Node.js module is functionGlobalContext in settings.js. Add crypto there and restart Node-RED:
functionGlobalContext: {
crypto: require("crypto"),
},
Set AYEWATCH_SECRET as an environment variable, either for the Node-RED process or in the flow's properties, so it stays out of the function code and out of exported flows.
The function node
Sample rule: Alert me when the Elmstead Library events page adds a new children's coding workshop or opens bookings for one. Ignore book club listings.
// Function node "Verify AyeWatch", Outputs: 2
const crypto = global.get("crypto");
const raw = msg.payload; // a Buffer, because "Do not parse request body" is ticked
// 1 and 2. Raw body and signature, compared in constant time
const expected = Buffer.from(
"sha256=" + crypto.createHmac("sha256", env.get("AYEWATCH_SECRET")).update(raw).digest("hex")
);
const got = Buffer.from(msg.req.headers["x-ayewatch-signature"] || "");
if (got.length !== expected.length || !crypto.timingSafeEqual(got, expected)) {
msg.statusCode = 401;
msg.payload = "Bad signature";
return [msg, null];
}
// 3. Dedupe on update_id, keeping the last 500
const alert = JSON.parse(raw.toString("utf8"));
const seen = flow.get("ayewatchSeen") || [];
msg.statusCode = 200;
if (seen.includes(alert.update_id)) {
msg.payload = "Already handled";
return [msg, null];
}
flow.set("ayewatchSeen", seen.concat(alert.update_id).slice(-500));
// 4. Reply on output 1, 5. act on output 2
msg.payload = "ok";
return [msg, { topic: "alerts/ayewatch", payload: alert }];
The reply message keeps msg.req and msg.res, which the http response node needs. The second output is a fresh message, so nothing downstream can touch the open request. Node.js lowercases header names, so the header key is lowercase.
Answer first, then act
Node-RED sends output 1 and output 2 one after the other, so AyeWatch gets its 200 straight away and well inside 10 seconds. The cost of that order: if the mqtt broker or the next node fails, AyeWatch does not retry, because it already has its 200. Add a catch node on the action branch and log or alert on errors.
If the action must succeed before you answer, move the http response node to the end of the action branch and copy msg.req and msg.res along. Keep the branch fast, since AyeWatch only waits 10 seconds.
Test the public address before you save it in AyeWatch. A request with no signature should come back as 401 Bad signature:
curl -i -X POST https://nodered.yourhome.example/ayewatch -H "Content-Type: application/json" -d "{}"
A 404 means the path or httpNodeRoot is different. A 3xx from the proxy means AyeWatch would fail too. On Node-RED 4.0 or older, upgrade first, or verify in a Cloudflare Worker and forward to Node-RED.
Limits and cost
- Public HTTPS. AyeWatch rejects private, loopback and internal addresses. A Node-RED box at home needs a reverse proxy or a tunnel with a public HTTPS name, such as
https://nodered.yourhome.example/ayewatch. - No basic auth on http in nodes. AyeWatch rejects webhook URLs that carry a username and password, so
httpNodeAuthcannot be used for this route. The signature is the lock. - Memory-only dedupe. Flow context lives in memory by default and resets on restart. A retry right after a restart could run twice.
- Public pages only. AyeWatch reads public pages and cannot sign in.
AyeWatch Pro is $9/mo with 50 topics and hourly checks; Pro+ is $19/mo with 200 topics and ASAP mode. Every plan starts with a 7-day free trial. Five event pages in separate web page monitors, checked every 6 hours, use 5 × 120 = 600 credits a month. That is over Pro's 500, so check them twice a day for 300, or take Pro+.
Build it
- Add
crypto: require("crypto")tofunctionGlobalContextinsettings.jsand restart Node-RED. - Add an http in node: POST,
/ayewatch, Do not parse request body ticked. - Add the function node with Outputs set to 2, then an http response node on output 1 and your action on output 2. Deploy.
- In AyeWatch, open Notification settings, Webhook, paste your public HTTPS URL and select Save Webhook. Reveal and copy the signing secret.
- Set it as the
AYEWATCH_SECRETenvironment variable and restart or redeploy. - Wait for a real update and check the debug sidebar.
| Node | Setting | Value |
|---|---|---|
| http in | Method and URL | POST, /ayewatch |
| http in | Do not parse request body | Ticked (Node-RED 4.1 or later) |
| function | Outputs | 2 |
| function | Secret | env.get("AYEWATCH_SECRET") |
| http response | Status | From msg.statusCode |
| settings.js | functionGlobalContext | crypto: require("crypto") |
Start a monitor in under a minute
Describe a topic or paste a URL. Cancel before the trial ends and you pay nothing.
Try it free for 7 daysThe bottom line
Tick one checkbox, add crypto to settings.js, and four nodes give you a verified receiver. From output 2, the alert can go anywhere Node-RED reaches.
FAQ
How do I get the raw request body in Node-RED?
Tick Do not parse request body on the http in node, available from Node-RED 4.1. msg.payload is then a Buffer with the exact bytes.
How do I use crypto in a Node-RED function node?
Add crypto: require("crypto") to functionGlobalContext in settings.js, restart, and read it with global.get("crypto").
Where are request headers in Node-RED?
In msg.req.headers, with lowercase names. The signature is msg.req.headers["x-ayewatch-signature"].
Why does my http in flow time out?
Every http in flow must reach an http response node. Without one the request hangs, and AyeWatch counts the timeout as a failed delivery.
Can AyeWatch reach Node-RED on my home network?
Only through a public HTTPS address. AyeWatch rejects private and internal addresses, so use a reverse proxy or a tunnel.