Skip to content

Commit 830361e

Browse files
committed
Deprecate URL,useAPI,BindAddress (slack,mattermost,rocketchat)
1 parent 1b1a9ce commit 830361e

File tree

6 files changed

+122
-77
lines changed

6 files changed

+122
-77
lines changed

bridge/config/config.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type ChannelInfo struct {
4040

4141
type Protocol struct {
4242
AuthCode string // steam
43-
BindAddress string // mattermost, slack
43+
BindAddress string // mattermost, slack // DEPRECATED
4444
Buffer int // api
4545
EditSuffix string // mattermost, slack, discord, telegram, gitter
4646
EditDisable bool // mattermost, slack, discord, telegram, gitter
@@ -72,12 +72,14 @@ type Protocol struct {
7272
SkipTLSVerify bool // IRC, mattermost
7373
Team string // mattermost
7474
Token string // gitter, slack, discord, api
75-
URL string // mattermost, slack, matrix
75+
URL string // mattermost, slack // DEPRECATED
7676
UseAPI bool // mattermost, slack
7777
UseSASL bool // IRC
7878
UseTLS bool // IRC
7979
UseFirstName bool // telegram
80-
WebhookURL string // discord
80+
WebhookBindAddress string // mattermost, slack
81+
WebhookURL string // mattermost, slack
82+
WebhookUse string // mattermost, slack, discord
8183
}
8284

8385
type ChannelOptions struct {
@@ -128,6 +130,28 @@ func NewConfig(cfgfile string) *Config {
128130
if _, err := toml.DecodeFile(cfgfile, &cfg); err != nil {
129131
log.Fatal(err)
130132
}
133+
fail := false
134+
for k, v := range cfg.Mattermost {
135+
res := Deprecated(v, "mattermost."+k)
136+
if res {
137+
fail = res
138+
}
139+
}
140+
for k, v := range cfg.Slack {
141+
res := Deprecated(v, "slack."+k)
142+
if res {
143+
fail = res
144+
}
145+
}
146+
for k, v := range cfg.Rocketchat {
147+
res := Deprecated(v, "rocketchat."+k)
148+
if res {
149+
fail = res
150+
}
151+
}
152+
if fail {
153+
log.Fatalf("Fix your config. Please see changelog for more information")
154+
}
131155
return &cfg
132156
}
133157

@@ -178,3 +202,17 @@ func GetIconURL(msg *Message, cfg *Protocol) string {
178202
iconURL = strings.Replace(iconURL, "{PROTOCOL}", protocol, -1)
179203
return iconURL
180204
}
205+
206+
func Deprecated(cfg Protocol, account string) bool {
207+
if cfg.BindAddress != "" {
208+
log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
209+
} else if cfg.URL != "" {
210+
log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
211+
} else if cfg.UseAPI == true {
212+
log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
213+
} else {
214+
return false
215+
}
216+
return true
217+
//log.Fatalf("ERROR: Fix your config: %s", account)
218+
}

bridge/discord/discord.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
4949
func (b *bdiscord) Connect() error {
5050
var err error
5151
flog.Info("Connecting")
52+
if b.Config.WebhookURL == "" {
53+
flog.Info("Connecting using token")
54+
} else {
55+
flog.Info("Connecting using webhookurl (for posting) and token")
56+
}
5257
if !strings.HasPrefix(b.Config.Token, "Bot ") {
5358
b.Config.Token = "Bot " + b.Config.Token
5459
}
@@ -110,7 +115,7 @@ func (b *bdiscord) Send(msg config.Message) error {
110115
return nil
111116
}
112117
if b.Config.WebhookURL == "" {
113-
flog.Debugf("Broadcasting using API")
118+
flog.Debugf("Broadcasting using token (API)")
114119
b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
115120
} else {
116121
flog.Debugf("Broadcasting using Webhook")

bridge/mattermost/mattermost.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ func (b *Bmattermost) Command(cmd string) string {
5555
}
5656

5757
func (b *Bmattermost) Connect() error {
58-
if !b.Config.UseAPI {
59-
flog.Info("Connecting webhooks")
60-
b.mh = matterhook.New(b.Config.URL,
58+
if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
59+
flog.Info("Connecting using webhookurl and webhookbindaddress")
60+
b.mh = matterhook.New(b.Config.WebhookURL,
6161
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
62-
BindAddress: b.Config.BindAddress})
62+
BindAddress: b.Config.WebhookBindAddress})
63+
} else if b.Config.WebhookURL != "" {
64+
flog.Info("Connecting using webhookurl (for posting) and token")
65+
b.mh = matterhook.New(b.Config.WebhookURL,
66+
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
67+
DisableServer: true})
6368
} else {
69+
flog.Info("Connecting using token")
6470
b.mc = matterclient.New(b.Config.Login, b.Config.Password,
6571
b.Config.Team, b.Config.Server)
6672
b.mc.SkipTLSVerify = b.Config.SkipTLSVerify
@@ -85,7 +91,7 @@ func (b *Bmattermost) Disconnect() error {
8591

8692
func (b *Bmattermost) JoinChannel(channel string) error {
8793
// we can only join channels using the API
88-
if b.Config.UseAPI {
94+
if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" {
8995
return b.mc.JoinChannel(b.mc.GetChannelId(channel, ""))
9096
}
9197
return nil
@@ -100,7 +106,7 @@ func (b *Bmattermost) Send(msg config.Message) error {
100106
if b.Config.PrefixMessagesWithNick {
101107
message = nick + message
102108
}
103-
if !b.Config.UseAPI {
109+
if b.Config.WebhookURL != "" {
104110
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
105111
matterMessage.IconURL = msg.Avatar
106112
matterMessage.Channel = channel
@@ -119,12 +125,13 @@ func (b *Bmattermost) Send(msg config.Message) error {
119125
}
120126

121127
func (b *Bmattermost) handleMatter() {
122-
flog.Debugf("Choosing API based Mattermost connection: %t", b.Config.UseAPI)
123128
mchan := make(chan *MMMessage)
124-
if b.Config.UseAPI {
125-
go b.handleMatterClient(mchan)
126-
} else {
129+
if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
130+
flog.Debugf("Choosing webhooks based receiving")
127131
go b.handleMatterHook(mchan)
132+
} else {
133+
flog.Debugf("Choosing login (api) based receiving")
134+
go b.handleMatterClient(mchan)
128135
}
129136
for message := range mchan {
130137
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)

bridge/rocketchat/rocketchat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ func (b *Brocketchat) Command(cmd string) string {
4141

4242
func (b *Brocketchat) Connect() error {
4343
flog.Info("Connecting webhooks")
44-
b.mh = matterhook.New(b.Config.URL,
44+
b.mh = matterhook.New(b.Config.WebhookURL,
4545
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
4646
DisableServer: true})
47-
b.rh = rockethook.New(b.Config.URL, rockethook.Config{BindAddress: b.Config.BindAddress})
47+
b.rh = rockethook.New(b.Config.WebhookURL, rockethook.Config{BindAddress: b.Config.WebhookBindAddress})
4848
go b.handleRocketHook()
4949
return nil
5050
}

bridge/slack/slack.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ func (b *Bslack) Command(cmd string) string {
5252
}
5353

5454
func (b *Bslack) Connect() error {
55-
flog.Info("Connecting")
56-
if !b.Config.UseAPI {
57-
b.mh = matterhook.New(b.Config.URL,
58-
matterhook.Config{BindAddress: b.Config.BindAddress})
55+
if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
56+
flog.Info("Connecting using webhookurl and webhookbindaddress")
57+
b.mh = matterhook.New(b.Config.WebhookURL,
58+
matterhook.Config{BindAddress: b.Config.WebhookBindAddress})
59+
} else if b.Config.WebhookURL != "" {
60+
flog.Info("Connecting using webhookurl (for posting) and token")
61+
b.mh = matterhook.New(b.Config.WebhookURL,
62+
matterhook.Config{DisableServer: true})
5963
} else {
64+
flog.Info("Connecting using token")
6065
b.sc = slack.New(b.Config.Token)
6166
b.rtm = b.sc.NewRTM()
6267
go b.rtm.ManageConnection()
@@ -73,7 +78,7 @@ func (b *Bslack) Disconnect() error {
7378

7479
func (b *Bslack) JoinChannel(channel string) error {
7580
// we can only join channels using the API
76-
if b.Config.UseAPI {
81+
if b.Config.WebhookURL == "" || b.Config.WebhookBindAddress == "" {
7782
if strings.HasPrefix(b.Config.Token, "xoxb") {
7883
// TODO check if bot has already joined channel
7984
return nil
@@ -96,7 +101,7 @@ func (b *Bslack) Send(msg config.Message) error {
96101
if b.Config.PrefixMessagesWithNick {
97102
message = nick + " " + message
98103
}
99-
if !b.Config.UseAPI {
104+
if b.Config.WebhookURL != "" {
100105
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
101106
matterMessage.Channel = channel
102107
matterMessage.UserName = nick
@@ -169,18 +174,19 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
169174
}
170175

171176
func (b *Bslack) handleSlack() {
172-
flog.Debugf("Choosing API based slack connection: %t", b.Config.UseAPI)
173177
mchan := make(chan *MMMessage)
174-
if b.Config.UseAPI {
175-
go b.handleSlackClient(mchan)
176-
} else {
178+
if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
179+
flog.Debugf("Choosing webhooks based receiving")
177180
go b.handleMatterHook(mchan)
181+
} else {
182+
flog.Debugf("Choosing token based receiving")
183+
go b.handleSlackClient(mchan)
178184
}
179185
time.Sleep(time.Second)
180186
flog.Debug("Start listening for Slack messages")
181187
for message := range mchan {
182188
// do not send messages from ourself
183-
if b.Config.UseAPI && message.Username == b.si.User.Name {
189+
if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" && message.Username == b.si.User.Name {
184190
continue
185191
}
186192
texts := strings.Split(message.Text, "\n")

matterbridge.toml.sample

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -199,51 +199,48 @@ ShowJoinPart=false
199199
#REQUIRED
200200

201201
[mattermost.work]
202-
#### Settings for webhook matterbridge.
203-
#### These settings will not be used when useAPI is enabled
204-
205-
#Url is your incoming webhook url as specified in mattermost.
206-
#See account settings - integrations - incoming webhooks on mattermost.
207-
#REQUIRED (unless useAPI=true)
208-
URL="https://yourdomain/hooks/yourhookkey"
209-
210-
#Address to listen on for outgoing webhook requests from mattermost.
211-
#See account settings - integrations - outgoing webhooks on mattermost.
212-
#This setting will not be used when using -plus switch which doesn't use
213-
#webhooks
214-
#REQUIRED (unless useAPI=true)
215-
BindAddress="0.0.0.0:9999"
216-
217-
#Icon that will be showed in mattermost.
218-
#OPTIONAL
219-
IconURL="http://youricon.png"
220-
221-
#### Settings for matterbridge -plus
222-
#### Thse settings will only be used when using the -plus switch.
223-
224-
#### Settings for using matterbridge API
225-
#OPTIONAL
226-
useAPI=false
227-
228202
#The mattermost hostname. (do not prefix it with http or https)
229-
#REQUIRED (when useAPI=true)
203+
#REQUIRED (when not using webhooks)
230204
Server="yourmattermostserver.domain"
231205

232206
#Your team on mattermost.
233-
#REQUIRED (when useAPI=true)
207+
#REQUIRED (when not using webhooks)
234208
Team="yourteam"
235209

236210
#login/pass of your bot.
237211
#Use a dedicated user for this and not your own!
238-
#REQUIRED (when useAPI=true)
212+
#REQUIRED (when not using webhooks)
239213
Login="yourlogin"
240214
Password="yourpass"
241215

242216
#Enable this to make a http connection (instead of https) to your mattermost.
243217
#OPTIONAL (default false)
244218
NoTLS=false
245219

246-
#### Shared settings for matterbridge and -plus
220+
#### Settings for webhook matterbridge.
221+
#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE DEDICATED BOT USER WHEN POSSIBLE!
222+
#You don't need to configure this, if you have configured the settings
223+
#above.
224+
225+
#Url is your incoming webhook url as specified in mattermost.
226+
#See account settings - integrations - incoming webhooks on mattermost.
227+
#If specified, messages will be sent to mattermost using this URL
228+
#OPTIONAL
229+
WebhookURL="https://yourdomain/hooks/yourhookkey"
230+
231+
#Address to listen on for outgoing webhook requests from mattermost.
232+
#See account settings - integrations - outgoing webhooks on mattermost.
233+
#If specified, messages will be received from mattermost on this ip:port
234+
#(this will only work if WebhookURL above is also configured)
235+
#OPTIONAL
236+
WebhookBindAddress="0.0.0.0:9999"
237+
238+
#Icon that will be showed in mattermost.
239+
#This only works when WebhookURL is configured
240+
#OPTIONAL
241+
IconURL="http://youricon.png"
242+
243+
#### End settings for webhook matterbridge.
247244

248245
#Enable to not verify the certificate on your mattermost server.
249246
#e.g. when using selfsigned certificates
@@ -345,37 +342,29 @@ ShowJoinPart=false
345342
#In this example we use [slack.hobby]
346343
#REQUIRED
347344
[slack.hobby]
348-
#### Settings for webhook matterbridge.
349-
#### These settings will not be used when useAPI is enabled
345+
#Token to connect with the Slack API
346+
#You'll have to use a test/api-token using a dedicated user and not a bot token.
347+
#See https://github.com/42wim/matterbridge/issues/75 for more info.
348+
#Use https://api.slack.com/custom-integrations/legacy-tokens
349+
#REQUIRED (when not using webhooks)
350+
Token="yourslacktoken"
350351

352+
#### Settings for webhook matterbridge.
351353
#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE SLACK API
352354
#AND DEDICATED BOT USER WHEN POSSIBLE!
353355
#Url is your incoming webhook url as specified in slack
354356
#See account settings - integrations - incoming webhooks on slack
355-
#REQUIRED (unless useAPI=true)
356-
URL="https://hooks.slack.com/services/yourhook"
357+
#OPTIONAL
358+
WebhookURL="https://hooks.slack.com/services/yourhook"
357359

358360
#NOT RECOMMENDED TO USE INCOMING/OUTGOING WEBHOOK. USE SLACK API
359361
#AND DEDICATED BOT USER WHEN POSSIBLE!
360362
#Address to listen on for outgoing webhook requests from slack
361363
#See account settings - integrations - outgoing webhooks on slack
362364
#This setting will not be used when useAPI is eanbled
363365
#webhooks
364-
#REQUIRED (unless useAPI=true)
365-
BindAddress="0.0.0.0:9999"
366-
367-
#### Settings for using slack API (RECOMMENDED)
368366
#OPTIONAL
369-
useAPI=false
370-
371-
#Token to connect with the Slack API
372-
#You'll have to use a test/api-token using a dedicated user and not a bot token.
373-
#See https://github.com/42wim/matterbridge/issues/75 for more info.
374-
#Use https://api.slack.com/custom-integrations/legacy-tokens
375-
#REQUIRED (when useAPI=true)
376-
Token="yourslacktoken"
377-
378-
#### Shared settings for webhooks and API
367+
WebhookBindAddress="0.0.0.0:9999"
379368

380369
#Icon that will be showed in slack
381370
#The string "{NICK}" (case sensitive) will be replaced by the actual nick / username.
@@ -559,12 +548,12 @@ ShowJoinPart=false
559548
#Read #https://rocket.chat/docs/administrator-guides/integrations/#how-to-create-a-new-incoming-webhook
560549
#See administration - integrations - new integration - incoming webhook
561550
#REQUIRED
562-
URL="https://yourdomain/hooks/yourhookkey"
551+
WebhookURL="https://yourdomain/hooks/yourhookkey"
563552

564553
#Address to listen on for outgoing webhook requests from rocketchat.
565554
#See administration - integrations - new integration - outgoing webhook
566555
#REQUIRED
567-
BindAddress="0.0.0.0:9999"
556+
WebhookBindAddress="0.0.0.0:9999"
568557

569558
#Your nick/username as specified in your incoming webhook "Post as" setting
570559
#REQUIRED

0 commit comments

Comments
 (0)