Page MenuHomePhabricator

Investigate bridging Matrix to Discord
Open, Needs TriagePublic

Description

It would be good to evaluate the reliability of sharing the same channel across Matrix (a good candidate for a movement-wide real-time chat tool) and Discord (a real-time chat tool that's popular in the younger generation). This came up in the context of bridging Hungarian Wikipedia's Matrix and Discord rooms but there are several potential other applications.

The bridge that looks the most mature is matrix-appservice-discord; see its project page for a short list of features and its github page for a marginally longer one.
(There's also mx-puppet-discord but that's a puppeting-based bridge so it's not really useful; see Using people's established Discord identities below. And matterbridge which supports many different chat systems, but conversely I'd expect it to be less capable.)


Things that work well

  • Setup. Invite the bot (t2bot.io or self-hosted) on both sides, command !discord bridge <serverid> <channelid> in Matrix, command !matrix approve in Discord within 5 minutes (needs admin accounts).
  • Syncing message content between the two channels. Initially a little slow but seemed to improve over time. Hyperlinks, most formatting, images work fine. Message deletion also works; message editing in Matrix is transferred to Discord well.
  • Faking identities. Both sides allow the bot to use an arbitratry nick and avatar, so it copies those from the message it's syncing. On the Matrix side it will create an account for each Discord user; on the Discord side it seems to reuse the same account and constantly change nicks and avatars (which Discord doesn't retroactively apply to the messages - this seems somwthat fragile, but works well at the moment).
  • Replies in Discord turn into proper replies in Matrix.
  • @-mentions (of Matrix or Discord users) posted in Matrix look as expected in Discord. @-mentions of Discord users posted in Discord also result in proper mentions in Matrix.
  • References to another Matrix channel in Matrix show up as matrix.to links in Discord, which I suppose is the most that can be done in that situation.
  • Stickers posted in Matrix are displayed properly as images in Discord.

Things that don't work well

  • Quote formatting in Matrix (>) for some reason results in plaintext no-linebreak text in Discord. (#659)
  • Reacjis don't travel either way. (#759)
  • Using people's established Matrix identities (ie. being able to prove to the bot that you own a given Discord account and a given Matrix account, and then it would post using your Matrix account instead of the bot's own) - I think this is possible in theory but not supported. This also means direct messages don't work.
  • Replies in Matrix are shown in Discord as quoting the text of the parent message - but there's no link to that message. (#693)
  • Message editing in Matrix is synced in a weird way: it if's the last message in the channel, it will be updated but there will be no (edited) notice. If it's no the last message, the bridge bot just reposts the edited version of the message with a link to the original, which changes a barely noticeable Matrix action into a highly disruptive one on the Discord side. Not sure if that's a bot API limitation or just a missing feature.
  • Presence sync from Discord to Matrix only includes users once they have posted something. Discord only has server-level presence, so maybe in some cases this is a useful limitation; but in others it isn't. (#761)
  • Gifs posted in Discord are displayed in Matrix as links to the gif sharing sites they are sourced from. Link preview is not necessarily useful either. (#762)
  • Discord threads are entirely hidden in Matrix. (#722)
  • Matrix threads are shown as main channel messages in Discord, with no indication of being in response to something. (FWIW, Matrix threads are still in beta and display similarly poorly in most Matrix clients as well.)
  • References to another Discord channel in Discord show up as broken Matrix links in Matrix. (#763)

Things that will probably never work

  • Using people's established Discord identities: Discord does not provide an API for this. The bot can use your Discord credentials to login as you (docs) but that's a non-starter, both from a security POV, and because it's forbidden by Discord's ToS and they do ban people for it.
  • Matrix users cannot be @-mentioned in Discord AFAICT. The bot seems to use a single Discord account and change its nick before posting (and then revert it), there are no separate accounts for Matrix users that could be pinged. (#760)
  • For the same reason, presence is not synced from Matrix to Discord.

Things that weren't tested

  • Moderation
  • Other admin level stuff (pinning etc.)
  • matterbridge, which seems like a viable alternative.

tl;dr

There are several deal-breakers IMO: direct messages don't work, @-mentions of Matrix users in Discord don't work. Depending on channel culture, reacjis might be a big problem too. Also threads once they are out of beta in Matrix. Bridging seems too disruptive to be worth it.

Reacjis are probably easy to fix; @-mentions might be fixable although not cleanly as Discord does not let the bot create new identities per nick. DMs are not fixable unless Discord starts supporting proper account puppeting. The thread implementations are quite different (plus Discord is auto-archiving threads after a time limit as a monetization attempt) so that's also unlikely to get fixed, I think.

Also the repo seems not actively maintained (cf. #443 and #716).

Event Timeline

@Inductiveload is running a bridge bot between #wikisource:matrix.org and the Wikisource Discord and might have some useful input

It's a simple Matterbridge bridge, with most of the Kubernetes deployment stolen from wm-bb, nothing fancy other than multiplexing a bunch of Discord rooms all into the general Matrix Wikisource channel (offtopic is also bridged, but to Wikisource-offtopic).

So far there have been no issues, except that one time the Toolforge NFS shares went down and it needed a manual prod.

Other than the channel mappings and a couple of bot ignores, the only real config change is:

MediaDownloadSize=10000000

Things that are a bit painful but I haven't bothered to look into:

  • URLs with _'s cause italics unless you wrap in < > (actually: probably a client thing with Element)
  • No @-ing (if you @ in Matrix, it doesn't ping in Discord) (actually: it does)
  • No reactions (they don't even show in the debug log)
  • Stickers/emojis (:likethis:) don't work, they just come across as the literal text :likethis: (obviously there are no stickers in the reverse direction as it's not our "own" homeserver to which we can add things like that)

Generally, it's better than having the Discord users (who are almost entirely a disjoint set from the Matrix/IRCers) completely cut off from Matrix, and if there was no bridge, I do not think many Discord users will be willing to make the effort to get onto Matrix/IRC. Since Discord is often livelier than Matrix, it would be a big shame to disconnect the two groups of users.

AFAICS Discord does not allow message editing, unless it is the last message of the channel (in which case it's changed with no indication of editing whatsoever). Instead the bridge bot (or Discord?) just reposts the edited version of the message with a link to the original, which is probably the least bad way of representing it; but that changes a barely noticeable Matrix action into a highly disruptive one on the Discord side.

Discord does allow message editing, so is this imprecise wording related to the bot framework you used to test or an incorrect understanding of Discord? Kind of looks like the former.

Discord does allow message editing, so is this imprecise wording related to the bot framework you used to test or an incorrect understanding of Discord? Kind of looks like the former.

That was me jumping to the wrong conclusion. I can indeed edit old messages in Discord, and the bridge syncs that perfectly. I can also edit my last message in Matrix, and the bot also syncs that (although the small (edited) notice does not get shown), If I edit an older message in Matrix, it results in a new message saying Edit: <new text>, with the word "Edit" linking to the original message. Not sure if it's a limitation of the bridge or of Discord's bot API.

It's a simple Matterbridge bridge, with most of the Kubernetes deployment stolen from wm-bb, nothing fancy other than multiplexing a bunch of Discord rooms all into the general Matrix Wikisource channel (offtopic is also bridged, but to Wikisource-offtopic).

Interesting, thanks! Does that mean you need to bridge both channels to a Mattermost channel, or can Matterbridge bridge directly between two non-Mattermost ones?

Does that mean you need to bridge both channels to a Mattermost channel, or can Matterbridge bridge directly between two non-Mattermost ones?

https://github.com/42wim/matterbridge says Note: Mattermost isn't required to run matterbridge.

Also I don't know what happens with threads, but AFAICT no one uses them in the Wikisource Discord or Matrix channels anyway.

WRT editing: with the matterbridge bridge (which as you found does not use any mattermost channel), if you edit in Matrix, you do get a "proper" edit in Discord (the message changes and the little (edited) appears). And in the other direction it's the same. So it sounds like the API exists and works, it's just a bridge implementation thing.

At @-ing does actually seem to work Matrix->Discord, and it seems to translate between the discord account and server nick, so I was wrong about that. And from Discord->Matrix, it pings when the message includes your username in general.

matrix-appservice-discord is apparently an official matrix.org project now, so maybe it will improve.