diff --git a/conversation.go b/conversation.go index e523716cc..6b0459a6b 100644 --- a/conversation.go +++ b/conversation.go @@ -337,17 +337,26 @@ func (api *Client) CloseConversationContext(ctx context.Context, channelID strin return response.NoOp, response.AlreadyClosed, response.Err() } +type CreateConversationParams struct { + ChannelName string + IsPrivate bool + TeamID string +} + // CreateConversation initiates a public or private channel-based conversation -func (api *Client) CreateConversation(channelName string, isPrivate bool) (*Channel, error) { - return api.CreateConversationContext(context.Background(), channelName, isPrivate) +func (api *Client) CreateConversation(params CreateConversationParams) (*Channel, error) { + return api.CreateConversationContext(context.Background(), params) } // CreateConversationContext initiates a public or private channel-based conversation with a custom context -func (api *Client) CreateConversationContext(ctx context.Context, channelName string, isPrivate bool) (*Channel, error) { +func (api *Client) CreateConversationContext(ctx context.Context, params CreateConversationParams) (*Channel, error) { values := url.Values{ "token": {api.token}, - "name": {channelName}, - "is_private": {strconv.FormatBool(isPrivate)}, + "name": {params.ChannelName}, + "is_private": {strconv.FormatBool(params.IsPrivate)}, + } + if params.TeamID != "" { + values.Set("team_id", params.TeamID) } response, err := api.channelRequest(ctx, "conversations.create", values) if err != nil { diff --git a/conversation_test.go b/conversation_test.go index 61a4e92b1..adbad7c28 100644 --- a/conversation_test.go +++ b/conversation_test.go @@ -385,7 +385,7 @@ func TestCreateConversation(t *testing.T) { http.HandleFunc("/conversations.create", okChannelJsonHandler) once.Do(startServer) api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/")) - channel, err := api.CreateConversation("CXXXXXXXX", false) + channel, err := api.CreateConversation(CreateConversationParams{ChannelName: "CXXXXXXXX"}) if err != nil { t.Errorf("Unexpected error: %s", err) return diff --git a/examples/pins/pins.go b/examples/pins/pins.go index d13d2d2c8..5c4f67c22 100644 --- a/examples/pins/pins.go +++ b/examples/pins/pins.go @@ -43,7 +43,7 @@ func main() { postAsUserID = authTest.UserID // Create a temporary channel - channel, err := api.CreateConversation(channelName, false) + channel, err := api.CreateConversation(slack.CreateConversationParams{ChannelName: channelName}) if err != nil { // If the channel exists, that means we just need to unarchive it diff --git a/slacktest/handlers_test.go b/slacktest/handlers_test.go index 6678e7684..dec4c99be 100644 --- a/slacktest/handlers_test.go +++ b/slacktest/handlers_test.go @@ -37,7 +37,7 @@ func TestServerCreateConversationHandler(t *testing.T) { go s.Start() client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL())) - conversation, err := client.CreateConversation("test", false) + conversation, err := client.CreateConversation(slack.CreateConversationParams{ChannelName: "test"}) assert.NoError(t, err) assert.Equal(t, "C0EAQDV4Z", conversation.ID) assert.Equal(t, "U023BECGF", conversation.Creator)