Skip to content

Commit f513470

Browse files
committed
Use channels:join permission to just ... join the channel
1 parent cbb877b commit f513470

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

bridge/slack/slack.go

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,44 +160,36 @@ func (b *Bslack) Disconnect() error {
160160
return b.rtm.Disconnect()
161161
}
162162

163-
// JoinChannel only acts as a verification method that checks whether Matterbridge's
164-
// Slack integration is already member of the channel. This is because Slack does not
165-
// allow apps or bots to join channels themselves and they need to be invited
166-
// manually by a user.
163+
// There is a separate OAUTH scope to join channels programmatically.
164+
// If you have not added `channels:join` then the bot will need to be added manually.
167165
func (b *Bslack) JoinChannel(channel config.ChannelInfo) error {
168166
// We can only join a channel through the Slack API.
169167
if b.sc == nil {
170168
return nil
171169
}
172170

173-
// try to join a channel when in legacy
174-
if b.legacy {
175-
_, _, _, err := b.sc.JoinConversation(channel.Name)
176-
if err != nil {
177-
switch err.Error() {
178-
case "name_taken", "restricted_action":
179-
case "default":
180-
return err
181-
}
182-
}
183-
}
184-
185171
b.channels.populateChannels(false)
186172

187173
channelInfo, err := b.channels.getChannel(channel.Name)
188174
if err != nil {
189-
return fmt.Errorf("could not join channel: %#v", err)
175+
return fmt.Errorf("could not find channel: %#v", err)
176+
}
177+
178+
// we can't join a channel unless we are using legacy tokens #651
179+
if !channelInfo.IsMember {
180+
b.Log.Infof("Not currently a member of %s. Trying to join by ID (%s)", channel.Name, channelInfo.ID)
181+
// try to join the channel
182+
_, _, _, err := b.sc.JoinConversation(channelInfo.ID)
183+
if err != nil {
184+
return fmt.Errorf("the slack integration that matterbridge is using is not member of channel '%s' (and cannot join), please add it manually. %s", channelInfo.Name, err)
185+
}
190186
}
191187

192188
if strings.HasPrefix(channel.Name, "ID:") {
193189
b.useChannelID = true
194190
channel.Name = channelInfo.Name
195191
}
196192

197-
// we can't join a channel unless we are using legacy tokens #651
198-
if !channelInfo.IsMember && !b.legacy {
199-
return fmt.Errorf("slack integration that matterbridge is using is not member of channel '%s', please add it manually", channelInfo.Name)
200-
}
201193
return nil
202194
}
203195

0 commit comments

Comments
 (0)