From 9522c6db20b7739eb46a55008d02b0d58968c53a Mon Sep 17 00:00:00 2001 From: Naoki Kanatani Date: Wed, 17 Mar 2021 03:04:23 +0900 Subject: [PATCH] Remove deprecated methods Related issues: - https://github.com/slack-go/slack/issues/748 - https://github.com/slack-go/slack/issues/876 More details: - https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api --- channels.go | 678 ---------------------------------- examples/channels/channels.go | 21 -- examples/groups/groups.go | 22 -- examples/ims/ims.go | 21 -- groups.go | 567 ---------------------------- im.go | 199 ---------- slacktest/handlers.go | 10 - slacktest/handlers_test.go | 53 --- slacktest/server.go | 3 - 9 files changed, 1574 deletions(-) delete mode 100644 examples/channels/channels.go delete mode 100644 examples/groups/groups.go delete mode 100644 examples/ims/ims.go diff --git a/channels.go b/channels.go index c05521d0f..2fca8b92e 100644 --- a/channels.go +++ b/channels.go @@ -3,8 +3,6 @@ package slack import ( "context" "net/url" - "strconv" - "time" ) type channelResponseFull struct { @@ -19,12 +17,6 @@ type channelResponseFull struct { } // Channel contains information about the channel -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api type Channel struct { GroupConversation IsChannel bool `json:"is_channel"` @@ -42,673 +34,3 @@ func (api *Client) channelRequest(ctx context.Context, path string, values url.V return response, response.Err() } - -// GetChannelsOption option provided when getting channels. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -type GetChannelsOption func(*ChannelPagination) error - -// GetChannelsOptionExcludeMembers excludes the members collection from each channel. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func GetChannelsOptionExcludeMembers() GetChannelsOption { - return func(p *ChannelPagination) error { - p.excludeMembers = true - return nil - } -} - -// GetChannelsOptionExcludeArchived excludes archived channels from results. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func GetChannelsOptionExcludeArchived() GetChannelsOption { - return func(p *ChannelPagination) error { - p.excludeArchived = true - return nil - } -} - -// ArchiveChannel archives the given channel -// see https://api.slack.com/methods/channels.archive -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) ArchiveChannel(channelID string) error { - return api.ArchiveChannelContext(context.Background(), channelID) -} - -// ArchiveChannelContext archives the given channel with a custom context -// see https://api.slack.com/methods/channels.archive -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) ArchiveChannelContext(ctx context.Context, channelID string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - } - - _, err = api.channelRequest(ctx, "channels.archive", values) - return err -} - -// UnarchiveChannel unarchives the given channel -// see https://api.slack.com/methods/channels.unarchive -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) UnarchiveChannel(channelID string) error { - return api.UnarchiveChannelContext(context.Background(), channelID) -} - -// UnarchiveChannelContext unarchives the given channel with a custom context -// see https://api.slack.com/methods/channels.unarchive -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) UnarchiveChannelContext(ctx context.Context, channelID string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - } - - _, err = api.channelRequest(ctx, "channels.unarchive", values) - return err -} - -// CreateChannel creates a channel with the given name and returns a *Channel -// see https://api.slack.com/methods/channels.create -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateChannel(channelName string) (*Channel, error) { - return api.CreateChannelContext(context.Background(), channelName) -} - -// CreateChannelContext creates a channel with the given name and returns a *Channel with a custom context -// see https://api.slack.com/methods/channels.create -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateChannelContext(ctx context.Context, channelName string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "name": {channelName}, - } - - response, err := api.channelRequest(ctx, "channels.create", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// GetChannelHistory retrieves the channel history -// see https://api.slack.com/methods/channels.history -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelHistory(channelID string, params HistoryParameters) (*History, error) { - return api.GetChannelHistoryContext(context.Background(), channelID, params) -} - -// GetChannelHistoryContext retrieves the channel history with a custom context -// see https://api.slack.com/methods/channels.history -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelHistoryContext(ctx context.Context, channelID string, params HistoryParameters) (*History, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - } - if params.Latest != DEFAULT_HISTORY_LATEST { - values.Add("latest", params.Latest) - } - if params.Oldest != DEFAULT_HISTORY_OLDEST { - values.Add("oldest", params.Oldest) - } - if params.Count != DEFAULT_HISTORY_COUNT { - values.Add("count", strconv.Itoa(params.Count)) - } - if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { - if params.Inclusive { - values.Add("inclusive", "1") - } else { - values.Add("inclusive", "0") - } - } - - if params.Unreads != DEFAULT_HISTORY_UNREADS { - if params.Unreads { - values.Add("unreads", "1") - } else { - values.Add("unreads", "0") - } - } - - response, err := api.channelRequest(ctx, "channels.history", values) - if err != nil { - return nil, err - } - return &response.History, nil -} - -// GetChannelInfo retrieves the given channel -// see https://api.slack.com/methods/channels.info -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelInfo(channelID string) (*Channel, error) { - return api.GetChannelInfoContext(context.Background(), channelID) -} - -// GetChannelInfoContext retrieves the given channel with a custom context -// see https://api.slack.com/methods/channels.info -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelInfoContext(ctx context.Context, channelID string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "include_locale": {strconv.FormatBool(true)}, - } - - response, err := api.channelRequest(ctx, "channels.info", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// InviteUserToChannel invites a user to a given channel and returns a *Channel -// see https://api.slack.com/methods/channels.invite -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) InviteUserToChannel(channelID, user string) (*Channel, error) { - return api.InviteUserToChannelContext(context.Background(), channelID, user) -} - -// InviteUserToChannelContext invites a user to a given channel and returns a *Channel with a custom context -// see https://api.slack.com/methods/channels.invite -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) InviteUserToChannelContext(ctx context.Context, channelID, user string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "user": {user}, - } - - response, err := api.channelRequest(ctx, "channels.invite", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// JoinChannel joins the currently authenticated user to a channel -// see https://api.slack.com/methods/channels.join -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) JoinChannel(channelName string) (*Channel, error) { - return api.JoinChannelContext(context.Background(), channelName) -} - -// JoinChannelContext joins the currently authenticated user to a channel with a custom context -// see https://api.slack.com/methods/channels.join -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) JoinChannelContext(ctx context.Context, channelName string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "name": {channelName}, - } - - response, err := api.channelRequest(ctx, "channels.join", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// LeaveChannel makes the authenticated user leave the given channel -// see https://api.slack.com/methods/channels.leave -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) LeaveChannel(channelID string) (bool, error) { - return api.LeaveChannelContext(context.Background(), channelID) -} - -// LeaveChannelContext makes the authenticated user leave the given channel with a custom context -// see https://api.slack.com/methods/channels.leave -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) LeaveChannelContext(ctx context.Context, channelID string) (bool, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - } - - response, err := api.channelRequest(ctx, "channels.leave", values) - if err != nil { - return false, err - } - - return response.NotInChannel, nil -} - -// KickUserFromChannel kicks a user from a given channel -// see https://api.slack.com/methods/channels.kick -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) KickUserFromChannel(channelID, user string) error { - return api.KickUserFromChannelContext(context.Background(), channelID, user) -} - -// KickUserFromChannelContext kicks a user from a given channel with a custom context -// see https://api.slack.com/methods/channels.kick -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) KickUserFromChannelContext(ctx context.Context, channelID, user string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "user": {user}, - } - - _, err = api.channelRequest(ctx, "channels.kick", values) - return err -} - -func newChannelPagination(c *Client, options ...GetChannelsOption) (cp ChannelPagination) { - cp = ChannelPagination{ - c: c, - limit: 200, // per slack api documentation. - } - - for _, opt := range options { - opt(&cp) - } - - return cp -} - -// ChannelPagination allows for paginating over the channels -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -type ChannelPagination struct { - Channels []Channel - limit int - excludeArchived bool - excludeMembers bool - previousResp *ResponseMetadata - c *Client -} - -// Done checks if the pagination has completed -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (ChannelPagination) Done(err error) bool { - return err == errPaginationComplete -} - -// Failure checks if pagination failed. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (t ChannelPagination) Failure(err error) error { - if t.Done(err) { - return nil - } - - return err -} - -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (t ChannelPagination) Next(ctx context.Context) (_ ChannelPagination, err error) { - var ( - resp *channelResponseFull - ) - - if t.c == nil || (t.previousResp != nil && t.previousResp.Cursor == "") { - return t, errPaginationComplete - } - - t.previousResp = t.previousResp.initialize() - - values := url.Values{ - "limit": {strconv.Itoa(t.limit)}, - "exclude_archived": {strconv.FormatBool(t.excludeArchived)}, - "exclude_members": {strconv.FormatBool(t.excludeMembers)}, - "token": {t.c.token}, - "cursor": {t.previousResp.Cursor}, - } - - if resp, err = t.c.channelRequest(ctx, "channels.list", values); err != nil { - return t, err - } - - t.c.Debugf("GetChannelsContext: got %d channels; metadata %v", len(resp.Channels), resp.Metadata) - t.Channels = resp.Channels - t.previousResp = &resp.Metadata - - return t, nil -} - -// GetChannelsPaginated fetches channels in a paginated fashion, see GetChannelsContext for usage. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelsPaginated(options ...GetChannelsOption) ChannelPagination { - return newChannelPagination(api, options...) -} - -// GetChannels retrieves all the channels -// see https://api.slack.com/methods/channels.list -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannels(excludeArchived bool, options ...GetChannelsOption) ([]Channel, error) { - return api.GetChannelsContext(context.Background(), excludeArchived, options...) -} - -// GetChannelsContext retrieves all the channels with a custom context -// see https://api.slack.com/methods/channels.list -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelsContext(ctx context.Context, excludeArchived bool, options ...GetChannelsOption) (results []Channel, err error) { - if excludeArchived { - options = append(options, GetChannelsOptionExcludeArchived()) - } - - p := api.GetChannelsPaginated(options...) - for err == nil { - p, err = p.Next(ctx) - if err == nil { - results = append(results, p.Channels...) - } else if rateLimitedError, ok := err.(*RateLimitedError); ok { - select { - case <-ctx.Done(): - err = ctx.Err() - case <-time.After(rateLimitedError.RetryAfter): - err = nil - } - } - } - - return results, p.Failure(err) -} - -// SetChannelReadMark sets the read mark of a given channel to a specific point -// Clients should try to avoid making this call too often. When needing to mark a read position, a client should set a -// timer before making the call. In this way, any further updates needed during the timeout will not generate extra calls -// (just one per channel). This is useful for when reading scroll-back history, or following a busy live channel. A -// timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout. -// see https://api.slack.com/methods/channels.mark -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelReadMark(channelID, ts string) error { - return api.SetChannelReadMarkContext(context.Background(), channelID, ts) -} - -// SetChannelReadMarkContext sets the read mark of a given channel to a specific point with a custom context -// For more details see SetChannelReadMark documentation -// see https://api.slack.com/methods/channels.mark -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelReadMarkContext(ctx context.Context, channelID, ts string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "ts": {ts}, - } - - _, err = api.channelRequest(ctx, "channels.mark", values) - return err -} - -// RenameChannel renames a given channel -// see https://api.slack.com/methods/channels.rename -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) RenameChannel(channelID, name string) (*Channel, error) { - return api.RenameChannelContext(context.Background(), channelID, name) -} - -// RenameChannelContext renames a given channel with a custom context -// see https://api.slack.com/methods/channels.rename -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) RenameChannelContext(ctx context.Context, channelID, name string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "name": {name}, - } - - // XXX: the created entry in this call returns a string instead of a number - // so I may have to do some workaround to solve it. - response, err := api.channelRequest(ctx, "channels.rename", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// SetChannelPurpose sets the channel purpose and returns the purpose that was successfully set -// see https://api.slack.com/methods/channels.setPurpose -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelPurpose(channelID, purpose string) (string, error) { - return api.SetChannelPurposeContext(context.Background(), channelID, purpose) -} - -// SetChannelPurposeContext sets the channel purpose and returns the purpose that was successfully set with a custom context -// see https://api.slack.com/methods/channels.setPurpose -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelPurposeContext(ctx context.Context, channelID, purpose string) (string, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "purpose": {purpose}, - } - - response, err := api.channelRequest(ctx, "channels.setPurpose", values) - if err != nil { - return "", err - } - return response.Purpose, nil -} - -// SetChannelTopic sets the channel topic and returns the topic that was successfully set -// see https://api.slack.com/methods/channels.setTopic -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelTopic(channelID, topic string) (string, error) { - return api.SetChannelTopicContext(context.Background(), channelID, topic) -} - -// SetChannelTopicContext sets the channel topic and returns the topic that was successfully set with a custom context -// see https://api.slack.com/methods/channels.setTopic -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetChannelTopicContext(ctx context.Context, channelID, topic string) (string, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "topic": {topic}, - } - - response, err := api.channelRequest(ctx, "channels.setTopic", values) - if err != nil { - return "", err - } - return response.Topic, nil -} - -// GetChannelReplies gets an entire thread (a message plus all the messages in reply to it). -// see https://api.slack.com/methods/channels.replies -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelReplies(channelID, thread_ts string) ([]Message, error) { - return api.GetChannelRepliesContext(context.Background(), channelID, thread_ts) -} - -// GetChannelRepliesContext gets an entire thread (a message plus all the messages in reply to it) with a custom context -// see https://api.slack.com/methods/channels.replies -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetChannelRepliesContext(ctx context.Context, channelID, thread_ts string) ([]Message, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "thread_ts": {thread_ts}, - } - response, err := api.channelRequest(ctx, "channels.replies", values) - if err != nil { - return nil, err - } - return response.History.Messages, nil -} diff --git a/examples/channels/channels.go b/examples/channels/channels.go deleted file mode 100644 index b41c57495..000000000 --- a/examples/channels/channels.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/slack-go/slack" -) - -func main() { - api := slack.New("YOUR_TOKEN_HERE") - channels, err := api.GetChannels(false) - if err != nil { - fmt.Printf("%s\n", err) - return - } - for _, channel := range channels { - fmt.Println(channel.Name) - // channel is of type conversation & groupConversation - // see all available methods in `conversation.go` - } -} diff --git a/examples/groups/groups.go b/examples/groups/groups.go deleted file mode 100644 index ed05a6a48..000000000 --- a/examples/groups/groups.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/slack-go/slack" -) - -func main() { - api := slack.New("YOUR_TOKEN_HERE") - // If you set debugging, it will log all requests to the console - // Useful when encountering issues - // api.SetDebug(true) - groups, err := api.GetGroups(false) - if err != nil { - fmt.Printf("%s\n", err) - return - } - for _, group := range groups { - fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name) - } -} diff --git a/examples/ims/ims.go b/examples/ims/ims.go deleted file mode 100644 index 363f06f44..000000000 --- a/examples/ims/ims.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/slack-go/slack" -) - -func main() { - api := slack.New("YOUR_TOKEN_HERE") - - userID := "USER_ID" - - _, _, channelID, err := api.OpenIMChannel(userID) - - if err != nil { - fmt.Printf("%s\n", err) - } - - api.PostMessage(channelID, slack.MsgOptionText("Hello World!", false)) -} diff --git a/groups.go b/groups.go index 4c5793dc3..b77f909db 100644 --- a/groups.go +++ b/groups.go @@ -1,574 +1,7 @@ package slack -import ( - "context" - "net/url" - "strconv" -) - // Group contains all the information for a group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api type Group struct { GroupConversation IsGroup bool `json:"is_group"` } - -type groupResponseFull struct { - Group Group `json:"group"` - Groups []Group `json:"groups"` - Purpose string `json:"purpose"` - Topic string `json:"topic"` - NotInGroup bool `json:"not_in_group"` - NoOp bool `json:"no_op"` - AlreadyClosed bool `json:"already_closed"` - AlreadyOpen bool `json:"already_open"` - AlreadyInGroup bool `json:"already_in_group"` - Channel Channel `json:"channel"` - History - SlackResponse -} - -func (api *Client) groupRequest(ctx context.Context, path string, values url.Values) (*groupResponseFull, error) { - response := &groupResponseFull{} - err := api.postMethod(ctx, path, values, response) - if err != nil { - return nil, err - } - - return response, response.Err() -} - -// ArchiveGroup archives a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) ArchiveGroup(group string) error { - return api.ArchiveGroupContext(context.Background(), group) -} - -// ArchiveGroupContext archives a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) ArchiveGroupContext(ctx context.Context, group string) error { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - - _, err := api.groupRequest(ctx, "groups.archive", values) - return err -} - -// UnarchiveGroup unarchives a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) UnarchiveGroup(group string) error { - return api.UnarchiveGroupContext(context.Background(), group) -} - -// UnarchiveGroupContext unarchives a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) UnarchiveGroupContext(ctx context.Context, group string) error { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - - _, err := api.groupRequest(ctx, "groups.unarchive", values) - return err -} - -// CreateGroup creates a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateGroup(group string) (*Group, error) { - return api.CreateGroupContext(context.Background(), group) -} - -// CreateGroupContext creates a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateGroupContext(ctx context.Context, group string) (*Group, error) { - values := url.Values{ - "token": {api.token}, - "name": {group}, - } - - response, err := api.groupRequest(ctx, "groups.create", values) - if err != nil { - return nil, err - } - return &response.Group, nil -} - -// CreateChildGroup creates a new private group archiving the old one -// This method takes an existing private group and performs the following steps: -// 1. Renames the existing group (from "example" to "example-archived"). -// 2. Archives the existing group. -// 3. Creates a new group with the name of the existing group. -// 4. Adds all members of the existing group to the new group. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateChildGroup(group string) (*Group, error) { - return api.CreateChildGroupContext(context.Background(), group) -} - -// CreateChildGroupContext creates a new private group archiving the old one with a custom context -// For more information see CreateChildGroup -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CreateChildGroupContext(ctx context.Context, group string) (*Group, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - - response, err := api.groupRequest(ctx, "groups.createChild", values) - if err != nil { - return nil, err - } - return &response.Group, nil -} - -// GetGroupHistory fetches all the history for a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupHistory(group string, params HistoryParameters) (*History, error) { - return api.GetGroupHistoryContext(context.Background(), group, params) -} - -// GetGroupHistoryContext fetches all the history for a private group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupHistoryContext(ctx context.Context, group string, params HistoryParameters) (*History, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - if params.Latest != DEFAULT_HISTORY_LATEST { - values.Add("latest", params.Latest) - } - if params.Oldest != DEFAULT_HISTORY_OLDEST { - values.Add("oldest", params.Oldest) - } - if params.Count != DEFAULT_HISTORY_COUNT { - values.Add("count", strconv.Itoa(params.Count)) - } - if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { - if params.Inclusive { - values.Add("inclusive", "1") - } else { - values.Add("inclusive", "0") - } - } - if params.Unreads != DEFAULT_HISTORY_UNREADS { - if params.Unreads { - values.Add("unreads", "1") - } else { - values.Add("unreads", "0") - } - } - - response, err := api.groupRequest(ctx, "groups.history", values) - if err != nil { - return nil, err - } - return &response.History, nil -} - -// InviteUserToGroup invites a specific user to a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) InviteUserToGroup(group, user string) (*Group, bool, error) { - return api.InviteUserToGroupContext(context.Background(), group, user) -} - -// InviteUserToGroupContext invites a specific user to a private group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) InviteUserToGroupContext(ctx context.Context, group, user string) (*Group, bool, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "user": {user}, - } - - response, err := api.groupRequest(ctx, "groups.invite", values) - if err != nil { - return nil, false, err - } - return &response.Group, response.AlreadyInGroup, nil -} - -// LeaveGroup makes authenticated user leave the group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) LeaveGroup(group string) error { - return api.LeaveGroupContext(context.Background(), group) -} - -// LeaveGroupContext makes authenticated user leave the group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) LeaveGroupContext(ctx context.Context, group string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - - _, err = api.groupRequest(ctx, "groups.leave", values) - return err -} - -// KickUserFromGroup kicks a user from a group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) KickUserFromGroup(group, user string) error { - return api.KickUserFromGroupContext(context.Background(), group, user) -} - -// KickUserFromGroupContext kicks a user from a group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) KickUserFromGroupContext(ctx context.Context, group, user string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "user": {user}, - } - - _, err = api.groupRequest(ctx, "groups.kick", values) - return err -} - -// GetGroups retrieves all groups -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroups(excludeArchived bool) ([]Group, error) { - return api.GetGroupsContext(context.Background(), excludeArchived) -} - -// GetGroupsContext retrieves all groups with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupsContext(ctx context.Context, excludeArchived bool) ([]Group, error) { - values := url.Values{ - "token": {api.token}, - } - if excludeArchived { - values.Add("exclude_archived", "1") - } - - response, err := api.groupRequest(ctx, "groups.list", values) - if err != nil { - return nil, err - } - return response.Groups, nil -} - -// GetGroupInfo retrieves the given group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupInfo(group string) (*Group, error) { - return api.GetGroupInfoContext(context.Background(), group) -} - -// GetGroupInfoContext retrieves the given group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupInfoContext(ctx context.Context, group string) (*Group, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "include_locale": {strconv.FormatBool(true)}, - } - - response, err := api.groupRequest(ctx, "groups.info", values) - if err != nil { - return nil, err - } - return &response.Group, nil -} - -// SetGroupReadMark sets the read mark on a private group -// Clients should try to avoid making this call too often. When needing to mark a read position, a client should set a -// timer before making the call. In this way, any further updates needed during the timeout will not generate extra -// calls (just one per channel). This is useful for when reading scroll-back history, or following a busy live -// channel. A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupReadMark(group, ts string) error { - return api.SetGroupReadMarkContext(context.Background(), group, ts) -} - -// SetGroupReadMarkContext sets the read mark on a private group with a custom context -// For more details see SetGroupReadMark -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupReadMarkContext(ctx context.Context, group, ts string) (err error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "ts": {ts}, - } - - _, err = api.groupRequest(ctx, "groups.mark", values) - return err -} - -// OpenGroup opens a private group -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) OpenGroup(group string) (bool, bool, error) { - return api.OpenGroupContext(context.Background(), group) -} - -// OpenGroupContext opens a private group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) OpenGroupContext(ctx context.Context, group string) (bool, bool, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - } - - response, err := api.groupRequest(ctx, "groups.open", values) - if err != nil { - return false, false, err - } - return response.NoOp, response.AlreadyOpen, nil -} - -// RenameGroup renames a group -// XXX: They return a channel, not a group. What is this crap? :( -// Inconsistent api it seems. -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) RenameGroup(group, name string) (*Channel, error) { - return api.RenameGroupContext(context.Background(), group, name) -} - -// RenameGroupContext renames a group with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) RenameGroupContext(ctx context.Context, group, name string) (*Channel, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "name": {name}, - } - - // XXX: the created entry in this call returns a string instead of a number - // so I may have to do some workaround to solve it. - response, err := api.groupRequest(ctx, "groups.rename", values) - if err != nil { - return nil, err - } - return &response.Channel, nil -} - -// SetGroupPurpose sets the group purpose -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupPurpose(group, purpose string) (string, error) { - return api.SetGroupPurposeContext(context.Background(), group, purpose) -} - -// SetGroupPurposeContext sets the group purpose with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupPurposeContext(ctx context.Context, group, purpose string) (string, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "purpose": {purpose}, - } - - response, err := api.groupRequest(ctx, "groups.setPurpose", values) - if err != nil { - return "", err - } - return response.Purpose, nil -} - -// SetGroupTopic sets the group topic -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupTopic(group, topic string) (string, error) { - return api.SetGroupTopicContext(context.Background(), group, topic) -} - -// SetGroupTopicContext sets the group topic with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) SetGroupTopicContext(ctx context.Context, group, topic string) (string, error) { - values := url.Values{ - "token": {api.token}, - "channel": {group}, - "topic": {topic}, - } - - response, err := api.groupRequest(ctx, "groups.setTopic", values) - if err != nil { - return "", err - } - return response.Topic, nil -} - -// GetGroupReplies gets an entire thread (a message plus all the messages in reply to it). -// see https://api.slack.com/methods/groups.replies -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupReplies(channelID, thread_ts string) ([]Message, error) { - return api.GetGroupRepliesContext(context.Background(), channelID, thread_ts) -} - -// GetGroupRepliesContext gets an entire thread (a message plus all the messages in reply to it) with a custom context -// see https://api.slack.com/methods/groups.replies -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetGroupRepliesContext(ctx context.Context, channelID, thread_ts string) ([]Message, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channelID}, - "thread_ts": {thread_ts}, - } - response, err := api.groupRequest(ctx, "groups.replies", values) - if err != nil { - return nil, err - } - return response.History.Messages, nil -} diff --git a/im.go b/im.go index a884b2953..7c4bc2572 100644 --- a/im.go +++ b/im.go @@ -1,11 +1,5 @@ package slack -import ( - "context" - "net/url" - "strconv" -) - type imChannel struct { ID string `json:"id"` } @@ -21,200 +15,7 @@ type imResponseFull struct { } // IM contains information related to the Direct Message channel -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api type IM struct { Conversation IsUserDeleted bool `json:"is_user_deleted"` } - -func (api *Client) imRequest(ctx context.Context, path string, values url.Values) (*imResponseFull, error) { - response := &imResponseFull{} - err := api.postMethod(ctx, path, values, response) - if err != nil { - return nil, err - } - - return response, response.Err() -} - -// CloseIMChannel closes the direct message channel -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CloseIMChannel(channel string) (bool, bool, error) { - return api.CloseIMChannelContext(context.Background(), channel) -} - -// CloseIMChannelContext closes the direct message channel with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) CloseIMChannelContext(ctx context.Context, channel string) (bool, bool, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channel}, - } - - response, err := api.imRequest(ctx, "im.close", values) - if err != nil { - return false, false, err - } - return response.NoOp, response.AlreadyClosed, nil -} - -// OpenIMChannel opens a direct message channel to the user provided as argument -// Returns some status and the channel ID -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) OpenIMChannel(user string) (bool, bool, string, error) { - return api.OpenIMChannelContext(context.Background(), user) -} - -// OpenIMChannelContext opens a direct message channel to the user provided as argument with a custom context -// Returns some status and the channel ID -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) OpenIMChannelContext(ctx context.Context, user string) (bool, bool, string, error) { - values := url.Values{ - "token": {api.token}, - "user": {user}, - } - - response, err := api.imRequest(ctx, "im.open", values) - if err != nil { - return false, false, "", err - } - return response.NoOp, response.AlreadyOpen, response.Channel.ID, nil -} - -// MarkIMChannel sets the read mark of a direct message channel to a specific point -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) MarkIMChannel(channel, ts string) (err error) { - return api.MarkIMChannelContext(context.Background(), channel, ts) -} - -// MarkIMChannelContext sets the read mark of a direct message channel to a specific point with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) MarkIMChannelContext(ctx context.Context, channel, ts string) error { - values := url.Values{ - "token": {api.token}, - "channel": {channel}, - "ts": {ts}, - } - - _, err := api.imRequest(ctx, "im.mark", values) - return err -} - -// GetIMHistory retrieves the direct message channel history -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetIMHistory(channel string, params HistoryParameters) (*History, error) { - return api.GetIMHistoryContext(context.Background(), channel, params) -} - -// GetIMHistoryContext retrieves the direct message channel history with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetIMHistoryContext(ctx context.Context, channel string, params HistoryParameters) (*History, error) { - values := url.Values{ - "token": {api.token}, - "channel": {channel}, - } - if params.Latest != DEFAULT_HISTORY_LATEST { - values.Add("latest", params.Latest) - } - if params.Oldest != DEFAULT_HISTORY_OLDEST { - values.Add("oldest", params.Oldest) - } - if params.Count != DEFAULT_HISTORY_COUNT { - values.Add("count", strconv.Itoa(params.Count)) - } - if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { - if params.Inclusive { - values.Add("inclusive", "1") - } else { - values.Add("inclusive", "0") - } - } - if params.Unreads != DEFAULT_HISTORY_UNREADS { - if params.Unreads { - values.Add("unreads", "1") - } else { - values.Add("unreads", "0") - } - } - - response, err := api.imRequest(ctx, "im.history", values) - if err != nil { - return nil, err - } - return &response.History, nil -} - -// GetIMChannels returns the list of direct message channels -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetIMChannels() ([]IM, error) { - return api.GetIMChannelsContext(context.Background()) -} - -// GetIMChannelsContext returns the list of direct message channels with a custom context -// -// Deprecated: channels.*, groups.* im.* and mpim.* methods will be deprecated in the next version. -// In Slack, these API are no longer available for newly Apps created after June 10th, 2020. -// Also, existing applications will not be able to use these APIs after February 24th, 2021. -// -// See also: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api -func (api *Client) GetIMChannelsContext(ctx context.Context) ([]IM, error) { - values := url.Values{ - "token": {api.token}, - } - - response, err := api.imRequest(ctx, "im.list", values) - if err != nil { - return nil, err - } - return response.IMs, nil -} diff --git a/slacktest/handlers.go b/slacktest/handlers.go index 85eec5804..5638838c9 100644 --- a/slacktest/handlers.go +++ b/slacktest/handlers.go @@ -82,11 +82,6 @@ func (sts *Server) conversationsInfoHandler(w http.ResponseWriter, r *http.Reque _, _ = w.Write(encoded) } -// handle channels.list and conversations.list -func listChannelsHandler(w http.ResponseWriter, _ *http.Request) { - _, _ = w.Write([]byte(defaultChannelsListJSON)) -} - // handle conversations.create func createConversationHandler(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(defaultConversationJSON)) @@ -112,11 +107,6 @@ func inviteConversationHandler(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(inviteConversationJSON)) } -// handle groups.list -func listGroupsHandler(w http.ResponseWriter, _ *http.Request) { - _, _ = w.Write([]byte(defaultGroupsListJSON)) -} - // handle chat.postMessage func (sts *Server) postMessageHandler(w http.ResponseWriter, r *http.Request) { serverAddr := r.Context().Value(ServerBotHubNameContextKey).(string) diff --git a/slacktest/handlers_test.go b/slacktest/handlers_test.go index b3ef5fefd..9ad35f754 100644 --- a/slacktest/handlers_test.go +++ b/slacktest/handlers_test.go @@ -31,21 +31,6 @@ func TestPostMessageHandler(t *testing.T) { assert.NotEmpty(t, tstamp, "timestamp should not be empty") } -func TestServerListChannels(t *testing.T) { - s := NewTestServer() - go s.Start() - - client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) - channels, err := client.GetChannels(true) - assert.NoError(t, err) - assert.Len(t, channels, 2) - assert.Equal(t, "C024BE91L", channels[0].ID) - assert.Equal(t, "C024BE92L", channels[1].ID) - for _, channel := range channels { - assert.Equal(t, "W012A3CDE", channel.Creator) - } -} - func TestServerCreateConversationHandler(t *testing.T) { s := NewTestServer() go s.Start() @@ -137,41 +122,3 @@ func TestBotInfoHandler(t *testing.T) { assert.Equal(t, s.BotName, bot.Name) assert.False(t, bot.Deleted) } - -func TestListGroupsHandler(t *testing.T) { - s := NewTestServer() - go s.Start() - - client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) - groups, err := client.GetGroups(true) - assert.NoError(t, err) - if !assert.Len(t, groups, 1, "should have one group") { - t.FailNow() - } - mygroup := groups[0] - assert.Equal(t, "G024BE91L", mygroup.ID, "id should match") - assert.Equal(t, "secretplans", mygroup.Name, "name should match") - assert.True(t, mygroup.IsGroup, "should be a group") -} - -func TestListChannelsHandler(t *testing.T) { - s := NewTestServer() - go s.Start() - - client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) - channels, err := client.GetChannels(true) - assert.NoError(t, err) - if !assert.Len(t, channels, 2, "should have two channels") { - t.FailNow() - } - generalChan := channels[0] - otherChan := channels[1] - assert.Equal(t, "C024BE91L", generalChan.ID, "id should match") - assert.Equal(t, "general", generalChan.Name, "name should match") - assert.Equal(t, "Fun times", generalChan.Topic.Value) - assert.True(t, generalChan.IsMember, "should be in channel") - assert.Equal(t, "C024BE92L", otherChan.ID, "id should match") - assert.Equal(t, "bot-playground", otherChan.Name, "name should match") - assert.Equal(t, "Fun times", otherChan.Topic.Value) - assert.True(t, otherChan.IsMember, "should be in channel") -} diff --git a/slacktest/server.go b/slacktest/server.go index aae24995d..aa6c0a180 100644 --- a/slacktest/server.go +++ b/slacktest/server.go @@ -50,14 +50,11 @@ func NewTestServer(custom ...binder) *Server { s.Handle("/rtm.start", rtmStartHandler) s.Handle("/rtm.connect", RTMConnectHandler) s.Handle("/chat.postMessage", s.postMessageHandler) - s.Handle("/channels.list", listChannelsHandler) - s.Handle("/conversations.list", listChannelsHandler) s.Handle("/conversations.create", createConversationHandler) s.Handle("/conversations.setTopic", setConversationTopicHandler) s.Handle("/conversations.setPurpose", setConversationPurposeHandler) s.Handle("/conversations.rename", renameConversationHandler) s.Handle("/conversations.invite", inviteConversationHandler) - s.Handle("/groups.list", listGroupsHandler) s.Handle("/users.info", usersInfoHandler) s.Handle("/users.lookupByEmail", usersInfoHandler) s.Handle("/bots.info", botsInfoHandler)