node-red-contrib-anypush 0.1.0
Node-RED nodes for anypush: send push notifications and job exit statuses to an anypush channel on your Android phone
node-red-contrib-anypush
Node-RED nodes for anypush: send push notifications, and report a job's exit status, from a flow to an anypush channel on your Android phone.
anypush is an Android app (on Google Play as app.anypush).
You make a channel in the app and copy its address. Free to start, no ads, Android 7 and up. Scripts and webhooks:
https://anypush.app/webhooks.
Prerequisites
- Node-RED 3.0 or later, on Node.js 18 or later (the nodes use Node's built-in
fetch). - An anypush channel address, from the anypush app.
The package has no runtime dependencies.
Install
In the Node-RED editor: Menu > Manage palette > Install, search for node-red-contrib-anypush, and select
install.
Or in your Node-RED user directory (usually ~/.node-red):
npm install node-red-contrib-anypush
and restart Node-RED.
Nodes
anypush-channel (config node)
Holds one channel address: https://anypush.app/h/YOUR_CHANNEL_TOKEN, or the token alone.
The address is a secret: anyone who has it can push to your phone. The config node keeps it in its credentials, as a password field. Node-RED stores credentials encrypted and leaves them out of exported flows. The nodes never write the address to a message, a status or the log.
anypush (category: network)
Sends each incoming message to the channel. The Send field picks what msg.payload is.
Send msg.payload as a message (the default):
| Input | Becomes |
|---|---|
msg.payload |
the message, 1 to 4096 characters. Objects are sent as their JSON text, buffers as UTF-8 text. |
node Title, or msg.topic when the node's Title is empty |
the title, at most 256 characters |
msg.priority, or the node's Priority |
low, normal (default) or high |
msg.url, or the node's URL |
an http or https link, opened when the notification is tapped |
msg.idempotencyKey (optional) |
the same key on the same channel within a day sends once; anypush answers the first message again with duplicate: true. Set one per message if your flow retries. |
The request is POST https://anypush.app/h/<token> with a JSON body.
Send msg.payload as a job status:
| Input | Becomes |
|---|---|
msg.payload |
the job's exit status as a shell prints it ($?): a whole number from 0 to 255, or a string of digits |
msg.log (optional) |
the end of the job's log, shown as the alert's text |
0is a silent heartbeat: no notification. It restarts the channel's "tell me when this goes quiet" clock.1to255is a high-priority alert, "Exited with status N", with the end ofmsg.logas its text. anypush sends at most one alert an hour per status.
The request is POST https://anypush.app/h/<token>/<status> with msg.log as a plain-text body. A check-in channel
does not take job statuses and answers 409.
Output: the same message, with msg.payload set to anypush's answer, for example:
{ "id": 1042, "duplicate": false }
anypush's answer also has a status_url. The node leaves it out, because it contains the channel address; it
leaves out any other field that carries the address or a token too.
Status: a green dot when anypush took the message (sent, status 3 sent, or duplicate, not sent again), a
red ring when it did not.
Errors
On an error the node calls node.error(err, msg), so a catch node gets the message, and sends nothing on. The
error never contains the channel address.
| anypush answers | Error message | Retry? |
|---|---|---|
| 404 | No anypush channel at this address: the address is wrong, or the channel was deleted | no |
| 409 (job status mode) | This anypush channel does not take job statuses (a check-in channel answers 409) | no |
| 413 | The message is too large for anypush: the whole request may be at most 64 KiB | no |
| 422 | "anypush refused the message:" followed by anypush's reason, for example "The message is required." | no |
| 429 | Too many messages to this anypush channel (60 a minute per channel, or the app's daily cap), with the Retry-After seconds |
later |
| 503 | anypush is briefly unavailable, with the Retry-After seconds |
yes |
The node also checks its input before it sends: an empty message, a priority other than low, normal or high,
a URL that is not http or https, or a job status outside 0 to 255 is an error without a request. If anypush does not
answer within 15 seconds, or the network fails, the error is "Could not reach anypush".
Examples
Import them in the editor with Menu > Import > Examples > node-red-contrib-anypush:
- send-a-message: an inject node sends "Backup failed on nas" with the topic
nightly-backupat high priority. - report-a-job-status: an inject node sends status
0every 5 minutes, a heartbeat for Node-RED itself: when Node-RED stops, the heartbeats stop.
The examples contain no channel address. Open the anypush node, edit its channel, and paste your own.
Development
npm install
npm test
The tests run the nodes in Node-RED's test runtime (node-red-node-test-helper and mocha, dev dependencies only)
with fetch replaced by a fake and a fake channel token. They start no server and send nothing.