Facebook as an XMPP gateway

xmpp.pngCe billet est en anglais pour une audience plus large 🙂

Once upon a time, facebook messenger was XMPP compatible. That means that using it with XMPP clients as pidgin was easy and open. But time changes and facebook decided to close its XMPP gateway to its popular messenger service.

I like to have centralised chat service. At home I can use pidgin or adium but I had to connect all my accounts on each device. And I needed a good web service. That once was featured by meebo but after google acquired it the service was stopped. That’s when I decided to switch to a full self hosted service based on eJabberd for XMPP server and Jappix as a web fronted. I can still use any XMPP compatible client but I only have one account to connect!

Through my XMPP server I can, with gateways, access other services such as ICQ, AIM, Yahoo or other XMPP services. That’s what I use for gtalk and facebook… My main gateway server is Spectrum 2 (even if dev is stalled…) which itself use libpurple to connect to ICQ, AIM.

This long intro is here to expose how I built the system. After facebook shut down of its XMPP gateway I needed a way to connect to facebook again. And the solution was purple-facebook which is a third party plugin for libpurple to use native Facebook api to connect to chat service.

The preliminary step is to have ejabberd and spectrum2 running and communicating. I will not give a lot of details on how to configure those two and will assume you know at least a little of how to create a spectrum 2 transport and declare it within your xmpp server (note that this is totally ejabberd independ, you could use any gateway compatible xmpp server for this purpose)

First you have to get and compile purple-facebook. This one is easy: get the release tarball, apt-get libjson-glib-dev and follow the instructions:

$ tar xvf purple-facebook-*.tar.gz
$ cd purple-facebook-*
$ ./configure
$ make

If everything was fine you can sudo make install which should copy files into /usr/lib/purple-2 (libfacebook.so, libfacebook.la)

Second step is to create a spectrum2 transport in /etc/spectrum2/transports. You can use spectrum.cfg.example as a starting point. What I changed was the jid / port / password. The important part:

# Full path to backend binary.

# Libpurple protocol-id for spectrum_libpurple_backend

You can also set the type to facebook!

Do not forget to add this transport to your XMPP server configuration file and restart/reload it if needed.

Third step is to start spectrum2 gateway: spectrum2_manager jid.chat.server.com start. This should create a /var/lib/spectrum2/jid.chat.server.com directory.

Last and most important step before jumping to your client you need to setup SSL root certificates. If not you will get an empty json error. To do this, as root:

# You should adapt to your JID and root CA files location.
cd /var/lib/spectrum2/jid.chat.server.com
ln -s /etc/ssl/certs ca-certs
spectrum2_manager jid.chat.server.com restart

Now connected to Jappix or your prefered XMPP client, discover services and subscribe to your new jid.chat.server.com gateway!