2021-11-16 16:03:25 +01:00
Send notifications via Matrix
=============================
2024-03-06 14:30:18 +01:00
[](https://github.com/eworm-de/routeros-scripts/stargazers)
[](https://github.com/eworm-de/routeros-scripts/network)
[](https://github.com/eworm-de/routeros-scripts/watchers)
2024-03-28 22:54:23 +01:00
[](https://mikrotik.com/download/changelogs/)
2024-03-06 14:30:18 +01:00
[](https://t.me/routeros_scripts)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick& hosted_button_id=A4ZXBD6YS2W8J)
2023-01-10 14:45:27 +01:00
[⬅️ Go back to main README ](../../README.md )
2021-11-16 16:03:25 +01: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 13:08:49 +01:00
devices. Create and setup an account there, we will reference that as
"*general account*" later.
2021-11-16 16:03:25 +01:00
Configuration
-------------
Edit `global-config-overlay` , add `MatrixHomeServer` , `MatrixAccessToken` and
2022-02-21 18:21:26 +01:00
`MatrixRoom` - see below on hints how to retrieve this information. Then
reload the configuration.
2023-06-07 14:16:08 +02: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 13:08:49 +01: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 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
> ℹ ️ **Info**: The *matrix.org* server uses a Cloudflare certificate. You can
> install that with: `$CertificateAvailable "Cloudflare Inc ECC CA-3"`
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
### From other device
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01: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 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
### Setup new account
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01: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 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
#### Authenticate
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01: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 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
$SetupMatrixAuthenticate "@example:matrix .org" "v3ry-s3cr3t";
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01:00

2022-02-21 18:21:26 +01:00
2024-04-01 23:40:09 +02:00
The configuration is written to a new configuration snippet
`global-config-overlay.d/mod/notification-matrix` .
2023-11-08 13:08:49 +01:00
#### Join Room
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01: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 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
Finally make the *notification account* join into the room by accepting
the invite.
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01:00
$SetupMatrixJoinRoom "!WUcxpSjKyxSGelouhA:matrix.org";
2022-02-21 18:21:26 +01:00
2023-11-08 13:08:49 +01:00

2022-02-21 18:21:26 +01:00
2024-04-01 23:40:09 +02:00
The configuration is appended to the configuration snippet
`global-config-overlay.d/mod/notification-matrix` .
2021-11-16 16:03:25 +01: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 09:52:18 +02:00
But of course you can use the function to send notifications directly. Give
it a try:
2022-06-05 22:50:23 +02:00
2023-11-08 17:29:25 +01:00
$SendMatrix "Subject..." "Body...";
2022-06-05 22:50:23 +02:00
Alternatively this sends a notification with all available and configured
methods:
2023-11-08 17:29:25 +01:00
$SendNotification "Subject..." "Body...";
2022-06-05 22:50:23 +02:00
2023-05-22 09:52:18 +02: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 16:25:52 +02:00
In case there is a situation when the queue needs to be purged there is a
function available:
$PurgeMatrixQueue;
2021-11-16 16:03:25 +01:00
See also
--------
2022-09-23 15:07:30 +02:00
* [Send notifications via e-mail ](notification-email.md )
2023-10-11 07:40:55 +02:00
* [Send notifications via Ntfy ](notification-ntfy.md )
2021-11-16 16:03:25 +01:00
* [Send notifications via Telegram ](notification-telegram.md )
---
2023-01-10 14:45:27 +01:00
[⬅️ Go back to main README ](../../README.md )
[⬆️ Go back to top ](#top )