toc
small changes, started ntfy2call section
subscribing on matrix and listing pushers
To save power some phones running mobile linux like Librem5 and Pinephone suspend when not being used.
In suspended state a linux mobile phone can't receive messages via IP.
There are three ways to wake a mobile linux phone from suspend:
I decided it would be worth a try to call my Librem5 when I want it to check for outstanding messages.
Here's a diagram of my setup:
Watch the boring demo video.
I'll put the details of my proof of concept into this repository. An issue tracker will help to improve this if there's interest.
For questions, comments and corrections please use the issue tracker
Until then you can look at my notes taken while setting this up.
Let's start from the top of the diagram and walk through the branches.
I'm selfhosting a ntfy server. It is a basic setup and everything I did should work using the public server ntfy.sh as well.
To understand the concept it's good to understand the following terms:
The context is visualized nicely on the UnifiedPush Webpage.
To get a notification from the notifcation server you'll need to tell you matrix server that it should use a gateway to UnifiedPush. The gateway converts Matrix Push Format to UnifiedPush. Simplifying things I would say that ntfy understands Matrix Push and converts it into UnifiedPush.
If you use a matrix client that supports UnifiedPush it'd offer you to tell your matrix server to send notifications this way.
Fractal and Chatty do not support UnifiedPush, yet, and anyway for the calling side we'll need to receive notifications.
I used this specification for matrix to subscribe to notifications via requests created by curl
.
First you'll need to authenticate to the matrix server to get a token used in all other operations.
userid = account name in the form of @account:doma.in
# get token
curl -XPOST -d '{"type":"m.login.password", "user":"<userid>", "password":"<password>"}' 'https://<matrix server domain name>/_matrix/client/r0/login' | jq .
Note: <matrix server domain name>
needs not be the same as the domain in your account name @account:doma.in
. doma.in
can be different. To find the <matrix server domain name>
for the doma.in
part of your account you could use curl -X GET 'https://doma.in/.well-known/matrix/server'
(replacing doma.in
with the actual domain of your account. You'll get something like {"m.server": "matrix.doma.in:443"}
telling you that the <matrix server domain name>
for your matrix account is matrix.doma.in
on tcp port 443.
You'll get an anwer like:
{
"user_id": "@account:doma.in",
"access_token": "Q9DaadNCqQvJkeh48KckaleR48KC8902",
"home_server": "doma.in",
"device_id": "GYfViNPhJz"
}
You'll need the access_token which in the example is Q9DaadNCqQvJkeh48KckaleR48KC8902
for the following operatoins.
Once you received your token you can tell your matrix server to send notifications to your ntfy server on some topic:
PUSHER='
"pushkey": "https://<ntfy server>/<topic>?up=1",
"app_id": "me.myself.noapp",
"kind": "http",
"data": {
"url": "https://<ntfy server>/_matrix/push/v1/notify",
"format": "event_id_only"
},
"app_display_name": "ntfy2call",
"device_display_name": "some_device",
"lang": "de"
'
curl -i -X POST "https://<matrix server domain name>/_matrix/client/v3/pushers/set" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token>' \
-d "{${PUSHER}}"
You're free to change the app_id
, app_display_name
and device_display_name
to your likings.
The answer should look like this:
HTTP/2 200
server: nginx
date: Tue, 15 Oct 2024 06:47:13 GMT
content-type: application/json
content-length: 2
[possibly more headers…]
{}
It is just an empty json. To check if the subscription worked you should look at the registered pushers.
curl -s -X GET 'https://<matrix server domain name>/_matrix/client/v3/pushers?access_token=<access_token>' -H 'Accept: application/json' | jq .
The answer looks something like this:
{
"pushers": [
{
"pushkey": "https://<ntfy server>/<topic>?up=1",
"app_id": "my.myself.noapp",
"kind": "http",
"data": {
"url": "https://<ntfy server>/_matrix/push/v1/notify",
"format": "event_id_only"
},
"app_display_name": "ntfy2call",
"device_display_name": "some_device",
"lang": "de"
},
# probably more entries with additional pushers
# if they've been registered by a client supporting
# UnifiedPush the topic will start with 'up'
]
}
TODO - if you know please let me know by an issue
TODO - if you know please let me know by an issue
To test notifications generated by the matrix server you can open the web gui of ntfy (login if needed) and subscribe to the topic you set on the matrix server for notifications.
Once the matrix server generates a notification you'll get the notification on the web gui.
If this works you completed successfully the configuration of matrix and ntfy.
Now that notifications through ntfy are set up and working you'll need to make sure that your phone is woken when a new notification arrives.
I solved this part by making a phone call to my Librem5 to have the modem wake up the CPU from suspend.
The same effect could be achived by sending an SMS. SMS has the advantage that it is clearly within the contract your using. Calling without ever having the intention of picking up the call might be signaling without paying for it. You need to check your situation and decide.
Using SMS costs money, but offers two advantages:
chatty
. For calls an extra component (Phosh Anti-Spam) is needed.Furthermore Guido Günther is thinking about a notification distributor build into chatty that would allow acting on behalf of the content of the notification-SMS: start the app that subscribed to the notification topic of the SMS and provide the notification content.
That said: I'll probably change my setup towards SMS once these things work and pay a few €/month to get an SMS flatrate for some SIM to be used to send the notification SMS.