From 36d8ea281cc4721d8b9c5d6b6793a2ee92b47f08 Mon Sep 17 00:00:00 2001 From: James Collier <26444312+MaybeJustJames@users.noreply.github.com> Date: Fri, 6 Jan 2023 20:09:07 +1100 Subject: [PATCH] Allow the mautrix whatsapp relaybot to be enabled with a variable (#2381) * Allow the mautrix whatsapp relaybot to be enable with a variable This allows a user to enable the relaybot by setting a variable in `vars.yml` in the same way that the mautrix signal relaybot is configured. * Correct default values for mautrix whatsapp relaybot variables * Add documentation for using the relaybot with mautrix whatsapp * Adjust variable names to better reflect what they do * Set default variables properly and use to_json in template --- .../configuring-playbook-bridge-mautrix-whatsapp.md | 13 +++++++++++++ .../defaults/main.yml | 6 ++++++ .../templates/config.yaml.j2 | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/configuring-playbook-bridge-mautrix-whatsapp.md b/docs/configuring-playbook-bridge-mautrix-whatsapp.md index 8ae6e5a0..b08556fe 100644 --- a/docs/configuring-playbook-bridge-mautrix-whatsapp.md +++ b/docs/configuring-playbook-bridge-mautrix-whatsapp.md @@ -11,6 +11,19 @@ matrix_mautrix_whatsapp_enabled: true ``` Whatsapp multidevice beta is required, now it is enough if Whatsapp is connected to the Internet every 2 weeks. +The relay bot functionality is off by default. If you would like to enable the relay bot, add the following to your `vars.yml` file: +```yaml +matrix_mautrix_whatsapp_bridge_relay_enabled: true +``` + +By default, only admins are allowed to set themselves as relay users. To allow anyone on your homeserver to set themselves as relay users add this to your `vars.yml` file: +```yaml +matrix_mautrix_whatsapp_bridge_relay_admin_only: false +``` + +If you want to activate the relay bot in a room, use `!whatsapp set-relay`. +Use `!whatsapp unset-relay` to deactivate. + ## Enable backfilling history This requires a server with MSC2716 support, which is currently an experimental feature in synapse. Note that as of Synapse 1.46, there are still some bugs with the implementation, especially if using event persistence workers. diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml index 1307d09e..3a722eeb 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml @@ -102,6 +102,12 @@ matrix_mautrix_whatsapp_bridge_permissions: | | combine({matrix_admin: 'admin'} if matrix_admin else {}) }} +# Enable bridge relay functionality +matrix_mautrix_whatsapp_bridge_relay_enabled: false + +# Only allow admins on this home server to set themselves as a relay user +matrix_mautrix_whatsapp_bridge_relay_admin_only: true + # Default mautrix-whatsapp configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 index 4b5af2e9..0962ac4d 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 @@ -396,9 +396,9 @@ bridge: relay: # Whether relay mode should be allowed. If allowed, `!wa set-relay` can be used to turn any # authenticated user into a relaybot for that chat. - enabled: false + enabled: {{ matrix_mautrix_whatsapp_bridge_relay_enabled | to_json }} # Should only admins be allowed to set themselves as relay users? - admin_only: true + admin_only: {{ matrix_mautrix_whatsapp_bridge_relay_admin_only | to_json }} # The formats to use when sending messages to WhatsApp via the relaybot. message_formats: m.text: "{{ '{{ .Sender.Displayname }}' }}: {{ '{{ .Message }}' }}"