From 187373f4c43435007c9e29c8e914f24d25fe5dd1 Mon Sep 17 00:00:00 2001 From: Timo Reimann Date: Tue, 18 Apr 2023 13:29:03 +0200 Subject: [PATCH] Opt in to private channel support explicitly --- README.md | 2 ++ main.go | 8 +++++++- slack.go | 15 +++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0113f6..7a401aa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index bb89782..2a5abf8 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var ( slToken string notAlphaNumRE = regexp.MustCompile(`[^[:alnum:]]`) minDaemonUpdateFrequency = 1 * time.Minute + includePrivateChannels bool ) func main() { @@ -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", @@ -132,7 +138,7 @@ func realMain(p params) error { sp := syncerParams{ pdClient: newPagerDutyClient(pdToken), - slClient: newSlackMetaClient(slToken), + slClient: newSlackMetaClient(slToken, includePrivateChannels), } ctx := context.Background() diff --git a/slack.go b/slack.go index 9d3a3bb..2121a28 100644 --- a/slack.go +++ b/slack.go @@ -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, } } @@ -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 })