How to use my hosted ntfy instance

public - Will show date when possible

One really cool thing I'm happy to have self-hosted is ntfy.sh, which makes it easy to privately and securely get push notifications on my devices when tasks complete. I'd like to document how to use this, since other members of my household will likely need it, and I don't want to forget either!

Fundamentally, you want something like this in your ~/.bashrc:

export NTFY_TOKEN="tk_blahblahblah"
export NTFY_DEFAULT_TOPIC="maddie-alerts"
ntfy() {
  local msg="$1"
  local topic="$2"
  if [ -z "$topic" ]; then
    topic="$NTFY_DEFAULT_TOPIC"
  fi
  curl -d "$msg" \
    -H "Authorization: Bearer $NTFY_TOKEN" \
    "https://ntfy.maddiem4.cc/$topic"
}

Once you have that in your shell, you can do stuff like:

ntfy "Send this alert to my default topic"
ntfy "And now an alert for a specific topic" specific-topic

It's those exports you'll want to customize. Your default topic can be whatever you want (as long as you have access to it). But what about the token? Well, you have to ask me, and here's what I end up having to do on the host machine.

ssh indiana.local
cd ~/projects/personal_site
docker-compose exec -it ntfy ntfy user add --role=admin yourname # if necessary
docker-compose exec -it ntfy ntfy token add --label yourcomputer yourname

You'll need to pick a password. I don't want to know it, but make sure it's written down. You'll need it for subscribing via the phone app too. Once you've put it in during the user creation prompt, I can give you the resulting token for use in your .bashrc.