An IRC bouncer-style Matrix Bridge to access the Tox network
  • Python 96.8%
  • Shell 2.1%
  • Dockerfile 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Brendan Kidwell f0b68cb404
Some checks failed
CI / arm64 (push) Has been skipped
CI / test (push) Has been cancelled
typo
2026-11-19 00:15:15 -05:00
.github/workflows M6: packaging and documentation 2026-11-17 18:45:07 -05:00
contrib M6: packaging and documentation 2026-11-17 18:45:07 -05:00
dev M6: packaging and documentation 2026-11-17 18:45:07 -05:00
doc M6: packaging and documentation 2026-11-17 18:45:07 -05:00
docker/patches M0: spike pytox with c-toxcore v0.2.25 in Docker 2026-11-17 17:18:51 -05:00
matrix_bridge_tox M6: packaging and documentation 2026-11-17 18:45:07 -05:00
spike M0: spike pytox with c-toxcore v0.2.25 in Docker 2026-11-17 17:18:51 -05:00
tests M6: packaging and documentation 2026-11-17 18:45:07 -05:00
.gitignore M6: packaging and documentation 2026-11-17 18:45:07 -05:00
CLAUDE.md Add project plan, license and agent notes 2026-11-17 16:58:18 -05:00
Dockerfile M6: packaging and documentation 2026-11-17 18:45:07 -05:00
LICENSE Add project plan, license and agent notes 2026-11-17 16:58:18 -05:00
NOTICE M6: packaging and documentation 2026-11-17 18:45:07 -05:00
pyproject.toml M1-M5: appservice bridge with profiles, friends, outbox, groups and files 2026-11-17 18:06:08 -05:00
README.md typo 2026-11-19 00:15:15 -05:00

matrix-bridge-tox

A bouncer-style Matrix appservice that bridges to the Tox network, modelled on Heisenbridge.

Each authorized Matrix user on your homeserver gets their own Tox identities ("profiles"). The bridge keeps them online around the clock, so to their Tox friends they look like ordinary, always-reachable Tox users. It is a personal Tox client that lives on your server; it does not relay shared rooms between many Matrix and Tox users.

This application was built with the help of an LLM agent.

Production-Readiness Status

This is new software created in November 2026. I (Brendan Kidwell) am using it to talk to one Tox friend on my own home Matrix Synapse server. It works, but no one else is using it yet and it hasn't been tested much.

By January 2027 I hope to clean up the installation procedure, perhaps package a .deb and/or an AppImage, add more documentation pages, and make a first official release.

Contact me if you want to be involved or need help installing it on your own server.

Features

  • Several Tox identities per Matrix user: create new ones, or import and export .tox files from qTox, Toxic and other clients.
  • Heisenbridge-style text commands: a control room with the bridge bot, one room per profile, one direct chat per Tox friend, one room per Tox group chat.
  • Friend requests in and out, text and /me messages both ways, typing notifications, presence, names and status messages, avatars both ways.
  • Offline delivery: Tox has no offline messages, so the bridge queues what you send while a friend is offline and delivers it when they come online. Queued messages carry a ⏳ reaction until the friend's client confirms receipt, and the friend's puppet then marks the message as read.
  • Long messages are split to fit Tox's limit; replies are sent with a quote of the original, and edits as * corrected text.
  • File transfers both ways with configurable size limits.
  • NGC group chats (the current Tox group system): create, join, invite, accept invites, leave, topics, nicknames, moderation notices. Group members appear as Matrix puppets.
  • Tox identities are encrypted at rest with a bridge-held key and reconnect unattended after restarts.
  • SQLite by default, PostgreSQL optional.

Not supported (yet): audio and video calls, end-to-end encrypted Matrix rooms, legacy Tox conferences, relay/plumbed rooms.

Trust model

Your Tox identity (its secret key) is stored on the server running the bridge, encrypted with a key that the bridge holds so it can bring your identity online after a restart without asking you. The server operator can therefore use your Tox identity, just as they can read your unencrypted Matrix rooms. If you can't trust the operator, run your own homeserver and bridge.

Requirements

  • A Matrix homeserver that supports appservices. These instructions use Synapse.
  • Docker (recommended), or Python ≥ 3.11 plus a C toolchain to build c-toxcore.
  • Ideally, a range of UDP ports forwarded from your Internet router to the bridge host (one per Tox profile). Without forwarding, Tox still works through hole punching and TCP relays, just less directly.

The bridge ships with c-toxcore v0.2.25 and a pinned build of TokTok's pytox binding. See doc/M0-SPIKE.md for why these versions.

Installation with Docker

1. Build the image

git clone https://git.glump.net/brendan-apps/matrix-bridge-tox.git
cd matrix-bridge-tox
docker build -t matrix-bridge-tox:latest .

The build compiles c-toxcore and pytox and takes a few minutes (longer on a Raspberry Pi). The Dockerfile works on amd64 and arm64; contrib/build-multiarch.sh builds both with docker buildx.

2. Write the config

mkdir data
docker run --rm matrix-bridge-tox:latest --example-config > data/config.yaml

Edit data/config.yaml. At minimum set:

homeserver:
  url: http://127.0.0.1:8008   # Synapse's client API, as seen from the bridge
  domain: example.org          # your server name
appservice:
  url: http://127.0.0.1:9898   # how Synapse reaches the bridge
bridge:
  owner: "@you:example.org"    # admin of the bridge
  allow: ["@*:example.org"]    # who may use it (optional)

All options are documented in the example config (matrix_bridge_tox/data/example-config.yaml).

3. Generate the registration file

docker run --rm --user "$(id -u):$(id -g)" -v "$PWD/data:/data" matrix-bridge-tox:latest -c /data/config.yaml -g

This writes data/registration.yaml with fresh tokens. Re-running it refuses to overwrite the file unless you add --force (which changes the tokens, so Synapse must be updated too).

4. Set up Synapse

Make the registration file readable by Synapse (copy it next to homeserver.yaml if they run as different users or in different containers) and add to homeserver.yaml:

app_service_config_files:
  - /path/to/registration.yaml

# The bridge bot cannot read encrypted rooms. Don't force encryption for new rooms:
encryption_enabled_by_default_for_room_type: "off"

# Optional: lets puppets show Tox friends' online status.
presence:
  enabled: true

Restart Synapse.

5. Start the bridge

contrib/docker-compose.yml is a ready example:

cp contrib/docker-compose.yml .
sudo chown -R 1337:1337 data     # the image runs as uid/gid 1337
docker compose up -d
docker compose logs -f

On first start the bridge creates data/toxbridge.key, the key that encrypts all Tox identities. Back it up (see Backups).

The example uses host networking, so the 127.0.0.1 addresses in the config work unchanged and toxcore binds its UDP ports directly on the host. It also shows the alternative with Docker's bridge network and published ports, which needs appservice.listen_address: 0.0.0.0 and a homeserver.url the container can reach.

Host layout and networking

Same host (recommended). Synapse and the bridge run on one machine. The bridge listens on 127.0.0.1:9898 and the registration url is http://127.0.0.1:9898.

Separate hosts. Run the bridge on another machine (usually on the same private LAN): set appservice.listen_address to a LAN interface, appservice.url to the address Synapse should use, and homeserver.url to Synapse's LAN address. Securing the link between the two hosts (trusted LAN, VPN, firewall rules, TLS proxy) is up to you.

Tox UDP ports. Each profile gets one fixed UDP port from tox.udp.port_range (default 33445–33464, i.e. up to 20 profiles) when it is created, and keeps it across restarts. Forward that range from your router to the bridge host. When the range is full, new profiles run TCP-relay-only (with a notice); an admin can widen the range and then use NETWORK udp on in the profile room. No inbound TCP ports are needed.

Router: forward UDP 33445–33464 to the bridge host. Host firewall examples:

# nftables
nft add rule inet filter input udp dport 33445-33464 accept
# ufw
ufw allow 33445:33464/udp

With Docker, publish the range 1:1 (33445-33464:33445-33464/udp) so the port toxcore binds is the port that's forwarded, or use network_mode: host.

Using the bridge

Start a direct chat with @toxbridge:example.org (keep it unencrypted). This is your control room. Commands there are typed bare; every command accepts -h, and HELP lists them all.

Control room
PROFILES List your Tox identities
CREATE <name> Make a new Tox identity (and its profile room)
IMPORT <name> [passphrase] Upload a .tox file, then reply to it with this
EXPORT <name> [passphrase] Get the profile as a .tox file (encrypted with the passphrase if given)
OPEN <name> Re-invite yourself to a profile room
DELETE <name> [--yes] Destroy an identity
STATUS, SOURCE Version and uptime; where to get the source code
USERS, ALLOW [glob], DENY <glob>, ADMIN <mxid> on|off Admin only

Each identity has a profile room for its commands and notices (friend requests, connection status, group invites). Commands there can be typed bare too.

Profile room
CONNECT, DISCONNECT, RECONNECT, AUTOCONNECT on|off Bring the identity online/offline; start it with the bridge
INFO Status, name, Tox ID, UDP port
ID [qr] Show your Tox ID, optionally as a QR code
NAME, STATUSMSG, ONLINE/AWAY/BUSY Your Tox profile
AVATAR [clear] Reply to an image to make it your Tox avatar
NOSPAM [new|XXXXXXXX] Show or change your nospam (gives you a new Tox ID)
ADD <toxid> [message] Send a friend request
REQUESTS, ACCEPT <n>, REJECT <n> Incoming friend requests
FRIENDS, OPEN <friend>, REMOVE <friend> [--yes] Friends; <friend> is a number from FRIENDS, a name or a key prefix
GROUPS, GROUP create|join|invites|accept|decline|invite|leave|open ... Group chats
BOOTSTRAP [now|add|remove|refresh] Bootstrap nodes (changes are admin only)
NETWORK [udp on|off], PROXY [http|socks5 <host> <port> | off] Transport options (apply with RECONNECT)

A friend room is a direct chat with the friend's puppet (@tox_<public key>:example.org). Just talk. Room commands are prefixed with toxbridge: (or the bot's display name): toxbridge: INFO, toxbridge: QUEUE [clear] (messages waiting for delivery), toxbridge: REMOVE. Leaving the room unbridges it; a new room is opened when the friend writes again or you use OPEN.

A group room mirrors one Tox group. Members appear as puppets when they speak. Commands: toxbridge: INFO, TOPIC <text>, NICK <name>, INVITE <friend>, LEAVE. Leaving the room leaves the Tox group.

Notes:

  • A Tox group member's key is specific to the group, so a friend who is also in a group appears as a separate puppet there.
  • Tox can't delete or edit sent messages. Redacting a message that is still queued removes it from the queue; otherwise you get a notice.
  • Encrypted Matrix rooms are not supported. The bridge creates its rooms unencrypted and refuses encrypted control rooms.

Backups

Your Tox identity is its secret key: lose it and your friends must re-add a new Tox ID. Back up:

  1. toxbridge.key (the savedata encryption key), stored separately from
  2. the database (toxbridge.db and its -wal/-shm files for SQLite, or a pg_dump), and
  3. config.yaml and registration.yaml.

The database alone doesn't expose identities without the key file, and the key file alone holds no identities. Users can also keep their own copy with EXPORT <name> <passphrase>.

For a consistent SQLite backup while the bridge runs, use sqlite3 toxbridge.db ".backup backup.db".

Upgrading

git pull
docker build -t matrix-bridge-tox:latest .
docker compose up -d

Database migrations run automatically at start. Tox savedata is written on every change and periodically; stopping the bridge saves every identity first. c-toxcore and pytox are pinned in the Dockerfile (and contrib/build-pytox.sh) and are upgraded together, deliberately.

Installing without Docker

On Debian/Ubuntu:

sudo apt install build-essential cmake ninja-build git pkg-config libsodium-dev python3-dev python3-venv
sudo useradd --system --home /var/lib/matrix-bridge-tox --create-home toxbridge
sudo git clone https://git.glump.net/brendan-apps/matrix-bridge-tox.git /opt/matrix-bridge-tox/src
sudo python3 -m venv /opt/matrix-bridge-tox/venv
sudo /opt/matrix-bridge-tox/src/contrib/build-pytox.sh /opt/matrix-bridge-tox/venv /opt/toxcore
sudo /opt/matrix-bridge-tox/venv/bin/pip install /opt/matrix-bridge-tox/src

Then write /var/lib/matrix-bridge-tox/config.yaml, generate the registration (sudo -u toxbridge /opt/matrix-bridge-tox/venv/bin/python -m matrix_bridge_tox -c /var/lib/matrix-bridge-tox/config.yaml -g), set up Synapse as above, and install contrib/matrix-bridge-tox.service as a systemd unit.

PostgreSQL

Install with the postgres extra (pip install '.[postgres]'; the Docker dev target includes it) and set database: postgres://user:password@host/dbname.

Development

Everything runs in Docker. The design is in doc/PLAN.md.

dev/setup.sh                      # Synapse config, bridge config, registration, dev image
(cd dev && docker compose up -d)  # Synapse on localhost:8008 + the bridge with live source

Register a user (e.g. @admin:localhost, the dev owner) with any Matrix client against http://localhost:8008, or start Element with docker compose --profile element up -d and open http://localhost:8080. After code changes, docker compose restart bridge.

Tests:

# unit tests + Tox integration tests (two Tox instances over loopback)
docker run --rm -u "$(id -u)" -v "$PWD:/app" -w /app --entrypoint python matrix-bridge-tox:dev -m pytest -q -p no:cacheprovider
# end-to-end: a Matrix test user drives the bridge against a scripted Tox peer,
# then the bridge is restarted and checked again
dev/run-e2e.sh

spike/spike.py is the original pytox feasibility spike (milestone M0).

License

AGPL-3.0-or-later; see LICENSE and NOTICE. If you run a modified version of the bridge for others, you must offer them its source code: set bridge.source_url so the SOURCE command points at it.