summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-12-03 00:10:29 +0100
committerWim <wim@42.be>2016-12-03 00:10:29 +0100
commitfee159541f60bad245794cda69649fab569c2024 (patch)
treec5f65f068656b317bd786ba6059e21f58b569698 /bridge
parentd81e6bf6ce7f30f1b87c39c49272469f85dc2bd2 (diff)
downloadmatterbridge-msglm-fee159541f60bad245794cda69649fab569c2024.tar.gz
matterbridge-msglm-fee159541f60bad245794cda69649fab569c2024.tar.bz2
matterbridge-msglm-fee159541f60bad245794cda69649fab569c2024.zip
Add initial Rocket.Chat support
Diffstat (limited to 'bridge')
-rw-r--r--bridge/bridge.go4
-rw-r--r--bridge/config/config.go1
-rw-r--r--bridge/rocketchat/rocketchat.go82
3 files changed, 87 insertions, 0 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go
index 8c715369..b387812a 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -6,6 +6,7 @@ import (
"github.com/42wim/matterbridge/bridge/gitter"
"github.com/42wim/matterbridge/bridge/irc"
"github.com/42wim/matterbridge/bridge/mattermost"
+ "github.com/42wim/matterbridge/bridge/rocketchat"
"github.com/42wim/matterbridge/bridge/slack"
"github.com/42wim/matterbridge/bridge/telegram"
"github.com/42wim/matterbridge/bridge/xmpp"
@@ -59,6 +60,9 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
case "telegram":
b.Config = cfg.Telegram[name]
b.Bridger = btelegram.New(cfg.Telegram[name], bridge.Account, c)
+ case "rocketchat":
+ b.Config = cfg.Rocketchat[name]
+ b.Bridger = brocketchat.New(cfg.Rocketchat[name], bridge.Account, c)
}
return b
}
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 4b0a7ead..971013d7 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -80,6 +80,7 @@ type Config struct {
Xmpp map[string]Protocol
Discord map[string]Protocol
Telegram map[string]Protocol
+ Rocketchat map[string]Protocol
General Protocol
Gateway []Gateway
SameChannelGateway []SameChannelGateway
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
new file mode 100644
index 00000000..d87450ec
--- /dev/null
+++ b/bridge/rocketchat/rocketchat.go
@@ -0,0 +1,82 @@
+package brocketchat
+
+import (
+ "github.com/42wim/matterbridge/bridge/config"
+ "github.com/42wim/matterbridge/hook/rockethook"
+ "github.com/42wim/matterbridge/matterhook"
+ log "github.com/Sirupsen/logrus"
+)
+
+type MMhook struct {
+ mh *matterhook.Client
+ rh *rockethook.Client
+}
+
+type Brocketchat struct {
+ MMhook
+ Config *config.Protocol
+ Remote chan config.Message
+ name string
+ Account string
+}
+
+var flog *log.Entry
+var protocol = "rocketchat"
+
+func init() {
+ flog = log.WithFields(log.Fields{"module": protocol})
+}
+
+func New(cfg config.Protocol, account string, c chan config.Message) *Brocketchat {
+ b := &Brocketchat{}
+ b.Config = &cfg
+ b.Remote = c
+ b.Account = account
+ return b
+}
+
+func (b *Brocketchat) Command(cmd string) string {
+ return ""
+}
+
+func (b *Brocketchat) Connect() error {
+ flog.Info("Connecting webhooks")
+ b.mh = matterhook.New(b.Config.URL,
+ matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
+ DisableServer: true})
+ b.rh = rockethook.New(b.Config.URL, rockethook.Config{BindAddress: b.Config.BindAddress})
+ go b.handleRocketHook()
+ return nil
+}
+
+func (b *Brocketchat) JoinChannel(channel string) error {
+ return nil
+}
+
+func (b *Brocketchat) Send(msg config.Message) error {
+ flog.Debugf("Receiving %#v", msg)
+ matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
+ matterMessage.Channel = msg.Channel
+ matterMessage.UserName = msg.Username
+ matterMessage.Type = ""
+ matterMessage.Text = msg.Text
+ err := b.mh.Send(matterMessage)
+ if err != nil {
+ flog.Info(err)
+ return err
+ }
+ return nil
+}
+
+func (b *Brocketchat) handleRocketHook() {
+ for {
+ message := b.rh.Receive()
+ flog.Debugf("Receiving from rockethook %#v", message)
+ // do not loop
+ if message.UserName == b.Config.Nick {
+ continue
+ }
+ flog.Debugf("Sending message from %s on %s to gateway", message.UserName, b.Account)
+ b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account}
+ }
+}