Cookbook · Node.js 18+
Drone alert for your town
Satelit follows drones up to 300 km from Moldova's border and estimates their path for the next 30 minutes. You set the zones: a town and its radius, a point, or the whole country. When a drone is in a zone or reaches it within your minutes, the drone.zone webhook comes to your server, once per drone.
- Runs on
- Node.js 18+
- One run
- 0 credits
- A month
- 0 credits
- Set up in
- 15 min
$ PORT=8080 node drone_alert.mjsDRONE ALERT: A drone may reach chisinau (30 km) in about 12 min, near Ocnița, heading S at 180 km/h.How it works
- Add your server's address in the dashboard with the events
drone.zone,drone.enteredanddrone.ended, and your zones, for example{"city": "chisinau", "radius_km": 30, "lead_min": 15}. - The script checks the signature in
Satelit-Signature, answers 200 and ignores a retry with the sameid. - On
drone.zone,data.eta_minsays in how many minutes the drone arrives; 0 means it is in the zone already.data.zonesays which zone. - It tells the channel at once, with the reported place, heading and speed.
drone.endedsays when the drone is gone.
What it costs: Webhooks spend no credits. Zones are on plans with webhooks: 3 on Creator, 20 on Pro, 100 on Business. The Start plan has no webhooks.
How to run it
export SATELIT_WEBHOOK_SECRET=whsec_...
export TELEGRAM_TOKEN=... TELEGRAM_CHAT=@canalul_tau
PORT=8080 node drone_alert.mjsWhat it outputs
DRONE ALERT: A drone may reach chisinau (30 km) in about 12 min, near Ocnița, heading S at 180 km/h.The full script
#!/usr/bin/env node
// Receives Satelit's drone watch (any plan with webhooks): drone.zone when a drone is in one of your zones or on its way
// there, drone.entered when one is inside Moldova, drone.ended when it is gone. Checks the signature, tells your channel once
// per drone and stage, and edits nothing else. Your zones are set in the dashboard on the address, for example
// [{"city": "chisinau", "radius_km": 30, "lead_min": 15}, {"lat": 47.76, "lon": 27.93, "radius_km": 20, "lead_min": 10}]
// SATELIT_WEBHOOK_SECRET=... PORT=8080 node drone_alert.mjs
// TELEGRAM_TOKEN=... TELEGRAM_CHAT=@your_channel (without them the alert is printed)
// Put it behind HTTPS and add the address with the events drone.zone, drone.entered and drone.ended.
import { createHmac, timingSafeEqual } from "node:crypto";
import { createServer } from "node:http";
const SECRET = process.env.SATELIT_WEBHOOK_SECRET;
if (!SECRET) throw new Error("Set SATELIT_WEBHOOK_SECRET");
const { TELEGRAM_TOKEN, TELEGRAM_CHAT } = process.env;
const seen = new Set();
function verified(rawBody, header = "") {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const t = Number(parts.t);
if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
const expected = Buffer.from(createHmac("sha256", SECRET).update(`${t}.${rawBody}`).digest("hex"));
const given = Buffer.from(parts.v1 ?? "");
return expected.length === given.length && timingSafeEqual(expected, given);
}
async function tell(text) {
console.log(text);
if (!TELEGRAM_TOKEN || !TELEGRAM_CHAT) return;
fetch(`https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ chat_id: TELEGRAM_CHAT, text, disable_web_page_preview: true }),
}).catch((e) => console.error(`telegram: ${e.message}`));
}
// the zone in words: a town and its radius, a point, or the whole country
const zoneName = (z) => (z.moldova ? "Moldova" : z.city ? `${z.city} (${z.radius_km} km)` : `${z.lat}, ${z.lon} (${z.radius_km} km)`);
const where = (d) => `near ${d.last_reported?.near ?? "an unknown place"}, heading ${d.heading ?? "?"} at ${d.speed_kmh ?? "?"} km/h`;
const count = (d) => (d.count > 1 ? `${d.count} drones` : "A drone");
function zone(d) {
const is = d.count > 1 ? "are" : "is";
const what = d.eta_min === 0 ? `${is} in ${zoneName(d.zone)}` : `may reach ${zoneName(d.zone)} in about ${d.eta_min} min`;
tell(`DRONE ALERT: ${count(d)} ${what}, ${where(d)}. Estimate, preliminary. ${d.url ?? ""}`.trim());
}
function entered(d) {
const town = d.moldova?.towns?.[0];
tell(`DRONE IN MOLDOVA: ${count(d)} ${where(d)}${town ? `, ${town.km} km from ${town.name}` : ""}. Follow the authorities' instructions. ${d.url ?? ""}`.trim());
}
function ended(d) {
tell(`Drone track ended (${d.status}): ${d.last_reported?.near ?? "last place unknown"}.`);
}
const server = createServer((req, res) => {
const chunks = [];
req.on("data", (c) => chunks.push(c));
req.on("end", () => {
const raw = Buffer.concat(chunks).toString("utf8");
if (!verified(raw, req.headers["satelit-signature"])) {
res.writeHead(401).end();
return;
}
const event = JSON.parse(raw);
res.writeHead(200).end(); // answer first: Satelit does not wait for your work
if (seen.has(event.id)) return; // a retry of what we already handled
seen.add(event.id);
if (event.type === "drone.zone") zone(event.data);
else if (event.type === "drone.entered") entered(event.data);
else if (event.type === "drone.ended") ended(event.data);
});
});
server.listen(Number(process.env.PORT ?? 8080), () => console.log(`listening on ${server.address().port}`));
Routes used
Questions about this cookbook
How exact is the drone's position?
It is an estimate from public reports, with its uncertainty in position.accuracy_km. The path in ahead is the likely one, not a certain one. The preliminary field is always true.
Can I watch several towns?
Yes, each address holds up to 20 zones: towns with a radius, points with a radius or {"moldova": true}. Each drone comes once per zone.
Is it an official alert system?
No. These are Satelit's estimates. Always follow the authorities' instructions; official incidents come separately, as drone.incident.