summaryrefslogtreecommitdiffstats
path: root/bridge/slack/legacy.go
diff options
context:
space:
mode:
authorDuco van Amstel <duco.vanamstel@gmail.com>2018-11-13 19:51:19 +0000
committerWim <wim@42.be>2018-11-13 20:51:19 +0100
commite19ba5a06ad94c389df1b253d30c9ba6e4d14273 (patch)
tree7fdf1a9650d4bfd4e5e71638f92cb7f48c52ecc9 /bridge/slack/legacy.go
parentf7a5077d5d8dee61e86f5ec8b17b66bf257dd68c (diff)
downloadmatterbridge-msglm-e19ba5a06ad94c389df1b253d30c9ba6e4d14273.tar.gz
matterbridge-msglm-e19ba5a06ad94c389df1b253d30c9ba6e4d14273.tar.bz2
matterbridge-msglm-e19ba5a06ad94c389df1b253d30c9ba6e4d14273.zip
Add new Slack connection and forked legacy Slack bridge (#582)
Diffstat (limited to 'bridge/slack/legacy.go')
-rw-r--r--bridge/slack/legacy.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/bridge/slack/legacy.go b/bridge/slack/legacy.go
new file mode 100644
index 00000000..a7e7f01f
--- /dev/null
+++ b/bridge/slack/legacy.go
@@ -0,0 +1,74 @@
+package bslack
+
+import (
+ "errors"
+
+ "github.com/42wim/matterbridge/bridge"
+ "github.com/42wim/matterbridge/matterhook"
+ "github.com/nlopes/slack"
+)
+
+type BslackLegacy struct {
+ *Bslack
+}
+
+func NewLegacy(cfg *bridge.Config) bridge.Bridger {
+ return &BslackLegacy{Bslack: newBridge(cfg)}
+}
+
+func (b *BslackLegacy) Connect() error {
+ b.RLock()
+ defer b.RUnlock()
+ if b.GetString(incomingWebhookConfig) != "" {
+ switch {
+ case b.GetString(outgoingWebhookConfig) != "":
+ b.Log.Info("Connecting using webhookurl (sending) and webhookbindaddress (receiving)")
+ b.mh = matterhook.New(b.GetString(outgoingWebhookConfig), matterhook.Config{
+ InsecureSkipVerify: b.GetBool(skipTLSConfig),
+ BindAddress: b.GetString(incomingWebhookConfig),
+ })
+ case b.GetString(tokenConfig) != "":
+ b.Log.Info("Connecting using token (sending)")
+ b.sc = slack.New(b.GetString(tokenConfig))
+ b.rtm = b.sc.NewRTM()
+ go b.rtm.ManageConnection()
+ b.Log.Info("Connecting using webhookbindaddress (receiving)")
+ b.mh = matterhook.New(b.GetString(outgoingWebhookConfig), matterhook.Config{
+ InsecureSkipVerify: b.GetBool(skipTLSConfig),
+ BindAddress: b.GetString(incomingWebhookConfig),
+ })
+ default:
+ b.Log.Info("Connecting using webhookbindaddress (receiving)")
+ b.mh = matterhook.New(b.GetString(outgoingWebhookConfig), matterhook.Config{
+ InsecureSkipVerify: b.GetBool(skipTLSConfig),
+ BindAddress: b.GetString(incomingWebhookConfig),
+ })
+ }
+ go b.handleSlack()
+ return nil
+ }
+ if b.GetString(outgoingWebhookConfig) != "" {
+ b.Log.Info("Connecting using webhookurl (sending)")
+ b.mh = matterhook.New(b.GetString(outgoingWebhookConfig), matterhook.Config{
+ InsecureSkipVerify: b.GetBool(skipTLSConfig),
+ DisableServer: true,
+ })
+ if b.GetString(tokenConfig) != "" {
+ b.Log.Info("Connecting using token (receiving)")
+ b.sc = slack.New(b.GetString(tokenConfig))
+ b.rtm = b.sc.NewRTM()
+ go b.rtm.ManageConnection()
+ go b.handleSlack()
+ }
+ } else if b.GetString(tokenConfig) != "" {
+ b.Log.Info("Connecting using token (sending and receiving)")
+ b.sc = slack.New(b.GetString(tokenConfig))
+ b.rtm = b.sc.NewRTM()
+ go b.rtm.ManageConnection()
+ go b.handleSlack()
+ }
+ if b.GetString(incomingWebhookConfig) == "" && b.GetString(outgoingWebhookConfig) == "" && b.GetString(tokenConfig) == "" {
+ return errors.New("no connection method found. See that you have WebhookBindAddress, WebhookURL or Token configured")
+ }
+ return nil
+}