Bridge facebook messenger with any service supported by matterbridge

fbridge

fbridge bridges facebook messenger with any service supported by matterbridge trough the API interface.

fbridge is using fbchat to connect to facebook.

Requirements:
$ pip install requests
$ pip install fbchat
$ pip install toml

Run the bridge:

$ python3 fbridge.py

fbridge will send any message received to “defaultgateway”. This needs to be in your matterbridge.toml file. You can then sort out the messages you want by added the threadID to config.toml

Matterbridge needs to be restarted any time you want to reconnect this client. There is some issue causing messages to be dropped if not.

I am a GO developer so there is improvements to be made to my python. Pull requests and improvement suggestions are welcome.

Comments
  • [noob issue] Bridge doesn't seem to work

    [noob issue] Bridge doesn't seem to work

    I don't exactly know how does it all work, but I still tried to configure it. After running python3 fbridge.py it gives me a number of errors.

    Login of mymail@mymail successful.
    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
        (self._dns_host, self.port), self.timeout, **extra_kw)
      File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 80, in create_connection
        raise err
      File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 70, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
        chunked=chunked)
      File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
        conn.request(method, url, **httplib_request_kw)
      File "/usr/lib/python3.7/http/client.py", line 1244, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/usr/lib/python3.7/http/client.py", line 1290, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/usr/lib/python3.7/http/client.py", line 1239, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/usr/lib/python3.7/http/client.py", line 1026, in _send_output
        self.send(msg)
      File "/usr/lib/python3.7/http/client.py", line 966, in send
        self.connect()
      File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in connect
        conn = self._new_conn()
      File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
        self, "Failed to establish a new connection: %s" % e)
    urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0xb5ad87f0>: Failed to establish a new connection: [Errno 111] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
        timeout=timeout
      File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
        _stacktrace=sys.exc_info()[2])
      File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
        raise MaxRetryError(_pool, url, error or ResponseError(cause))
    urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=4242): Max retries exceeded with url: /api/messages (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xb5ad87f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.7/threading.py", line 865, in run
        self._target(*self._args, **self._kwargs)
      File "fbridge.py", line 50, in listen
        r = requests.get('http://localhost:4242/api/messages')
      File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
        return request('get', url, params=params, **kwargs)
      File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
        return session.request(method=method, url=url, **kwargs)
      File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
        resp = self.send(prep, **send_kwargs)
      File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
        r = adapter.send(request, **kwargs)
      File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
        raise ConnectionError(e, request=request)
    requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=4242): Max retries exceeded with url: /api/messages (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xb5ad87f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
    
    Listening...
    

    Additionally when someone types something I get information for it in the terminal. Also output of matterbridge

    [0000]  INFO main:         [setupLogger:matterbridge.go:97] Enabling debug logging.
    [0000]  INFO main:         [main:matterbridge.go:46] Running version 1.17.5 8eb5e3cb
    [0000]  INFO router:       [Start:gateway/router.go:66] Parsing gateway fbbridge //maybe there's the issue?
    [0000]  INFO router:       [Start:gateway/router.go:75] Starting bridge: telegram.mytelegram 
    [0000]  INFO telegram:     [Connect:bridge/telegram/telegram.go:32] Connecting
    [0000]  INFO telegram:     [Connect:bridge/telegram/telegram.go:45] Connection succeeded
    [0000]  INFO telegram:     [joinChannels:bridge/bridge.go:77] telegram.mytelegram: joining 866432893 (ID: 866432893telegram.mytelegram)
    [0000]  INFO main:         [main:matterbridge.go:61] Gateway(s) started succesfully. Now relaying messages
    

    my matterbridge.toml

    [telegram.mytelegram]
    #See https://core.telegram.org/bots#6-botfather 
    #and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
    Token="this seems to be correct"
    RemoteNickFormat="<{NICK}>"
    
    [[gateway]]
    name="fbbridge"
    enable=true
    
    [[gateway.inout]]
    account="telegram.mytelegram"
    channel="this seems to be correct"
    

    Also I don't know if I should make an issue on matterbridge repo

  • 2FA connection fails

    2FA connection fails

    you can see my error :

    Paullux@dvkbuntu:~/fbridge$ python3 fbridge.py
    Logging in paulwoisard...
    Please enter your 2FA code --> 677061
    Submitting 2FA code.
    Attempt #1 failed, retrying
    Traceback (most recent call last):
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login
        self._state = State.login(
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Please enter your 2FA code --> 677061
    Submitting 2FA code.
    Saving browser.
    Starting Facebook checkup flow.
    Verifying login attempt.
    Saving device again.
    Attempt #2 failed, retrying
    Traceback (most recent call last):
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login
        self._state = State.login(
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 153, in login
        raise _exception.FBchatUserError(
    fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/login/checkpoint/)
    Please enter your 2FA code --> 016232
    Submitting 2FA code.
    Saving browser.
    Starting Facebook checkup flow.
    Verifying login attempt.
    Saving device again.
    Attempt #3 failed, retrying
    Traceback (most recent call last):
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login
        self._state = State.login(
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 153, in login
        raise _exception.FBchatUserError(
    fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/login/checkpoint/)
    Please enter your 2FA code --> 678383
    Submitting 2FA code.
    Attempt #4 failed, retrying
    Traceback (most recent call last):
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login
        self._state = State.login(
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Please enter your 2FA code --> 678383
    Submitting 2FA code.
    Saving browser.
    Starting Facebook checkup flow.
    Verifying login attempt.
    Saving device again.
    Traceback (most recent call last):
      File "fbridge.py", line 100, in <module>
        client = FBListener(username, password)
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 103, in __init__
        self.login(email, password, max_tries, user_agent=user_agent)
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login
        self._state = State.login(
      File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 153, in login
        raise _exception.FBchatUserError(
    fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/login/checkpoint/)
    
  • Work with docker matterbridge ?

    Work with docker matterbridge ?

    First of all thank you for this project,

    Have you try to integrate your project in the docker image of matterbridge ?

    If yes, do you any example of configuration ?

  • "IndexError: list index out of range" (can't connect to Facebook?)

    I feel like I'm so close, but maybe missing some detail somewhere. I'd be grateful if anybody could shed some light on what I'm doing wrong here!

    when I run python3 fbridge.py, here's what I get:

    Logging in [email protected]...
    Attempt #1 failed, retrying
    Traceback (most recent call last):
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 209, in login
        user_agent=user_agent,
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Attempt #2 failed, retrying
    Traceback (most recent call last):
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 209, in login
        user_agent=user_agent,
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Attempt #3 failed, retrying
    Traceback (most recent call last):
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 209, in login
        user_agent=user_agent,
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Attempt #4 failed, retrying
    Traceback (most recent call last):
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 209, in login
        user_agent=user_agent,
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    Traceback (most recent call last):
      File "fbridge.py", line 100, in <module>
        client = FBListener(username, password)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 103, in __init__
        self.login(email, password, max_tries, user_agent=user_agent)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_client.py", line 209, in login
        user_agent=user_agent,
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 151, in login
        return cls.from_session(session=session)
      File "/home/chris/.local/lib/python3.5/site-packages/fbchat/_state.py", line 190, in from_session
        revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
    IndexError: list index out of range
    

    my matterbridge.toml:

    [mattermost]
        [mattermost.work]
        UseTLS=true
        NoTLS=false
        Server="https://secret"
        Team="helloworld"
        Login="secretusername"
        Password="p355w0rd"
        PrefixMessagesWithNick=true
        RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
    
    [api.myapi]
    BindAddress="127.0.0.1:4242"
    Buffer=1000
    RemoteNickFormat="{NICK}"
    
    
    ## This is the default FB gateway. All facebook measseages will be sendt here
    [[gateway]]
    name="FBgateway"
    enable=true
    
    [[gateway.inout]]
    account="mattermost.work"
    channel="hello"
    
    [[gateway.inout]]
    account="api.myapi"
    channel="api"
    
  • Use RemoteNickFormat provided by matterbridge

    Use RemoteNickFormat provided by matterbridge

    Add jmsg["username"]+ before the message text jmsg["text"] being sent to Facebook messenger, in order to display the RemoteNickFormat (often set as username and origin service).

  • RemoteNickFormat is ignored

    RemoteNickFormat is ignored

    Hi! Thanks for this great tool, I got it working fairly easily. I will create a docker container for this when I have the time to make setting up easier.

    I have one problem however: RemoteNickFormat is ignored, meaning messages sent to Facebook will just contain the message, no info on who wrote the message. Here are the relevant parts of my matterbridge.toml:

    [api.myapi]
    BindAddress="127.0.0.1:4242"
    Buffer=1000
    RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
    
    ## This is the default FB gateway. All facebook measseages will be sent here
    [[gateway]]
    name="FBgateway"
    enable=true
    RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
    
  • display actual usernames

    display actual usernames

    Minor improvement to username output.

    I'd like to implement using one channel to handle threaded messages from all facebook users, once we have https://github.com/42wim/matterbridge/pull/627 and/or https://github.com/42wim/matterbridge/issues/638

Apex-api-bridge - Bridge between apexlegendsapi and ApeStats

apex-api-sync This app updates a mongo instance with the players most recent dat

Feb 17, 2022
Listmonk-messenger - Lightweight HTTP server to handle webhooks from listmonk and forward it to different messengers
Listmonk-messenger - Lightweight HTTP server to handle webhooks from listmonk and forward it to different messengers

listmonk-messenger Lightweight HTTP server to handle webhooks from listmonk and

Dec 28, 2022
Facebook's NTP libraries
Facebook's NTP libraries

NTP Collection of Facebook's NTP libraries. Protocol NTP protocol implementation Chrony and ntpd control protocol implementations Leaphash Utility pac

Dec 16, 2022
check if an {id, username, phonenumber, email} is associated with a facebook account
check if an {id, username, phonenumber, email} is associated with a facebook account

FacebookChecker FacebookChecker checks if an {id, username, phonenumber, email} is associated with a facebook account and get some information about t

Dec 2, 2022
This app brings the Matterbridge binary to your server to connect Nextcloud Talk with other chat services

This app brings the Matterbridge binary to your server to connect Nextcloud Talk with other chat services

Sep 12, 2022
Matterbridge mattermost plugin

mattermost-plugin Matterbridge mattermost plugin WIP Configuration You have to create a matterbridge.toml configuration file before running make. Beca

Dec 11, 2022
Matterbridge API Connector for Vintage Story Server

Matterbridge API Connector for Vintage Story Server

Oct 21, 2021
Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.
Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.

Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.

Dec 27, 2022
Matterbridge API plugin for Reddit Community Chat

Mattereddit 2 Mattereddit is a Matterbridge API plugin allowing you to connect Reddit group chats to the various chat services supported by Matterbrid

Sep 13, 2022
Connect a Minecraft Forge server to Matterbridge

Mattercraft Mattercraft is a Minecraft Forge mod that relays chat messages between a Minecraft server and Matterbridge. It uses Matterbridge's HTTP AP

Jul 28, 2022
Matterbridge link for Minecraft Server chat.

Matterbridge link for Minecraft Server chat. Simple bridge between Minecraft, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, Rocket.Chat, Hipchat(via xmpp), Matrix and Steam.

Mar 28, 2022
Connect Discourse threads to Matterbridge

Matterbabble Matterbabble is an API client for Discourse and Matterbridge. It mirrors Discourse posts in a topic to Matterbridge messages on a gateway

Dec 7, 2022
IPIP.net officially supported IP database ipdb format parsing library

IPIP.net officially supported IP database ipdb format parsing library

Dec 27, 2022
easyRpc - Sync && Async Call supported

easyRpc - Sync && Async Call supported

Feb 16, 2022
A Matrix-iMessage puppeting bridge

A Matrix-iMessage puppeting bridge. The bridge runs on a Mac or jailbroken iPhone (soon™). A websocket proxy is required to receive appservice events from the homeserver.

Jan 2, 2023
vks is a Vulkan bridge for Go.

vks vks is a Vulkan bridge for Go. The header generator folder contains the code that is used to generate the vulkan bindings. It woks similar to c-fo

Sep 3, 2022
Bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API
Bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)

Jan 4, 2023
An inline buildpack for deploying a mattermost-irc bridge

Matterbridge-Heroku An inline buildpack for hosting Matterbridge on Heroku. Heroku is a platform for easily deploying applications. A buildpack provid

Nov 26, 2022
Grpc bridge to various mediabank related systems

Mediabank bridge This internal tool enables authenticated gRPC based endpoint for securely communicating with systems like: Telestream Vantage Workflo

Jan 7, 2022