42wim / matterbridge

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!)
Apache License 2.0
6.56k stars 617 forks source link

Does chat support have to built into the matterbridge binary? #880

Closed jakubgs closed 5 years ago

jakubgs commented 5 years ago

If I wanted to develop bridging functionality for https://status.im/, would that have to be built into MatterBridge itself, or could it have a form of a library loaded on runtime?

I couldn't find any clear instructions on how to extend MatterBridge with your own chat support, but from what I've gathered the only way is to fork MatterBridge and add that functionality to its codebase. Is that right?

Helcaraxan commented 5 years ago

Hello @jakubgs.

There are two ways in which Matterbridge can support a new protocol:

qaisjp commented 5 years ago

or could it have a form of a library loaded on runtime

This could be achieved using plugins: https://golang.org/pkg/plugin/

jakubgs commented 5 years ago

Thanks for the explanation, appreciate it.

I think I'd rather implement what you call "native support", but the Status protocol isn't stable enough yet to be included in your master. I think for now it would make more sense for us to try to implement support in a fork, and once the Protocol is stable enough we can try contributing a PR to master.

jakubgs commented 5 years ago

So, my understanding is that an implementation of a chat has to implement the Bridge interface: https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/bridge.go#L11-L16 One thing I'm was wondering about is how the plugin gets the configuration, but it appears the Bridge interface methods provide that already: https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/discord/discord.go#L54 https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/bridge.go#L98-L104 Other than that, is there anything else I should know?

jakubgs commented 5 years ago

One thing that makes me wonder is how MatterBridge gets messages from the channel.

I can see that Gitter bridge implements some kind of Go routine in JoinChannel that sends messages into a channel: https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/gitter/gitter.go#L69 But for example in Telegram module JoinChannel is empty: https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/telegram/telegram.go#L54-L56 So I'm not sure how this part works, maybe you can explain this to me?

42wim commented 5 years ago

https://github.com/42wim/matterbridge/wiki/Gateway:-developing-new-one is also a helpful page

@jakubgs regarding JoinChannel some protocols need to bot to be joined by the admin so they don't need or can't join the channel themselves.

Maybe the xmpp one is a bit simpeler: https://github.com/42wim/matterbridge/blob/942d8f1cedfb7325c0720f8967751bb1b77f5b82/bridge/xmpp/xmpp.go

Wrt how you get messages, most of the bridges run a for loop in a go routine on a successfull Connect() which receive the messages from the server and send them into matterbridge using the Remote message channel.

jakubgs commented 5 years ago

Perfect, thank you for the explanation. I will close it for now, and will eventually get back to you with a possible PR, but that might be a while before we consider our protocol libraries stable.

Cheers!