Skip to content

Commit a1680bf

Browse files
authored
Merge pull request #11 from timoreimann/make-private-channel-usage-optional
Opt in to private channel support explicitly
2 parents 50111fe + 187373f commit a1680bf

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ You will need to create a Slack app with the following scopes:
2121

2222
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.)
2323

24+
Support for private channels also needs the `--include-private-channels` flag to be explicitly set.
25+
2426
Next up, one or more _slack syncs_ must be configured, preferrably through a YAML configuration file. Here is an [example file](config.example.yaml):
2527

2628
```yaml

main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
slToken string
1919
notAlphaNumRE = regexp.MustCompile(`[^[:alnum:]]`)
2020
minDaemonUpdateFrequency = 1 * time.Minute
21+
includePrivateChannels bool
2122
)
2223

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

133139
sp := syncerParams{
134140
pdClient: newPagerDutyClient(pdToken),
135-
slClient: newSlackMetaClient(slToken),
141+
slClient: newSlackMetaClient(slToken, includePrivateChannels),
136142
}
137143

138144
ctx := context.Background()

slack.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,19 @@ func (cl channelList) find(id, name string) *slack.Channel {
5454
}
5555

5656
type slackMetaClient struct {
57-
slackClient *slack.Client
57+
slackClient *slack.Client
58+
channelTypes []string
5859
}
5960

60-
func newSlackMetaClient(token string) *slackMetaClient {
61+
func newSlackMetaClient(token string, includePrivateChannels bool) *slackMetaClient {
62+
channelTypes := []string{"public_channel"}
63+
if includePrivateChannels {
64+
channelTypes = append(channelTypes, "private_channel")
65+
}
66+
6167
return &slackMetaClient{
62-
slackClient: slack.New(token),
68+
slackClient: slack.New(token),
69+
channelTypes: channelTypes,
6370
}
6471
}
6572

@@ -100,7 +107,7 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
100107
Cursor: cursor,
101108
ExcludeArchived: "true",
102109
Limit: 200,
103-
Types: []string{"public_channel", "private_channel"},
110+
Types: metaClient.channelTypes,
104111
})
105112
return err
106113
})

0 commit comments

Comments
 (0)