Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for external_limited option of inviteShared #1330

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,42 +329,71 @@ func (api *Client) InviteUsersToConversationContext(ctx context.Context, channel
}

// InviteSharedEmailsToConversation invites users to a shared channels by email.
// For more details, see InviteSharedEmailsToConversationContext documentation.
// For more details, see InviteSharedToConversationContext documentation.
func (api *Client) InviteSharedEmailsToConversation(channelID string, emails ...string) (string, bool, error) {
return api.inviteSharedToConversationHelper(context.Background(), channelID, emails, nil)
return api.InviteSharedToConversationContext(context.Background(), InviteSharedToConversationParams{
ChannelID: channelID,
Emails: emails,
})
}

// InviteSharedEmailsToConversationContext invites users to a shared channels by email using context.
// For more details, see inviteSharedToConversationHelper documentation.
// For more details, see InviteSharedToConversationContext documentation.
func (api *Client) InviteSharedEmailsToConversationContext(ctx context.Context, channelID string, emails ...string) (string, bool, error) {
return api.inviteSharedToConversationHelper(ctx, channelID, emails, nil)
return api.InviteSharedToConversationContext(ctx, InviteSharedToConversationParams{
ChannelID: channelID,
Emails: emails,
})
}

// InviteSharedUserIDsToConversation invites users to a shared channels by user id.
// For more details, see InviteSharedUserIDsToConversationContext documentation.
// For more details, see InviteSharedToConversationContext documentation.
func (api *Client) InviteSharedUserIDsToConversation(channelID string, userIDs ...string) (string, bool, error) {
return api.inviteSharedToConversationHelper(context.Background(), channelID, nil, userIDs)
return api.InviteSharedToConversationContext(context.Background(), InviteSharedToConversationParams{
ChannelID: channelID,
UserIDs: userIDs,
})
}

// InviteSharedUserIDsToConversationContext invites users to a shared channels by user id with context.
// For more details, see inviteSharedToConversationHelper documentation.
// For more details, see InviteSharedToConversationContext documentation.
func (api *Client) InviteSharedUserIDsToConversationContext(ctx context.Context, channelID string, userIDs ...string) (string, bool, error) {
return api.inviteSharedToConversationHelper(ctx, channelID, nil, userIDs)
return api.InviteSharedToConversationContext(ctx, InviteSharedToConversationParams{
ChannelID: channelID,
UserIDs: userIDs,
})
}

// inviteSharedToConversationHelper invites emails or userIDs to a channel with a custom context.
// InviteSharedToConversationParams defines the parameters for the InviteSharedToConversation and InviteSharedToConversationContext functions.
type InviteSharedToConversationParams struct {
ChannelID string
Emails []string
UserIDs []string
ExternalLimited *bool
}

// InviteSharedToConversation invites emails or userIDs to a channel.
// For more details, see InviteSharedToConversationContext documentation.
func (api *Client) InviteSharedToConversation(params InviteSharedToConversationParams) (string, bool, error) {
return api.InviteSharedToConversationContext(context.Background(), params)
}

// InviteSharedToConversationContext invites emails or userIDs to a channel with a custom context.
// This is a helper function for InviteSharedEmailsToConversation and InviteSharedUserIDsToConversation.
// It accepts either emails or userIDs, but not both.
// Slack API docs: https://api.slack.com/methods/conversations.inviteShared
func (api *Client) inviteSharedToConversationHelper(ctx context.Context, channelID string, emails []string, userIDs []string) (string, bool, error) {
func (api *Client) InviteSharedToConversationContext(ctx context.Context, params InviteSharedToConversationParams) (string, bool, error) {
values := url.Values{
"token": {api.token},
"channel": {channelID},
"channel": {params.ChannelID},
}
if len(params.Emails) > 0 {
values.Add("emails", strings.Join(params.Emails, ","))
} else if len(params.UserIDs) > 0 {
values.Add("user_ids", strings.Join(params.UserIDs, ","))
}
if len(emails) > 0 {
values.Add("emails", strings.Join(emails, ","))
} else if len(userIDs) > 0 {
values.Add("user_ids", strings.Join(userIDs, ","))
if params.ExternalLimited != nil {
values.Add("external_limited", strconv.FormatBool(*params.ExternalLimited))
}
response := struct {
SlackResponse
Expand Down
21 changes: 21 additions & 0 deletions conversation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,27 @@ func TestInviteSharedToConversation(t *testing.T) {
t.Error("is legacy shared channel should be false")
}
})

t.Run("external_limited", func(t *testing.T) {
userIDs := []string{"UXXXXXXX1", "UXXXXXXX2"}
externalLimited := true
inviteID, isLegacySharedChannel, err := api.InviteSharedToConversation(InviteSharedToConversationParams{
ChannelID: "CXXXXXXXX",
UserIDs: userIDs,
ExternalLimited: &externalLimited,
})
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
if inviteID == "" {
t.Error("invite id should have a value")
return
}
if isLegacySharedChannel {
t.Error("is legacy shared channel should be false")
}
})
}

func TestKickUserFromConversation(t *testing.T) {
Expand Down