2021-11-16 15:03:25 +00:00
|
|
|
|
Send notifications via Matrix
|
|
|
|
|
=============================
|
|
|
|
|
|
2023-01-10 13:45:27 +00:00
|
|
|
|
[⬅️ Go back to main README](../../README.md)
|
2021-11-16 15:03:25 +00:00
|
|
|
|
|
|
|
|
|
> ℹ️️ **Info**: This module can not be used on its own but requires the base
|
|
|
|
|
> installation. See [main README](../../README.md) for details.
|
|
|
|
|
|
|
|
|
|
Description
|
|
|
|
|
-----------
|
|
|
|
|
|
|
|
|
|
This module adds support for sending notifications via
|
|
|
|
|
[Matrix](https://matrix.org/) via client server api. A queue is used to
|
|
|
|
|
make sure notifications are not lost on failure but sent later.
|
|
|
|
|
|
|
|
|
|
Requirements and installation
|
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
|
|
Just install the module:
|
|
|
|
|
|
|
|
|
|
$ScriptInstallUpdate mod/notification-matrix;
|
|
|
|
|
|
|
|
|
|
Also install a Matrix client on at least one of your mobile and/or desktop
|
2023-11-08 12:08:49 +00:00
|
|
|
|
devices. Create and setup an account there, we will reference that as
|
|
|
|
|
"*general account*" later.
|
2021-11-16 15:03:25 +00:00
|
|
|
|
|
|
|
|
|
Configuration
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
Edit `global-config-overlay`, add `MatrixHomeServer`, `MatrixAccessToken` and
|
2022-02-21 17:21:26 +00:00
|
|
|
|
`MatrixRoom` - see below on hints how to retrieve this information. Then
|
|
|
|
|
reload the configuration.
|
|
|
|
|
|
2023-06-07 12:16:08 +00:00
|
|
|
|
> ℹ️ **Info**: Copy relevant configuration from
|
|
|
|
|
> [`global-config`](../../global-config.rsc) (the one without `-overlay`) to
|
|
|
|
|
> your local `global-config-overlay` and modify it to your specific needs.
|
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
The Matrix server is connected via encrypted https, and certificate
|
|
|
|
|
verification is applied. So make sure you have the certificate chain for
|
|
|
|
|
your server in device's certificate store.
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
> ℹ️ **Info**: The *matrix.org* server uses a Cloudflare certificate. You can
|
|
|
|
|
> install that with: `$CertificateAvailable "Cloudflare Inc ECC CA-3"`
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
### From other device
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
If you have setup your Matrix *notification account* before just reuse that.
|
|
|
|
|
Copy the relevant configuration to the device to be configured.
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
### Setup new account
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
As there is no privilege separation you should create a dedicated account
|
|
|
|
|
for use with these scripts, in addition to your *general account*.
|
|
|
|
|
We will reference that as "*notification account*" in the following steps.
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
#### Authenticate
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
Matrix user accounts are identified by a unique user id in the form of
|
|
|
|
|
`@localpart:domain`. Use that and your password to generate an access token
|
|
|
|
|
and write first part of the configuration:
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
$SetupMatrixAuthenticate "@example:matrix.org" "v3ry-s3cr3t";
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
![authenticate](notification-matrix.d/01-authenticate.avif)
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
#### Join Room
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
Every Matix chat is a room, so we have to create one. Do that with your
|
|
|
|
|
*general account*, this makes sure your *general account* is the room owner.
|
|
|
|
|
Then join the room and invite the *notification account* by its user id
|
|
|
|
|
"*@example:matrix.org*".
|
|
|
|
|
Look up the *room id* within the Matrix client, it should read like
|
|
|
|
|
"*!WUcxpSjKyxSGelouhA:matrix.org*" (starting with an exclamation mark and
|
|
|
|
|
ending with the domain).
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
Finally make the *notification account* join into the room by accepting
|
|
|
|
|
the invite.
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
$SetupMatrixJoinRoom "!WUcxpSjKyxSGelouhA:matrix.org";
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
![join room](notification-matrix.d/02-join-room.avif)
|
2022-02-21 17:21:26 +00:00
|
|
|
|
|
2023-11-08 12:08:49 +00:00
|
|
|
|
The settings have been appended to `global-config-overlay`. You may want to
|
|
|
|
|
edit to move it to an appropriate place.
|
2021-11-16 15:03:25 +00:00
|
|
|
|
|
|
|
|
|
Usage and invocation
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
There's nothing special to do. Every script or function sending a notification
|
|
|
|
|
will now send it to your Matrix account.
|
|
|
|
|
|
2023-05-22 07:52:18 +00:00
|
|
|
|
But of course you can use the function to send notifications directly. Give
|
|
|
|
|
it a try:
|
2022-06-05 20:50:23 +00:00
|
|
|
|
|
2023-11-08 16:29:25 +00:00
|
|
|
|
$SendMatrix "Subject..." "Body...";
|
2022-06-05 20:50:23 +00:00
|
|
|
|
|
|
|
|
|
Alternatively this sends a notification with all available and configured
|
|
|
|
|
methods:
|
|
|
|
|
|
2023-11-08 16:29:25 +00:00
|
|
|
|
$SendNotification "Subject..." "Body...";
|
2022-06-05 20:50:23 +00:00
|
|
|
|
|
2023-05-22 07:52:18 +00:00
|
|
|
|
To use the functions in your own scripts you have to declare them first.
|
|
|
|
|
Place this before you call them:
|
|
|
|
|
|
|
|
|
|
:global SendMatrix;
|
|
|
|
|
:global SendNotification;
|
|
|
|
|
|
2023-08-06 14:25:52 +00:00
|
|
|
|
In case there is a situation when the queue needs to be purged there is a
|
|
|
|
|
function available:
|
|
|
|
|
|
|
|
|
|
$PurgeMatrixQueue;
|
|
|
|
|
|
2021-11-16 15:03:25 +00:00
|
|
|
|
See also
|
|
|
|
|
--------
|
|
|
|
|
|
2022-09-23 13:07:30 +00:00
|
|
|
|
* [Send notifications via e-mail](notification-email.md)
|
2023-10-11 05:40:55 +00:00
|
|
|
|
* [Send notifications via Ntfy](notification-ntfy.md)
|
2021-11-16 15:03:25 +00:00
|
|
|
|
* [Send notifications via Telegram](notification-telegram.md)
|
|
|
|
|
|
|
|
|
|
---
|
2023-01-10 13:45:27 +00:00
|
|
|
|
[⬅️ Go back to main README](../../README.md)
|
|
|
|
|
[⬆️ Go back to top](#top)
|