This is a puppetted Matrix bridge for Facebook.
git clone https://github.com/matrix-hacks/matrix-puppet-facebook
cd matrix-puppet-facebook
npm install
Create and update config.json to match your setup:
cp config.sample.json ./config.json
nano ./config.json
node login.js
This prompts you for your Facebook username/password, logs in, and creates an appstate.json containing your login token. It will also prompt you about login approvals (i.e. 2FA) if you have them enabled on your Facebook account. Note this script may output some errors, but as long as appstate.json is written and works properly once you run the bridge, you can ignore them.
This will generate a facebook-registration.yaml
file:
node index.js -r -u "http://your-bridge-server:8090"
Note: The 'registration' setting in the config.json needs to set to the path of this file. By default, it already is.
Make sure that from the perspective of the homeserver, the url is correctly pointing to your bridge server. e.g. url: 'http://your-bridge-server.example.org:8090'
and is reachable. If you use reverse proxy, you can use "http://localhost:8090".
Copy this facebook-registration.yaml
file to your home server:
cp facebook-registration.yaml /etc/matrix-synapse/
Edit your homeserver.yaml file and update the app_service_config_files
with the path to the facebook-registration.yaml
file:
nano /etc/matrix-synapse/homeserver.yaml
It should look like this:
app_service_config_files: ["/etc/matrix-synapse/facebook-registration.yaml"]
If you plan to run this program as a service, you can continue at the next section.
Launch the bridge with ./start.sh
(see * below for more details on this). This is a bash script, so it only works on linux / osx. If you're on windows, you'll need to take a look at the script and make an equivalent batch file. It should be very simple.
Restart your Homeserver.
If you use systemd you can run the bridge as a service, so it will start automatically on system boot.
First edit the paths in the unit file:
nano matrix-puppet-facebook.service
Make sure the matrix-synapse user has write permissions to this directory.
After editing enable the service:
cp ./matrix-puppet-facebook.service /etc/systemd/system
systemctl daemon-reload
systemctl enable matrix-puppet-facebook.service
systemctl start matrix-puppet-facebook.service
Restart your homeserver:
systemctl restart matrix-synapse.service
You can also use the bridge with docker. Proceed with steps normally but instead of running script or service, compile the docker image:
docker build -t matrix-puppet-facebook .
Of course you need working docker on your system.
After that you can run the container:
docker run -d --restart=always -p 8090:8090 matrix-puppet-facebook
-d is --detach (runs in background), --restart is needed for restarting bridge container when it quits (it does that every few hours), -p binds port 8090 in container to 8090 on host
You can verify that containers works by running:
docker ps
* Just to explain the reason for start.sh
, facebook-chat-api contains a bug - https://github.com/Schmavery/facebook-chat-api/issues/555 that necessitates reconnecting to facebook periodically, otherwise message sending will start to fail after a couple of days. start.sh
ensures that the process restarts properly any time it dies.
Unable to load crypto module: crypto will be disabled: Error: global.Olm is not defined
is not needed. matrix-js-sdk
internally, it will always warn if OLM is present or not, and unfortunately we can't tell it to not burp out that warning.