Skip to content

Commit

Permalink
conversation: support passing team id in CreateConversation
Browse files Browse the repository at this point in the history
This is a breaking change that hopefully future proofs this codepath
from future breaking changes, since adding additional params to the
struct should be backwards compatible.
  • Loading branch information
stephenwan-opal committed Oct 31, 2022
1 parent 7d4c987 commit d0de2c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions conversation.go
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion conversation_test.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/pins/pins.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion slacktest/handlers_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit d0de2c2

Please sign in to comment.