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: implement conversations.inviteShared #1195

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions conversation.go
Expand Up @@ -690,3 +690,53 @@ func (api *Client) MarkConversationContext(ctx context.Context, channel, ts stri
}
return response.Err()
}

type InviteSharedParams struct {
// Emails are the emails to be invited to the Slack Connect
Emails []string
// ExternalLimited determines whether the invitee is an external limited member.
// External limited members cannot invite other cannot invite others, export channel history,
// change channel visibility, topic, or name, and the channel will be set as private in the guest workspace.
// Defaults to true
ExternalLimited *bool
// UserIDs are the Slack IDs to be invited to the Slack Connect
UserIDs []string
}

var InvalidSharedInviteParamsError = errors.New("one of Emails or UserIDs must be supplied to InviteSharedParams")

// InviteSharedContext sends array(s) of user IDs and/or emails an invitation to a Slack Connect channel with a custom context
// At least one array of either emails or user IDs must be supplied to invite the recipient
func (api *Client) InviteSharedContext(ctx context.Context, channelID string, params InviteSharedParams) error {
if len(params.UserIDs) < 1 && len(params.Emails) < 1 {
return InvalidSharedInviteParamsError
}

values := url.Values{
"channel": {channelID},
}
if params.Emails != nil {
values.Add("emails", strings.Join(params.Emails, ","))
}
// the externalLimited parameter defaults to true; ignore it unless it is explicitly false
if params.ExternalLimited != nil && !*params.ExternalLimited {
values.Add("external_limited", "false")
}
if params.UserIDs != nil {
values.Add("user_ids", strings.Join(params.Emails, ","))
}

response := &SlackResponse{}
err := api.getMethod(ctx, "conversations.inviteShared", api.token, values, &response)
if err != nil {
return err
}

return response.Err()
}

// InviteShared sends array(s) of user IDs and/or emails an invitation to a Slack Connect channel
// At least one array of either emails or user IDs must be supplied to invite the recipient
func (api *Client) InviteShared(channelID string, params InviteSharedParams) error {
return api.InviteSharedContext(context.Background(), channelID, params)
}
16 changes: 16 additions & 0 deletions conversation_test.go
Expand Up @@ -591,3 +591,19 @@ func TestMarkConversation(t *testing.T) {
return
}
}

func TestInviteShared(t *testing.T) {
http.HandleFunc("/conversations.inviteShared", okJSONHandler)
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
params := &InviteSharedParams{}
err := api.InviteShared("CXXXXXXXX", *params)
assert.EqualError(t, err, InvalidSharedInviteParamsError.Error())

params.Emails = []string{"fake@email.com", "another@email.com"}
err = api.InviteShared("CXXXXXXXX", *params)
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
}