Skip to content

Commit 8646ac3

Browse files
authored
Use conversations api to join channels (#4)
1 parent 30c026b commit 8646ac3

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

example.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"botGravatarMail": "bot+%s@example.com",
2020
"humanGravatarMail": "%s@example.com",
2121
"joinChannels": [
22-
"#general"
22+
{"name": "#general", "id": "<slack channel id>"}
2323
]
2424
},
2525
"ldap": {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/go-redis/redis/v7 v7.4.0
1010
github.com/prometheus/alertmanager v0.21.0
1111
github.com/sirupsen/logrus v1.6.0
12-
github.com/slack-go/slack v0.6.5
12+
github.com/slack-go/slack v0.8.1
1313
github.com/spf13/cobra v1.0.0
1414
github.com/stretchr/testify v1.6.1
1515
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
507507
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
508508
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
509509
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
510-
github.com/slack-go/slack v0.6.5 h1:IkDKtJ2IROJNoe3d6mW870/NRKvq2fhLB/Q5XmzWk00=
511-
github.com/slack-go/slack v0.6.5/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
510+
github.com/slack-go/slack v0.8.1 h1:NqGXuzni8Is3EJWmsuMuBiCCPbWOlBgTKPvdlwS3Huk=
511+
github.com/slack-go/slack v0.8.1/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
512512
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
513513
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
514514
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=

slack/slack.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
"channels/storage"
1818
)
1919

20+
type Conversation struct {
21+
Name string `json:"name"`
22+
ID string `json:"id"`
23+
}
24+
2025
type Config struct {
2126
Name string
2227
Token string
@@ -26,7 +31,7 @@ type Config struct {
2631
BotGravatarMail string
2732
HumanGravatarMail string
2833

29-
JoinChannels []string
34+
JoinChannels []*Conversation
3035
}
3136

3237
type Client struct {
@@ -35,7 +40,7 @@ type Client struct {
3540
store storage.Backend
3641
cache storage.CacheBackend
3742

38-
joinChannels []string
43+
joinChannels []*Conversation
3944

4045
signedSecret string
4146

@@ -78,16 +83,16 @@ func (c *Client) Run() {
7883
go st.Pulling()
7984

8085
for _, ch := range c.joinChannels {
81-
if !strings.HasPrefix(ch, "#") {
86+
if !strings.HasPrefix(ch.Name, "#") {
8287
continue
8388
}
84-
_, err := c.api.JoinChannel(ch)
89+
_, warnings, _, err := c.api.JoinConversation(ch.ID)
8590

8691
if err != nil {
87-
logrus.Warnf("join channel %s failed: %v", ch, err)
92+
logrus.Warnf("join channel %s failed: %v, warning: %v", ch, err, warnings)
8893
continue
8994
}
90-
channel := st.NewChannel(ch)
95+
channel := st.NewChannel(ch.Name)
9196
channel.SetSendFn(func(msg *storage.Message) {
9297
// ignore message from self
9398
if msg.Source == storage.MessageSourceSlack {

0 commit comments

Comments
 (0)