Home

Awesome

tiny-matrix-bot

Simple (and tiny!) Matrix bot based on matrix-nio.

Bot triggers on messages matching regular expressions, runs corresponding script and sends output to room.

That's it.

Sans E2EE support, I consider this bot feature complete, but not bug free.

PRs are welcome, but no promises are given. You might be better off with fork.

Installation

It goes roughly like this:

sudo pip3 install matrix-nio
git clone https://github.com/4nd3r/tiny-matrix-bot
cd tiny-matrix-bot/scripts-enabled/
find ../scripts-available/ -type f -exec ln -s {} \;
cd ..
cp tiny-matrix-bot.env.sample tiny-matrix-bot.env
vim tiny-matrix-bot.env
./tiny-matrix-bot.sh

Configuration

Required environment variables:

Optional environment variables:

Scripts

Scripts can be written in any language and they MUST have +x bit set.

Setting the trigger

Bot sets an environment variable CONFIG and runs the script.

Manual example:

$ CONFIG=1 scripts-available/ping
^!?ping(!|\?)?$

Standard output MUST contain Python compatible regular expression.

Matching is case-insensitive.

Running triggered scripts

Following environment variables are set:

Manual example:

$ TMB_BODY='1Ms 1:1' scripts-available/piibel 
Alguses lõi Jumal taeva ja maa.

Non-empty standard output (if exit code is zero) will be sent to room as plain text.

Empty line between non-empty lines will separate messages.

To mimic interaction, messages are sent with small delay.

Running with systemd

Bot itself don't need to write persistent data, so read-only system access for long running service is reasonable thing to have, hence ProtectSystem=strict and friends.

However, if script wants to write persistent data, then write path MUST be allowed using ReadWritePaths= in systemd unit [Service] section. See systemd documentation for details.

Previous versions