Skip to content

Commit

Permalink
Opt in to private channel support explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
timoreimann committed Apr 18, 2023
1 parent 50111fe commit 187373f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ You will need to create a Slack app with the following scopes:

For private channels and when the `channels:join` scope is not assigned, the Slack app needs to be joined to the target channel manually. (One easy to do this is to select the app from a channel where it already exists and use the context menu to add it to another channel.)

Support for private channels also needs the `--include-private-channels` flag to be explicitly set.

Next up, one or more _slack syncs_ must be configured, preferrably through a YAML configuration file. Here is an [example file](config.example.yaml):

```yaml
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
slToken string
notAlphaNumRE = regexp.MustCompile(`[^[:alnum:]]`)
minDaemonUpdateFrequency = 1 * time.Minute
includePrivateChannels bool
)

func main() {
Expand Down Expand Up @@ -97,6 +98,11 @@ By default, the program will terminate after a single run. Use the --daemon flag
Usage: "how often on-call schedules should be checked for changes (minimum is 1 minute)",
Destination: &p.daemonUpdateFrequency,
},
&cli.BoolFlag{
Name: "include-private-channels",
Usage: "update topics from rivate channels as well",
Destination: &includePrivateChannels,
},
&cli.BoolFlag{
Name: "dry-run",
Usage: "do not update topic",
Expand Down Expand Up @@ -132,7 +138,7 @@ func realMain(p params) error {

sp := syncerParams{
pdClient: newPagerDutyClient(pdToken),
slClient: newSlackMetaClient(slToken),
slClient: newSlackMetaClient(slToken, includePrivateChannels),
}

ctx := context.Background()
Expand Down
15 changes: 11 additions & 4 deletions slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ func (cl channelList) find(id, name string) *slack.Channel {
}

type slackMetaClient struct {
slackClient *slack.Client
slackClient *slack.Client
channelTypes []string
}

func newSlackMetaClient(token string) *slackMetaClient {
func newSlackMetaClient(token string, includePrivateChannels bool) *slackMetaClient {
channelTypes := []string{"public_channel"}
if includePrivateChannels {
channelTypes = append(channelTypes, "private_channel")
}

return &slackMetaClient{
slackClient: slack.New(token),
slackClient: slack.New(token),
channelTypes: channelTypes,
}
}

Expand Down Expand Up @@ -100,7 +107,7 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
Cursor: cursor,
ExcludeArchived: "true",
Limit: 200,
Types: []string{"public_channel", "private_channel"},
Types: metaClient.channelTypes,
})
return err
})
Expand Down

0 comments on commit 187373f

Please sign in to comment.