### Enable and Start Mautrix-WhatsApp Service Source: https://github.com/mautrix/whatsapp/wiki/systemd-unit Command to enable the mautrix-whatsapp service to start on boot and immediately start it. ```bash systemctl enable --now mautrix-whatsapp ``` -------------------------------- ### Run the mautrix-whatsapp bridge Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup Start the bridge application after configuration. Ensure the config.yaml and registration.yaml files are correctly set up and referenced. ```bash ./mautrix-whatsapp ``` -------------------------------- ### Install Android SDK Components Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Installs necessary SDK components for Android development. Ensure the correct platform and system image versions are specified. ```shell ./tools/bin/sdkmanager --install platform-tools ./tools/bin/sdkmanager --install "platforms;android-24" ./tools/bin/sdkmanager --install "system-images;android-24;default;armeabi-v7a" ``` -------------------------------- ### Install APK using ADB Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Use ADB to install an APK file onto an Android emulator. This is an alternative to installing via Google Play. ```shell adb install APK_FILE ``` -------------------------------- ### Run mautrix-whatsapp Docker container Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Start the bridge in detached mode with persistent storage and port mapping. Use `--network=host` if using a local PostgreSQL database. ```bash docker run --restart unless-stopped -p 29318:29318 -v `pwd`:/data:z dock.mau.dev/tulir/mautrix-whatsapp:latest ``` -------------------------------- ### Docker Compose configuration for mautrix-whatsapp Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Example Docker Compose service definition for the mautrix-whatsapp bridge. Ensure volumes and environment variables are set correctly. ```yaml version: "3.7" services: mautrix-whatsapp: container_name: mautrix-whatsapp image: dock.mau.dev/tulir/mautrix-whatsapp:latest restart: unless-stopped environment: - UID=XXXX # (optional) User id of your docker user. Make sure to use the same one for your server (synapse). - GID=XXXX # (optional) Group id of your docker user. volumes: - ./mautrix-whatsapp/:/data # Use a sub directory if you plan to run another bridge. ``` -------------------------------- ### Start WhatsApp Main Activity Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Force start the WhatsApp main activity on an Android Virtual Device (AVD). This can be used to revive a sleeping or unresponsive emulator. Specify the device serial if not using the default. ```shell am start -n 'com.whatsapp/.HomeActivity' ``` ```shell adb [-s DEVICE_SERIAL] shell am start -n 'com.whatsapp/.HomeActivity' ``` -------------------------------- ### Clone the mautrix-whatsapp repository Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup Use this command to clone the bridge's source code from GitHub. Ensure Git is installed. ```bash git clone https://github.com/tulir/mautrix-whatsapp.git ``` -------------------------------- ### Run Android Emulator Headless Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Launch the Android emulator without a graphical interface. This is useful for running on servers or in automated environments. Ensure the emulator and system images are installed. ```shell ./emulator/emulator -avd AVD_NAME -no-audio -no-window [options] ``` -------------------------------- ### Migrate mautrix-whatsapp Database Source: https://github.com/mautrix/whatsapp/wiki/Database-migration Use this command to migrate the database from one type to another, for example, from SQLite to PostgreSQL. Ensure the bridge is stopped and the configuration is updated before running. ```bash mautrix-whatsapp --migrate-db ``` -------------------------------- ### Stop Bridge Service Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Commands to stop the mautrix-whatsapp bridge service, necessary before performing direct database modifications. Examples are provided for Docker and systemd. ```bash docker stop containerID ``` ```bash systemctl stop matrix-mautrix-whatsapp.service ``` -------------------------------- ### Mautrix-WhatsApp Systemd Service Unit Source: https://github.com/mautrix/whatsapp/wiki/systemd-unit This is a systemd unit file for the mautrix-whatsapp bridge. Ensure `User`, `WorkingDirectory`, and `ExecStart` are correctly configured for your installation. After creating or modifying this file, run `systemctl daemon-reload`. ```systemd [Unit] Description=mautrix-whatsapp bridge After=network.target [Service] Type=exec User=mautrix-whatsapp WorkingDirectory=/opt/mautrix-whatsapp ExecStart=/opt/mautrix-whatsapp/mautrix-whatsapp Restart=on-failure RestartSec=30s # Optional hardening to improve security ReadWritePaths=/opt/mautrix-whatsapp NoNewPrivileges=yes MemoryDenyWriteExecute=true PrivateDevices=yes PrivateTmp=yes ProtectHome=yes ProtectSystem=strict ProtectControlGroups=true RestrictSUIDSGID=true RestrictRealtime=true LockPersonality=true ProtectKernelLogs=true ProtectControlGroups=true ProtectKernelTunables=true ProtectHostname=true ProtectKernelModules=true PrivateUsers=true ProtectClock=true SystemCallArchitectures=native SystemCallErrorNumber=EPERM SystemCallFilter=@system-service [Install] WantedBy=multi-user.target ``` -------------------------------- ### Run mautrix-whatsapp Docker container to generate config Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Execute this command to create the initial configuration file for the bridge. Ensure you are in the bridge's directory. ```bash docker run --rm -v `pwd`:/data:z dock.mau.dev/tulir/mautrix-whatsapp:latest ``` -------------------------------- ### Compile mautrix-whatsapp with build.sh Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup Execute the build script to compile the bridge. It fetches Go dependencies and builds the executable. Use flags like -tags nosas for libolm2 compatibility or -tags nocrypto to disable encryption. ```bash ./build.sh ``` ```bash ./build.sh -tags nosas ``` ```bash ./build.sh -tags nocrypto ``` -------------------------------- ### Feed Desktop to Virtual Webcam Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Uses ffmpeg to capture the desktop screen and stream it to a virtual webcam device (`/dev/video0`). Adjust screen capture parameters (`-s`, `-i`) as needed. ```shell ffmpeg -f x11grab -s 640x480 -i :0.0+10,20 -vf format=pix_fmts=yuv420p -f v4l2 /dev/video0 ``` -------------------------------- ### Load v4l2loopback Module Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Loads the v4l2loopback kernel module, which is necessary for creating virtual video devices. This command should be run with root privileges. ```shell modprobe v4l2loopback ``` -------------------------------- ### Run Android Emulator Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Launches an Android Virtual Device. Options can be used to control audio, video, kernel display, snapshot usage, and memory. ```shell ./emulator/emulator -show-kernel -no-boot-anim -avd AVD_NAME ``` ```shell ./emulator/emulator -avd AVD_NAME -camera-back webcam0 ``` ```bash ./emulator/emulator -avd AVD_NAME [options] ``` -------------------------------- ### Configure Synapse homeserver.yaml for app service Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Specify the path to the mautrix-whatsapp registration file within your Synapse homeserver configuration. ```yaml app_service_config_files: - "/path/to/your/mautrix-whatsapp/registration.yaml" ``` -------------------------------- ### Generate Appservice Registration File Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup Run the bridge executable with the -g flag to generate the application service registration file. This file is required for the Matrix homeserver to recognize the bridge. Use -c and -r flags to specify custom paths for config and registration files. ```bash ./mautrix-whatsapp -g ``` ```bash ./mautrix-whatsapp -c myconfig.yaml -r myregistration.yaml ``` -------------------------------- ### Create Android Virtual Device (AVD) Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Creates a new Android Virtual Device with a specified name and SDK ID. The AVD will be located in ~/.android/avd/. ```shell ./tools/bin/avdmanager create avd -n AVD_NAME -k SDK_ID ``` -------------------------------- ### Enter SQLite Database Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Use this command to access the mautrix-whatsapp bridge's SQLite database for manual data manipulation, such as updating portal information. ```bash sqlite3 /matrix/mautrix-whatsapp/data/mautrix-whatsapp.db ``` -------------------------------- ### Docker Compose configuration for mautrix-whatsapp appservice Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Configure the appservice address and hostname within the bridge's config.yaml when using Docker Compose. This assumes Synapse is also defined in the same docker-compose.yml. ```yaml homeserver: address: https:// domain: appservice: address: http://mautrix-whatsapp:29318 # depends on the name you chose in the `docker-compose.yml`. Only works if synapse is defined in the same docker-compose.yml. hostname: mautrix-whatsapp ``` -------------------------------- ### Create New WhatsApp Group Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Run this command in a Matrix room to create a new WhatsApp group. Ensure the bridge bot is invited to an empty, encrypted room and that the room has a name. ```text !wa create ``` ```text !wa relaybot create ``` -------------------------------- ### Configure Synapse app service registration Source: https://github.com/mautrix/whatsapp/wiki/Bridge-setup-with-Docker Add the path to the generated registration file in your Synapse homeserver configuration. ```yaml app_service_config_files: - "/path/to/your/mautrix-whatsapp/registration.yaml" ``` -------------------------------- ### Configure Webcam Device Source: https://github.com/mautrix/whatsapp/wiki/Android-VM-Setup Renames device files to make a specific video device appear as the default `/dev/video0` for the Android emulator. This is useful if the desired webcam is not already `/dev/video0`. ```shell # needed if you want to feed /dev/video2 to the AVD sudo mv /dev/video0 /dev/video0.original sudo mv /dev/video2 /dev/video0 ``` -------------------------------- ### List WhatsApp Groups Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Use this command in the relaybot management room to list available WhatsApp groups. This is useful for finding the JID of a group you wish to bridge. ```text !wa relaybot list groups ``` ```text !wa list groups ``` -------------------------------- ### Login Relaybot to WhatsApp Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Use the standard login command in the relaybot management room to log the relaybot into WhatsApp. This command affects the relaybot, not your personal account. ```text !wa login ``` -------------------------------- ### Update Portal MXID in Database Source: https://github.com/mautrix/whatsapp/wiki/Relaybot This SQL command is used to manually bridge an existing Matrix room to a WhatsApp group by updating the portal's Matrix ID (mxid) in the database. Replace '' with the Matrix room's internal ID and 'groupid@g.us' with the WhatsApp group's JID. The bridge must be stopped before running this command. ```sql UPDATE portal SET mxid='' WHERE jid='groupid@g.us'; ``` -------------------------------- ### Logout User from WhatsApp Source: https://github.com/mautrix/whatsapp/wiki/Relaybot Before logging in the relaybot with a WhatsApp account, use this command in your normal management room to log out your personal account if it's already in use. ```text !wa logout ``` -------------------------------- ### Reload Systemd Daemon Source: https://github.com/mautrix/whatsapp/wiki/systemd-unit Command to reload the systemd manager configuration after creating or modifying a unit file. ```bash systemctl daemon-reload ``` -------------------------------- ### Query WhatsApp Group JID from Database Source: https://github.com/mautrix/whatsapp/wiki/Relaybot If a WhatsApp group is not found via commands, you can query its JID directly from the bridge's SQLite database. Replace 'WhatsApp_Group_Name' with the actual group name. ```sql SELECT * FROM portal WHERE name='WhatsApp_Group_Name'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.