Skip to content

Instantly share code, notes, and snippets.

@mpeter50
Last active May 13, 2024 21:04
Show Gist options
  • Save mpeter50/9220dac1056c9a66c313d049838c1ab2 to your computer and use it in GitHub Desktop.
Save mpeter50/9220dac1056c9a66c313d049838c1ab2 to your computer and use it in GitHub Desktop.
Matrix-Ntfy debugging advices for 2024 Q2

This guide has been written for element-hq/element-android#7069: UnifiedPush (ntfy) not working.
A lot of users has reported that they have problems, but I think most of the comments are not really helpful to be able to diagnose the issue.

I think I have found a few ways to test whether a few very specific parts of the notification pipeline are working or not.
An important tool in these tests is the Ntfy webapp: https://ntfy.sh/app
This is hosted by binwiederhier, the developer of Ntfy, and who runs the main Ntfy instance that is used by the matrix.org homeserver, so this webapp is safe to use on your own computers.

I have written the below guide

  • because Ntfy Matrix notifications does not work for me either, other than the test notification from the troubleshoot menu
  • and so that the devs are seeing my testing methodology, so they can have a better idea on what is failing

Testing the Ntfy Android app

First I would start with how you can test whether the Android app works correctly, and in turn whether it receives the notifications as it should.
For now we are leaving Matrix out of the test, for the sake of simplicity.

Short term test

For a quick test, do the following:

  1. create a new notification topic using the Ntfy webapp by subscribing to it (it is then created automatically)
  2. subscribe to the same topic with the android app (double check that you havent mistyped the topic name)
  3. place the android app in the background
  4. send a test notification using the web app. You can do so with the text input field at the bottom of the page, when a topic is opened.

This is fine for a quick test, but since you have just recently opened the android app, maybe it will only fail later, when it went unused for hours or such.

Long term test

For a long term test, open the android app and also subscribe to the stats topic. This is the URL: https://ntfy.sh/stats
The server publishes usage statistics to this topic every day at around 23:58 in.. I think according to UTC time zone.
My phone has been subscribed to this channel for the past weeks and it has received every single statistics notification exactly at 23:58.
You too can use this channel to test the long term stability of the app on your phone, to see if the OS has killed it or whatever has happened to it.

On my phone, there is no problem with these.

Testing the matrix.org homeserver whether it successfully sends the notification to the ntfy.sh Ntfy server

I consider this to be the next step, as it involves exactly one additional party in the notification pipeline. If the Ntfy Android app is working, but this isn't, your problem probably involves an issue between ntfy.sh and matrix.org servers.

Be sure to follow the below steps with an account from matrix.org.
After that, you may test with your other homeserver, but if you have issues first always test with matrix.org.

Even though we are not yet testing the Element Android app (the original one, not Element X!), we need to involve it too at this point, as I dont see a way in Element Web to set up Ntfy, or even just to check the list of current notification targets, that tell the Matrix homeserver where it should send the notifications.

So, install either Element Android, or SchildiChat (its a fork of it that is very similar), preferably from the main F-droid repository as thats what I'm testing with, and log in to your account. For the record, I'm using SC 1.6.12.sc77.
Wait until synchronization completely catches up, and no progress bar is moving anymore, because I was able to freeze the app with changing the notification provider in the settings while it was processing something.
Then, go to Settings > Notifications, and change the "Notification method" to "ntfy". If the option doesnt appear there, thats probably because the app does not see the Ntfy app. Be sure that you have it installed, in the same profile.

At this point the Matrix homeserver is told by the app, that it should send notifications to Ntfy. It does not ask which Ntfy server, it probably always sets up ntfy.sh. Now you need to check if this setup has actually happened. You are still in the "Settings > Notifications" menu in SC or Element Android, and at the bottom of the menu, open "Notification targets".
You should have a "HTTP PUSHER" target with push key like https://ntfy.sh/up***********, and a few other attributes. The push key is sensitive info, do not publish it!
If you have more than one HTTP PUSHER entries, thats probably not a problem technically, but it will make it harder for you to continue testing. In that case I recommend you to click "REMOVE" for all "HTTP PUSHER" entries (you may want to keep others, like "EMAIL PUSHER"), then in the previous menu switch "Notification method" back to background sync and then again to "ntfy". Verify the Notification target again.

The next step is now the actual testing.
On your desktop computer open your web browser, and inside it open the URL that is the push key shown in the mobile app. This should look like https://ntfy.sh/up******** which is again, sensitive, do not post it publicly. By doing this, you have opened the Ntfy webapp, and will see all notifications that the Ntfy server has received from matrix.org.

Finally, trigger some kind of notification for your account, and see if it arrives in the Ntfy webapp. Either use a secondary account to send a message in a private room where both of your accounts are members, or find a room that is very, very busy. Former is easier and better for testing.
Be sure to set this room to have you receive notifications for all messages. Set it up that way for both of your accounts to minimize mistakes.

screenshot of that setting

If you see the notifications in the Ntfy webapp, then this is working.
If you dont, it isnt, and probably there is some kind of problem between matrix.org and ntfy.sh. Or you have mistyped the topic.
I dont see them. Topic is corect.

You can verify whether you have correctly typed the topic using SC/Element Android: Open the troubleshoot notifications menu. The test notification should arrive in the Ntfy webapp in the same topic after the "Test Push" step is executed.
As I see this test should always work rergardless of the issue we are discussing, it seems as if it would not test the actual full pipeline.

Testing the full pipeline

If the above tests did not reveal any problem, you may test the full notification pipeline. Basically you do the same as when you have tested the matrix.org <-> ntfy.sh connection in the previous point, and while you should still check that notifications arrive in the webapp, you should also check the logs of the Ntfy Android app, and maybe those of SC/Element Android too.

In the Ntfy Android app, open the settings, and flip on "Record logs". After that, you'll be able to copy or upload the logs to the paste service of Ntfy's developer. Remember that these logs will have your sensitive topic names!!!
If you are more convenient with the ADB tools and logcat, the logs are printed there too. The app should log info about the processing of every incoming notification.

In your Matrix client, its good question.. I would say turn on all logging options and watch the logcat. I dont have a better idea.
When watching logcat, you could filter by the app's process id so that you see less noise, but you may miss warning messages from the OS itself that tell that the app couldnt receive the broadcast for some reason.

Closing words

Many of you have said that the app is receiving the notification as soon as you open it.
Those notifications are most probably not arriving through Ntfy, but through the app's internal sync mechanism, which is independent of it.

My conclusion is that to me it seems the issue is between ntfy.sh and matrix.org, at least in those cases when notifications consistently dont arrive.
Those who have said that Ntfy notifications broke for them, they may have a different issue (possibly even on top of this one), or it may be a concidence (probably unlikely).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment