Queue Processor script for Matrix
Go to file
Olivier 'reivilibre' ad51026405 Fix failures on first run 2021-01-31 18:52:47 +00:00
.gitignore Initial commit. 2021-01-31 17:17:17 +00:00
LICENSE-2.0.txt Initial commit. 2021-01-31 17:17:17 +00:00
README.md Initial commit. 2021-01-31 17:17:17 +00:00
mxqueueproc.py Fix failures on first run 2021-01-31 18:52:47 +00:00
requirements.txt Initial commit. 2021-01-31 17:17:17 +00:00

README.md

Matrix Queue Processor (matrix_queue_proc)

This is a quickly-thrown-together script which will:

  • retrieve unread text messages in a Matrix room
  • execute a script of your choice for each one
    • mark ( reaction) or redact those messages on success (0); or
    • reply with the process's exit code on failure.
  • exit once all those messages are processed.
    • (it is currently intended for occasional usage rather than continuous usage, but continuous usage may appear in the future.)

Use cases

  • archiving (youtube-dl, archivebox, etc...)
    • e.g. using the 'Share' function on a mobile phone to enqueue links

Usage

python3 mxqueueproc.py <room ID> <command to run>

If you prefer messages to be redacted rather than -reacted, use

MXQP_REDACT=1 python3 mxqueueproc.py <room ID> <command to run>

e.g.

python3 mxqueueproc.py !some_room_id:example.com youtube-dl

Installation and set-up

  • Set up a Python 3 virtual environment python3 -m venv path/to/venv
  • Activate it! . path/to/env/activate
  • Install requirements pip install -r requirements.txt
  • Activate this venv again whenever you wish to run mxqueueproc.

On first run, Matrix Queue Processor will guide you through a login.

You will need:

  • your homeserver URL (e.g. https://matrix.org)
  • your username (e.g. reivilibre)
  • your password (e.g. nottellingYOUofcourse)

For more advanced commands

For more complicated commands, it may be worthwhile (or even required) to create e.g. a bash script

#!/bin/bash
set -eu
task=$1

do_something --serious-business --wow=very $1

(set -eu makes undefined variables and command errors cause failure, so that the bot will report it to you.)

Don't forget to mark it as executable.