summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-06-24 19:36:10 +0200
committerWim <wim@42.be>2017-06-29 23:38:48 +0200
commit830361e48bab699d7a22af1eba3f3df85ac21bd3 (patch)
treea5b3c02f33efb5ed5c629f923e104ad287bc5842
parent1b1a9ce2503021c275a470c8da21d33bbdcf5681 (diff)
downloadmatterbridge-msglm-0.16.0-rc1.tar.gz
matterbridge-msglm-0.16.0-rc1.tar.bz2
matterbridge-msglm-0.16.0-rc1.zip
Deprecate URL,useAPI,BindAddress (slack,mattermost,rocketchat)v0.16.0-rc1
-rw-r--r--bridge/config/config.go44
-rw-r--r--bridge/discord/discord.go7
-rw-r--r--bridge/mattermost/mattermost.go27
-rw-r--r--bridge/rocketchat/rocketchat.go4
-rw-r--r--bridge/slack/slack.go28
-rw-r--r--matterbridge.toml.sample89
6 files changed, 122 insertions, 77 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 6244dd6a..fc41fe02 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -40,7 +40,7 @@ type ChannelInfo struct {
type Protocol struct {
AuthCode string // steam
- BindAddress string // mattermost, slack
+ BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api
EditSuffix string // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter
@@ -72,12 +72,14 @@ type Protocol struct {
SkipTLSVerify bool // IRC, mattermost
Team string // mattermost
Token string // gitter, slack, discord, api
- URL string // mattermost, slack, matrix
+ URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
UseSASL bool // IRC
UseTLS bool // IRC
UseFirstName bool // telegram
- WebhookURL string // discord
+ WebhookBindAddress string // mattermost, slack
+ WebhookURL string // mattermost, slack
+ WebhookUse string // mattermost, slack, discord
}
type ChannelOptions struct {
@@ -128,6 +130,28 @@ func NewConfig(cfgfile string) *Config {
if _, err := toml.DecodeFile(cfgfile, &cfg); err != nil {
log.Fatal(err)
}
+ fail := false
+ for k, v := range cfg.Mattermost {
+ res := Deprecated(v, "mattermost."+k)
+ if res {
+ fail = res
+ }
+ }
+ for k, v := range cfg.Slack {
+ res := Deprecated(v, "slack."+k)
+ if res {
+ fail = res
+ }
+ }
+ for k, v := range cfg.Rocketchat {
+ res := Deprecated(v, "rocketchat."+k)
+ if res {
+ fail = res
+ }
+ }
+ if fail {
+ log.Fatalf("Fix your config. Please see changelog for more information")
+ }
return &cfg
}
@@ -178,3 +202,17 @@ func GetIconURL(msg *Message, cfg *Protocol) string {
iconURL = strings.Replace(iconURL, "{PROTOCOL}", protocol, -1)
return iconURL
}
+
+func Deprecated(cfg Protocol, account string) bool {
+ if cfg.BindAddress != "" {
+ log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
+ } else if cfg.URL != "" {
+ log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
+ } else if cfg.UseAPI == true {
+ log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
+ } else {
+ return false
+ }
+ return true
+ //log.Fatalf("ERROR: Fix your config: %s", account)
+}
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 1acbb19b..e3ea9f9b 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -49,6 +49,11 @@ func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
func (b *bdiscord) Connect() error {
var err error
flog.Info("Connecting")
+ if b.Config.WebhookURL == "" {
+ flog.Info("Connecting using token")
+ } else {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ }
if !strings.HasPrefix(b.Config.Token, "Bot ") {
b.Config.Token = "Bot " + b.Config.Token
}
@@ -110,7 +115,7 @@ func (b *bdiscord) Send(msg config.Message) error {
return nil
}
if b.Config.WebhookURL == "" {
- flog.Debugf("Broadcasting using API")
+ flog.Debugf("Broadcasting using token (API)")
b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
} else {
flog.Debugf("Broadcasting using Webhook")
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index e88bf838..222522ee 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -55,12 +55,18 @@ func (b *Bmattermost) Command(cmd string) string {
}
func (b *Bmattermost) Connect() error {
- if !b.Config.UseAPI {
- flog.Info("Connecting webhooks")
- b.mh = matterhook.New(b.Config.URL,
+ if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
+ flog.Info("Connecting using webhookurl and webhookbindaddress")
+ b.mh = matterhook.New(b.Config.WebhookURL,
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
- BindAddress: b.Config.BindAddress})
+ BindAddress: b.Config.WebhookBindAddress})
+ } else if b.Config.WebhookURL != "" {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
+ DisableServer: true})
} else {
+ flog.Info("Connecting using token")
b.mc = matterclient.New(b.Config.Login, b.Config.Password,
b.Config.Team, b.Config.Server)
b.mc.SkipTLSVerify = b.Config.SkipTLSVerify
@@ -85,7 +91,7 @@ func (b *Bmattermost) Disconnect() error {
func (b *Bmattermost) JoinChannel(channel string) error {
// we can only join channels using the API
- if b.Config.UseAPI {
+ if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" {
return b.mc.JoinChannel(b.mc.GetChannelId(channel, ""))
}
return nil
@@ -100,7 +106,7 @@ func (b *Bmattermost) Send(msg config.Message) error {
if b.Config.PrefixMessagesWithNick {
message = nick + message
}
- if !b.Config.UseAPI {
+ if b.Config.WebhookURL != "" {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
matterMessage.IconURL = msg.Avatar
matterMessage.Channel = channel
@@ -119,12 +125,13 @@ func (b *Bmattermost) Send(msg config.Message) error {
}
func (b *Bmattermost) handleMatter() {
- flog.Debugf("Choosing API based Mattermost connection: %t", b.Config.UseAPI)
mchan := make(chan *MMMessage)
- if b.Config.UseAPI {
- go b.handleMatterClient(mchan)
- } else {
+ if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
+ flog.Debugf("Choosing webhooks based receiving")
go b.handleMatterHook(mchan)
+ } else {
+ flog.Debugf("Choosing login (api) based receiving")
+ go b.handleMatterClient(mchan)
}
for message := range mchan {
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
index 15cac553..8eb788f9 100644
--- a/bridge/rocketchat/rocketchat.go
+++ b/bridge/rocketchat/rocketchat.go
@@ -41,10 +41,10 @@ func (b *Brocketchat) Command(cmd string) string {
func (b *Brocketchat) Connect() error {
flog.Info("Connecting webhooks")
- b.mh = matterhook.New(b.Config.URL,
+ b.mh = matterhook.New(b.Config.WebhookURL,
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
DisableServer: true})
- b.rh = rockethook.New(b.Config.URL, rockethook.Config{BindAddress: b.Config.BindAddress})
+ b.rh = rockethook.New(b.Config.WebhookURL, rockethook.Config{BindAddress: b.Config.WebhookBindAddress})
go b.handleRocketHook()
return nil
}
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index ad6a2b60..94f74d73 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -52,11 +52,16 @@ func (b *Bslack) Command(cmd string) string {
}
func (b *Bslack) Connect() error {
- flog.Info("Connecting")
- if !b.Config.UseAPI {
- b.mh = matterhook.New(b.Config.URL,
- matterhook.Config{BindAddress: b.Config.BindAddress})
+ if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
+ flog.Info("Connecting using webhookurl and webhookbindaddress")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{BindAddress: b.Config.WebhookBindAddress})
+ } else if b.Config.WebhookURL != "" {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{DisableServer: true})
} else {
+ flog.Info("Connecting using token")
b.sc = slack.New(b.Config.Token)
b.rtm = b.sc.NewRTM()
go b.rtm.ManageConnection()
@@ -73,7 +78,7 @@ func (b *Bslack) Disconnect() error {
func (b *Bslack) JoinChannel(channel string) error {
// we can only join channels using the API
- if b.Config.UseAPI {
+ if b.Config.WebhookURL == "" || b.Config.WebhookBindAddress == "" {
if strings.HasPrefix(b.Config.Token, "xoxb") {
// TODO check if bot has already joined channel
return nil
@@ -96,7 +101,7 @@ func (b *Bslack) Send(msg config.Message) error {
if b.Config.PrefixMessagesWithNick {
message = nick + " " + message
}
- if !b.Config.UseAPI {
+ if b.Config.WebhookURL != "" {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
matterMessage.Channel = channel
matterMessage.UserName = nick
@@ -169,18 +174,19 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
}
func (b *Bslack) handleSlack() {
- flog.Debugf("Choosing API based slack connection: %t", b.Config.UseAPI)
mchan := make(chan *MMMessage)
- if b.Config.UseAPI {
- go b.handleSlackClient(mchan)
- } else {
+ if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
+ flog.Debugf("Choosing webhooks based receiving")
go b.handleMatterHook(mchan)
+ } else {
+ flog.Debugf("Choosing token based receiving")
+ go b.handleSlackClient(mchan)
}
time.Sleep(time.Second)
flog.Debug("Start listening for Slack messages")
for message := range mchan {
// do not send messages from ourself
- if b.Config.UseAPI && message.Username == b.si.User.Name {
+ if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" && message.Username == b.si.User.Name {
continue
}
texts := strings.Split(message.Text, "\n")
diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample
index a5c523bf..c725b141 100644
--- a/matterbridge.toml.sample
+++ b/matterbridge.toml.sample
@@ -199,43 +199,17 @@ ShowJoinPart=false
#REQUIRED
[mattermost.work]
-#### Settings for webhook matterbridge.
-#### These settings will not be used when useAPI is enabled
-
-#Url is your incoming webhook url as specified in mattermost.
-#See account settings - integrations - incoming webhooks on mattermost.
-#REQUIRED (unless useAPI=true)
-URL="https://yourdomain/hooks/yourhookkey"
-
-#Address to listen on for outgoing webhook requests from mattermost.
-#See account settings - integrations - outgoing webhooks on mattermost.
-#This setting will not be used when using -plus switch which doesn't use
-#webhooks
-#REQUIRED (unless useAPI=true)
-BindAddress="0.0.0.0:9999"
-
-#Icon that will be showed in mattermost.
-#OPTIONAL
-IconURL="http://youricon.png"
-
-#### Settings for matterbridge -plus
-#### Thse settings will only be used when using the -plus switch.
-
-#### Settings for using matterbridge API
-#OPTIONAL
-useAPI=false
-
#The mattermost hostname. (do not prefix it with http or https)
-#REQUIRED (when useAPI=true)
+#REQUIRED (when not using webhooks)
Server="yourmattermostserver.domain"
#Your team on mattermost.
-#REQUIRED (when useAPI=true)
+#REQUIRED (when not using webhooks)
Team="yourteam"
#login/pass of your bot.
#Use a dedicated user for this and not your own!
-#REQUIRED (when useAPI=true)
+#REQUIRED (when not using webhooks)
Login="yourlogin"
Password="yourpass"
@@ -243,7 +217,30 @@ Password="yourpass"
#OPTIONAL (default false)
NoTLS=false
-#### Shared settings for matterbridge and -plus
+#### Settings for webhook matterbridge.
+#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE DEDICATED BOT USER WHEN POSSIBLE!
+#You don't need to configure this, if you have configured the settings
+#above.
+
+#Url is your incoming webhook url as specified in mattermost.
+#See account settings - integrations - incoming webhooks on mattermost.
+#If specified, messages will be sent to mattermost using this URL
+#OPTIONAL
+WebhookURL="https://yourdomain/hooks/yourhookkey"
+
+#Address to listen on for outgoing webhook requests from mattermost.
+#See account settings - integrations - outgoing webhooks on mattermost.
+#If specified, messages will be received from mattermost on this ip:port
+#(this will only work if WebhookURL above is also configured)
+#OPTIONAL
+WebhookBindAddress="0.0.0.0:9999"
+
+#Icon that will be showed in mattermost.
+#This only works when WebhookURL is configured
+#OPTIONAL
+IconURL="http://youricon.png"
+
+#### End settings for webhook matterbridge.
#Enable to not verify the certificate on your mattermost server.
#e.g. when using selfsigned certificates
@@ -345,15 +342,20 @@ ShowJoinPart=false
#In this example we use [slack.hobby]
#REQUIRED
[slack.hobby]
-#### Settings for webhook matterbridge.
-#### These settings will not be used when useAPI is enabled
+#Token to connect with the Slack API
+#You'll have to use a test/api-token using a dedicated user and not a bot token.
+#See https://github.com/42wim/matterbridge/issues/75 for more info.
+#Use https://api.slack.com/custom-integrations/legacy-tokens
+#REQUIRED (when not using webhooks)
+Token="yourslacktoken"
+#### Settings for webhook matterbridge.
#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE SLACK API
#AND DEDICATED BOT USER WHEN POSSIBLE!
#Url is your incoming webhook url as specified in slack
#See account settings - integrations - incoming webhooks on slack
-#REQUIRED (unless useAPI=true)
-URL="https://hooks.slack.com/services/yourhook"
+#OPTIONAL
+WebhookURL="https://hooks.slack.com/services/yourhook"
#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE SLACK API
#AND DEDICATED BOT USER WHEN POSSIBLE!
@@ -361,21 +363,8 @@ URL="https://hooks.slack.com/services/yourhook"
#See account settings - integrations - outgoing webhooks on slack
#This setting will not be used when useAPI is eanbled
#webhooks
-#REQUIRED (unless useAPI=true)
-BindAddress="0.0.0.0:9999"
-
-#### Settings for using slack API (RECOMMENDED)
#OPTIONAL
-useAPI=false
-
-#Token to connect with the Slack API
-#You'll have to use a test/api-token using a dedicated user and not a bot token.
-#See https://github.com/42wim/matterbridge/issues/75 for more info.
-#Use https://api.slack.com/custom-integrations/legacy-tokens
-#REQUIRED (when useAPI=true)
-Token="yourslacktoken"
-
-#### Shared settings for webhooks and API
+WebhookBindAddress="0.0.0.0:9999"
#Icon that will be showed in slack
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
@@ -559,12 +548,12 @@ ShowJoinPart=false
#Read #https://rocket.chat/docs/administrator-guides/integrations/#how-to-create-a-new-incoming-webhook
#See administration - integrations - new integration - incoming webhook
#REQUIRED
-URL="https://yourdomain/hooks/yourhookkey"
+WebhookURL="https://yourdomain/hooks/yourhookkey"
#Address to listen on for outgoing webhook requests from rocketchat.
#See administration - integrations - new integration - outgoing webhook
#REQUIRED
-BindAddress="0.0.0.0:9999"
+WebhookBindAddress="0.0.0.0:9999"
#Your nick/username as specified in your incoming webhook "Post as" setting
#REQUIRED