Coder Social home page Coder Social logo

tiny-matrix-bot's Introduction

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:

  • TMB_HOMESERVER = https://example.com
  • TMB_ACCESS_TOKEN = ABCDEFGH
  • TMB_USER_ID = @bot:example.com

Optional environment variables:

  • TMB_SCRIPTS_PATH = scripts-enabled (this value is used when unset)
  • TMB_ACCEPT_INVITES = :example\.com$ (derived from TMB_USER_ID when unset)
  • TMB_PROXY = http://proxy.example.com:3128 (this value is an example, see matrix-nio documentation)

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:

  • TMB_ROOM_ID
  • TMB_SENDER
  • TMB_BODY

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

tiny-matrix-bot's People

Contributors

4nd3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.