Skip to content

Commit

Permalink
fix(sensor): Slack trigger should not join conversation for private c…
Browse files Browse the repository at this point in the history
…hannel (#1078)

* fix: 1077 - JoinConversation for private channel throws method_not_supported_for_channel_type

Signed-off-by: Shashwat Rawat <[email protected]>

* simplified comparison to bool

Signed-off-by: Shashwat Rawat <[email protected]>
  • Loading branch information
shashwat-appdirect authored Feb 23, 2021
1 parent 01355d7 commit 8b77d27
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sensors/triggers/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (t *SlackTrigger) Execute(ctx context.Context, events map[string]*v1alpha1.
Types: []string{"public_channel", "private_channel"},
}
channelID := ""
isPrivateChannel := false
for {
channels, nextCursor, err := api.GetConversations(params)
if err != nil {
Expand All @@ -121,6 +122,7 @@ func (t *SlackTrigger) Execute(ctx context.Context, events map[string]*v1alpha1.
for _, c := range channels {
if c.Name == channel {
channelID = c.ID
isPrivateChannel = c.IsPrivate
break
}
}
Expand All @@ -133,11 +135,14 @@ func (t *SlackTrigger) Execute(ctx context.Context, events map[string]*v1alpha1.
return nil, errors.Errorf("failed to get channelID of %s", channel)
}
// Only join if not joined? Maybe a join API call is easier.
c, _, _, err := api.JoinConversation(channelID)
t.Logger.Debug("successfully joined channel", zap.Any("channel", c))
if err != nil {
t.Logger.Error("unable to join channel...", zap.Any("channelName", channel), zap.Any("channelID", channelID), zap.Error(err))
return nil, errors.Wrapf(err, "failed to join channel %s", channel)
// Not applicable for private channels since bot cannot join private channels
if !isPrivateChannel {
c, _, _, err := api.JoinConversation(channelID)
t.Logger.Debug("successfully joined channel", zap.Any("channel", c))
if err != nil {
t.Logger.Error("unable to join channel...", zap.Any("channelName", channel), zap.Any("channelID", channelID), zap.Error(err))
return nil, errors.Wrapf(err, "failed to join channel %s", channel)
}
}

t.Logger.Info("posting to channel...", zap.Any("channelName", channel))
Expand Down

0 comments on commit 8b77d27

Please sign in to comment.