hemlock-sendmsg
is a small daemon for sending push notifications to the Hemlock mobile apps.
- Install
hemlock-sendmsg
on the machine which runs Evergreen action triggers. - In the Firebase Console, create a service account with the
cloudmessaging.messages.create
permission, create a service account key, and save it to thehemlock-sendmsg
install directory asservice-account.json
. For detailed instructions, see the Setup Guide to Push Notifications. - Start the server
$ ./hemlock-sendmsg
2024/04/20 13:07:25 initializing firebase with credentials file service-account.json
2024/04/20 13:07:25 listening on localhost:8842
Use -addr [host:port]
to change the server's address and port.
Use -credentialsFile [path]
or the GOOGLE_APPLICATION_CREDENTIALS
environment variable to change the location of the service account key.
POST to /send with parameters:
title
- the title of the notificationbody
- the body text of the notificationtoken
- the FCM registration tokentype
- the push notification type, controls the app screen that launches when you tap the notification; "pmc" for Patron Message Center, "main" for the main screendebug
- if not empty and not "0", log the call to stdout
For example:
$ token="f2uw...Sv2o"
$ curl -F token="$token" -F title="New Message" -F body="DM $(date '+%a %H:%M')" -F type=pmc -F debug=1 localhost:8842/send
ok
Will cause hemlock-sendmsg
to log something like:
2024/04/29 17:45:21 INFO POST /send result=ok code=200 username="" title="New Message" body="DM Mon 17:45" token=fHC...sQy
The push notification token is stored after login as a user setting. So to find the push notification token for the 'hemlock' user, you could issue the SQL query:
evergreen=# select s.value from actor.usr_setting s
join actor.usr u on u.id=s.usr
where usrname='hemlock' and s.name='hemlock.push_notification_data';
value
-------------
"fwql...y-MU"
(1 row)
GET /metrics
The metrics includes golang runtime and some other stats as well as internal stats in Prometheus format. To see just the internal status, grep for "hemlock_", e.g.
$ curl -sS localhost:8842/metrics | grep hemlock_
# HELP hemlock_notifications_sent_total Notifications sent, by result
# TYPE hemlock_notifications_sent_total counter
hemlock_notifications_sent_total{result="EmptyToken"} 1
hemlock_notifications_sent_total{result="ok"} 2