diff options
Diffstat (limited to 'channel.go')
-rw-r--r-- | channel.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/channel.go b/channel.go new file mode 100644 index 0000000..95cdd7d --- /dev/null +++ b/channel.go @@ -0,0 +1,39 @@ +package main + +import ( + "encoding/json" + "errors" + "log" + "net/http" + "net/url" +) + +func getUsers(token string, channel string) ([]string, error) { + u, _ := url.Parse("https://slack.com/api/channels.info") + u.Query().Set("token", token) + u.Query().Set("channel", channel) + req, err := http.NewRequest(http.MethodGet, u.String(), nil) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + resp, err := getClient().Do(req) + if err != nil { + log.Println(err) + return nil, err + } + r := struct { + OK bool `json:"ok"` + Error string `json:"error"` + Channel struct { + Members []string `json:"members"` + } `json:"channel"` + }{} + if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { + return nil, err + } + if !r.OK { + return nil, errors.New(r.Error) + } + return r.Channel.Members, nil +} |