Skip to content

Instantly share code, notes, and snippets.

@kousu
Created January 12, 2023 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kousu/74ce52f6ecbfde12b050bf249e5a99a2 to your computer and use it in GitHub Desktop.
Save kousu/74ce52f6ecbfde12b050bf249e5a99a2 to your computer and use it in GitHub Desktop.
Bridging Discord + XMPP

Just because the docs on https://github.com/42wim/matterbridge/wiki/ are a little bit obscure in some parts, here's a complete record of what I did:

  1. sudo pacman -S matterbridge
  2. Set up a generic systemd service file:
$ cat /etc/systemd/system/matterbridge\@.service 
[Unit]
Description=%I Chat Bridge
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/matterbridge -conf /etc/matterbridge/%I.toml
Restart=always
RestartSec=5s
User=matterbridge

[Install]
WantedBy=multi-user.target
  1. Went to prosody, ran sudo prosodyctl adduser matterbridge@example.com; generate the password with a password generator

  2. Went to https://discord.com/developers/applications, followed https://github.com/42wim/matterbridge/wiki/Discord-bot-setup; ran into bugs, documented them at 42wim/matterbridge#1944

    Eventually ended up with the bot joined and. MAKE SURE NOT TO SET ANY PERMISSIONS, the only permission you need is the "Create Webhook" permission, which is embedded in the URL that wiki page tells you to use to trigger the OAuth Authorize step

  3. Wrote this matterbridge config:

$ cat /etc/matterbridge/lab.toml 
[xmpp]
[xmpp.bridge]
Server="chat.example.com:5222"
Jid="matterbridge@example.com"
Password="xxxxxxxxxxxxxxx"
Muc="conference.example.com"
Nick="Discord"
RemoteNickFormat="<{NICK}> "

[discord]
[discord.bridge]
Token="xxxxxxxxxxxxxxxxxxxxxxx"
Server="7xxxxxxxxxxxxxxxxx" # get this from your discord url; if you're in https://discord.com/channels/7xxxxxxxxxxxxxxxxx/9xxxxxxxxxxxxxxxxx, take the first part
AutoWebhooks=true
RemoteNickFormat="{NICK}"

# ----------------------

[[gateway]]
name="general"
enable=true

[[gateway.inout]]
account="discord.bridge"
channel="ID:9xxxxxxxxxxxxxxxxx" # ditto, if in https://discord.com/channels/7xxxxxxxxxxxxxxxxx/9xxxxxxxxxxxxxxxxx, take the last part

[[gateway.inout]]
account="xmpp.bridge"
channel="general%lab" # -> this becomes general%lab@conference.example.com

[[gateway]]
name="cowork"
enable=true

[[gateway.inout]]
account="discord.bridge"
channel="ID:9xxxxxxxxxxxxxxxx"

[[gateway.inout]]
account="xmpp.bridge"
channel="cowork%lab" # ditto
  1. sudo systemctl enable --now matterbridge@lab

Bridges for other communities can be added by creating other bots/bot users and writing their credentials into other config files under /etc/matterbridge, They could all be run in a single matterbridge conf file, but that's more fragile. This way different communities can tick along mostly independently, so long as the underlying server is up.

  1. Watch logs with journalctl -f -u matterbridge@lab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment