diff --git a/conversation.go b/conversation.go index 44f06ea93..0916898b6 100644 --- a/conversation.go +++ b/conversation.go @@ -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) +} diff --git a/conversation_test.go b/conversation_test.go index 85011d5a6..f5bba7720 100644 --- a/conversation_test.go +++ b/conversation_test.go @@ -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 + } +}