Matrix: One Chat Protocol to Rule Them All
Once upon a time, there were many chat services. AOL Instant Messenger, Yahoo Messenger, ICQ and others. These messengers had their own desktop clients, and developers reverse engineered their protocol to build custom applications, both open and closed source. Trillian, Audium and Pidgin were applications that let people communicate across all these messengers with one program. Over time the old protocols died, and newer chat services like Facebook Messenger and Google Hangouts started storing your entire history on their servers. People started using the web interfaces and mobile apps, no longer caring about desktop programs.
Matrix is an open source communication protocol. It’s similar to XMPP (formerly Jabber) in the sense that anyone can set up a Matrix server and communicate to people on other Matrix servers. It’s a federated protocol, just like e-mail. Google Hangouts used to support XMPP federation, but silently removed support in 2014. Matrix supports bridging other chat services, so they can appear in a unified view. With my current setup of Matrix and appropriate bridges, I’ve combined my view of Facebook Messenger, Google Hangouts, Telegram and native Matrix chats into one convenient user interface. The path to get to that integration was not as simple.
The dedicated server I use for this website and other self-hosted web applications, is located in Germany. Logging in to Facebook or Google’s chat system from a country I’m not currently in, can raise all sorts of security flags and lock me out of my account. For those bridges, I purchased a small virtual machine in a Chicago data center. I installed a proxy on that server, accessible only via VPN, to view both Google and Facebook, so they record the IP address I’m connecting from with my web browser. This helps minimize security lockouts. Telegram isn’t hostile to third party developers, and has an official API. It doesn’t care my bridge is connecting to it from Germany, so I host it on the dedicated server.
The reference Matrix server is called Synapse. It, as well as the mautrix-telegram, mautrix-hangouts and mautrix-facebook bridges all have official Docker containers built by their developers. Each bridge must be able to communicate with the Synapse homeserver. Their instructions go through generating configuration and key pairs that are copied over to Synapse in order to form their authentication bridge. The bridges provide chat robots that guide you through getting OAuth tokens or cookies for those respective services.
The wiki for each bridge also has instructions for enabling double-puppeting, making each chat look seamless between myself and the accounts on the other side of each respective bridge. Without double-puppeting, each conversation will be in a three person group with the Matrix user, the bridge user (e.g my Google Hangouts user) and the person I’m talking to.
Enabling double-puppeting via the curl
command in the bridge documentation and calling login-matrix
on the bot, removes the creation of three person rooms. The bridged accounts will now show up as regular, two-person conversations.
I use the Element desktop app to connect to my matrix server, but I also have a web version of Element running from its own official Docker container in case I need to access chat from another computer. There are other clients, such as Mirage which is built using Qt and Fluffychat for mobile. Although I use Synapse for my homeserver, there are other servers that support the Matrix protocol that are in use and under active development.
Setting up all the Matrix components wasn’t too difficult, but it does require knowledge or experience with running services. It took a considerable amount of work and debugging to get each bridge operational, compounded slightly by my complex networking setup. Most people would probably just run all of this on a Raspberry Pi at home. I feel that using Matrix with bridges is still somewhat inaccessible to people who aren’t interested in development or server administration. Still, the satisfaction of having unified chat, plus one more layer of abstraction between myself and Google or Facebook, feels like it was wroth the overall effort.