Push notifications through ZNC
A bouncer such as ZNC stays on IRC while your phone is away, but it can't wake Heydrun to tell you about a mention or a private message. The znc-push module can: it sends each one to a push service, which shows it as a notification on your phone, even when Heydrun isn't connected.
This needs work on two sides. The first part is done on the computer that runs ZNC, by whoever looks after it. The rest is done on your phone and in Heydrun.
Soju and Ergo don't need any of this: they push through Heydrun's own Push notifications setting (see Using soju and Using Ergo). For the rest of what Heydrun does with ZNC, see Using ZNC.
What you need
- ZNC 1.7 or later, and a way to run commands on the computer it runs on.
- A push app on your phone. This guide uses ntfy, which is free and needs no account. znc-push also supports Pushover, Pushbullet, Telegram and others; their settings are in the module's own instructions.
1. Build and install znc-push (on the ZNC computer)
The module is at github.com/amyreese/znc-push. On Debian or Ubuntu, install what it needs to build:
sudo apt install znc-dev ca-certificates libcurl4-openssl-dev
Then, in the module's folder:
make curl=yes
make install
curl=yes makes it check the push service's certificate, which the default build doesn't. If make isn't there, znc-buildmod push.cpp builds it instead; copy the push.so it makes into your ZNC profile's modules folder.
2. Load the module
The quick way in step 3 offers to load it for you. To load it yourself, from Heydrun, in the server buffer for your ZNC network, either for every network on your ZNC account:
/msg *status loadmod --type=user push
or for this network only:
/msg *status loadmod push
Load it one way, not both, or you may be told about each message twice.
This network or all networks
- All networks on the account: one set of settings covers every network, including ones you add to ZNC later. Each push still says which network it came from, and Heydrun opens the matching network. "Only while no client is connected" still counts each network on its own, so being connected to one network doesn't hold back pushes from another. But the wait between pushes and the "replied" rule go by the channel or nick's name, not the network, so
#linuxon two networks shares one wait, and the conditions can't differ between networks. - This network only: its own settings, kept apart from your other networks. Each network you want pushes from is set up on its own.
Some people have found that push loaded for the whole account stopped notifying until its stored settings were removed. If that happens, unload it, delete moddata/push/.registry in your user's folder on the ZNC computer (such as ~/.znc/users/alice/moddata/push/.registry), then load and set it up again. This is znc-push issue 248.
3. The quick way: let Heydrun set it up
If you have a push app that works with UnifiedPush, such as ntfy, Heydrun can do steps 2 and 4 to 6 for you:
- Turn on Push notifications in Settings, IRC.
- While connected to ZNC, open the network's settings. Under Connection, with Server type at ZNC bouncer, or at IRC server once ZNC is detected, choose Set up push notifications.
- Choose This network only or All networks on this ZNC account. All networks is marked recommended when Heydrun has more than one network from the same ZNC account, which it tells by the server, port and ZNC username.
- Choose Set up.
Heydrun then talks to ZNC for you, and ZNC's answers appear in the server buffer:
- It asks
*statuswhich modules are loaded (ListMods). - If push isn't loaded, it asks you before loading it the way you chose, showing the command, with Don't ask again to skip asking from then on, as does Load ZNC's push module without asking in Settings, IRC. Choose Don't load and nothing on ZNC changes. If ZNC can't load it, because the module isn't installed or your ZNC user isn't allowed to load modules, Heydrun shows ZNC's reason.
- For all networks, once push is loaded for the account, it unloads any copy loaded for a single network, on each of the account's networks that's connected, so a failed load leaves push as it was. Any that aren't connected are listed, with the command to send there.
- For this network only, if push is already loaded for the whole account, it changes nothing and says so, since those settings are shared by every network.
- It sends push its settings: your push app's address with a random key only this phone knows, and pushing only while no client is connected. The service goes last, as until it's set znc-push reports an error for every mention.
The network's settings then say how push is set up, with three buttons: Check asks ZNC again and corrects what Heydrun has recorded, for push loaded, changed or removed outside Heydrun; Send a test push has znc-push send one, which should arrive at once; and Turn off unloads push the way it was loaded. Connect another network from the same ZNC account later, and Heydrun notices: with all networks chosen, the new one is covered already; with this network only, the server buffer says the new one isn't, so you can set it up too, or switch to all networks.
Heydrun understands ZNC's answers in English. If ZNC uses another language, or Heydrun says ZNC didn't answer as expected, choose Show the commands in the same dialog. It writes the commands Heydrun would send into the server buffer, each on its own line, for you to send or copy. They include your push app's address with the key, so keep them to yourself.
These pushes pass through your push app's server unencrypted, unlike soju's and Ergo's, so by default Heydrun asks only for who and where: the notification says "alice mentioned you in #rust" without the message.
To see the message too, turn on Show message text in ZNC push, under Push notifications in Settings, IRC, then choose Set up push notifications again. The text then passes your push server readable, so whoever runs that server, such as ntfy.sh, can read it. Turn it on only for a push server you trust or run yourself. Heydrun asks ZNC for up to 300 characters of each message, as ZNC otherwise cuts it at 100; Message length in ZNC push, just below, changes that, from 50 to 1000. Some ZNC builds put the text in the address they post to as well as in the post, so it can also end up in the push server's logs. Your push app's address alone isn't enough to fake one, because pushes without the key are ignored. The key is part of the address ZNC posts to, which ZNC and the push server can see, so anyone who can read those could send false alerts. With the message text off, they never see what was said.
To do it by hand instead, with an ntfy topic of your own and the message included, follow the steps below.
4. Choose an ntfy topic
In the ntfy app, add a subscription and give it a topic name that's hard to guess, such as a long random word. Anyone who knows the name can read what's sent to it, so don't use your nick. If you run your own ntfy server, use its address in the next step and protect the topic with a login.
5. Point znc-push at the topic
Back in Heydrun, send these, with your topic name in place of your-topic:
/msg *push set service url
/msg *push set message_uri https://ntfy.sh/your-topic/publish?title={context}&message={nick}:%20{message}
/msg *push set message_uri_post no
For a protected topic on your own server, add its login:
/msg *push set username your-login
/msg *push set secret your-password
6. Only when Heydrun isn't connected
Otherwise you'd be told twice, once by Heydrun and once by ntfy. This sends a push only while no client is connected to ZNC:
/msg *push set client_count_less_than 1
Other conditions you may want:
/msg *push set highlight word anotheradds words that count as a mention, besides your nick./msg *push set away_only yespushes only while you're marked away./msg *push set last_notification 300waits at least this many seconds between pushes for the same buffer. 300 is the default.
7. Test it
/msg *push send test
A notification saying "test" should arrive from ntfy, or, set up the quick way, one from Heydrun. If it doesn't, /msg *push set debug on makes the module report what it tried, in the *push query.
Turning it off
Turn off, in the network's settings, or by hand /msg *status unloadmod push, or unloadmod --type=user push if you loaded it for your account.