Heydrun

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

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

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:

  1. Turn on Push notifications in Settings, IRC.
  2. 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.
  3. 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.
  4. Choose Set up.

Heydrun then talks to ZNC for you, and ZNC's answers appear in the server buffer:

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:

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.