immanuelfodor / matrix-encrypted-webhooks

Send any JSON and form data through webhooks to Matrix end-to-end encrypted (E2EE) rooms with HTTP POST requests
MIT License
17 stars 5 forks source link
chatbot docker e2e-encryption e2ee json matrix synapse webhook webhook-server webhooks-catcher yaml

End-to-end encrypted (E2EE) Matrix Webhook Gateway

A microservice that forwards form data or JSON objects received in an HTTP POST request to an end-to-end-encrypted (E2EE) Matrix room. There is no schema restriction on the posted data, so you can throw at it anyting! Supports multiple rooms and sender aliases with different associated webhook URLs, e.g, one for Grafana, another for curl, and so on. Can convert the received payload to JSON or YAML for better message readability, and can apply Markdown formatting to messages. Easy installation with docker-compose.

Table of contents

Usage

cp .env{.example,}
# edit the .env with your preferred editor

mkdir -p store
chown 1000:1000 store
sudo docker-compose up -d --build

# post form data
curl -d 'hello="world"' http://localhost:8000/post/YOURSECRETTOKEN

# post a JSON
curl -H 'Content-Type: application/json' -d '{"hello":"world"}' http://localhost:8000/post/YOURSECRETTOKEN

# post a text file by converting it to a valid JSON array
cat /etc/resolv.conf | jq -R -s -c 'split("\n")' | curl -H 'Content-Type: application/json' -d @- http://localhost:8000/post/YOURSECRETTOKEN

# make posts cleaner by adding all parameters to a curl config file
printf '# @see: https://ec.haxx.se/cmdline-configfile.html
url = "http://localhost:8000/post/YOURSECRETTOKEN"
header = "Content-Type: application/json"
output = /dev/null
silent
' > ~/.matrix.curlrc
/any/command | curl -K ~/.matrix.curlrc -d @-

Configuration

The gateway tries to join all of the specified rooms in the .env file on start. However, you must make sure to invite the webhook user and accept the invite on behalf of them from any client before you start up the gateway!

Available customizations of posted messages

Matrix connection parameters

The notification channels

"Hidden" parameters that need no change most of the time

Dependencies

Installation on Manjaro Linux:

sudo pacman -S docker docker-compose

sudo systemctl enable --now docker

Of course, you'll also need a Matrix server up and running with at least one E2EE room and two users joined in the same room (the webhook user and probably you). Explaining setting these up is way beyond the scope of this document, so please see the online docs for proper instructions, or use a hosted Matrix server.

Development

Install global dependencies, install dev dependencies, create a new virtual environment, install package dependencies, then start the project:

# Manjaro
sudo pacman -S libolm
sudo pip install virtualenv

virtualenv venv

# Fish
source venv/bin/activate.fish

pip install -r requirements.txt

./docker-entrypoint.sh

Troubleshooting

Improvement ideas

Disclaimer

This is an experimental project. I do not take responsibility for anything regarding the use or misuse of the contents of this repository.

Contact

Immánuel Fodor
fodor.it | Linkedin