Repository: slack-go/slack
Pull request #1300 (2024-07-14 06:00:53)

chore: Adding Deprecation Notice for files.upload
This pull request adds a deprecation notice for files.upload and addresses #1287.

> files.upload is deprecated and will stop functioning on March 11, 2025. Use [files.getUploadURLExternal](https://api.slack.com/methods/files.getUploadURLExternal) and [files.completeUploadExternal](https://api.slack.com/methods/files.completeUploadExternal) to upload files instead. Newly created apps will be unable to use files.upload beginning May 8, 2024. See [Uploading files](https://api.slack.com/messaging/files#uploading_files) for more details on the process and [this changelog](https://api.slack.com/changelog/2024-04-a-better-way-to-upload-files-is-here-to-stay) for more on the deprecation.

Reference: https://api.slack.com/methods/files.upload#markdown


Patch:
diff --git a/conversation.go b/conversation.go
index 787a961..5552375 100644
--- a/conversation.go
+++ b/conversation.go
@@ -25,6 +25,7 @@ type Conversation struct {
 	IsGlobalShared     bool     `json:"is_global_shared"`
 	IsPendingExtShared bool     `json:"is_pending_ext_shared"`
 	IsPrivate          bool     `json:"is_private"`
+	IsReadOnly         bool     `json:"is_read_only"`
 	IsMpIM             bool     `json:"is_mpim"`
 	Unlinked           int      `json:"unlinked"`
 	NameNormalized     string   `json:"name_normalized"`
diff --git a/files.go b/files.go
index 40a5d16..eae8407 100644
--- a/files.go
+++ b/files.go
@@ -351,12 +351,16 @@ func (api *Client) ListFilesContext(ctx context.Context, params ListFilesParamet
 	return response.Files, &params, nil
 }
 
-// UploadFile uploads a file
+// UploadFile uploads a file.
+// DEPRECATED: Use UploadFileV2 instead. This will stop functioning on March 11, 2025.
+// For more details, see: https://api.slack.com/methods/files.upload#markdown
 func (api *Client) UploadFile(params FileUploadParameters) (file *File, err error) {
 	return api.UploadFileContext(context.Background(), params)
 }
 
-// UploadFileContext uploads a file and setting a custom context
+// UploadFileContext uploads a file and setting a custom context.
+// DEPRECATED: Use UploadFileV2Context instead. This will stop functioning on March 11, 2025.
+// For more details, see: https://api.slack.com/methods/files.upload#markdown
 func (api *Client) UploadFileContext(ctx context.Context, params FileUploadParameters) (file *File, err error) {
 	// Test if user token is valid. This helps because client.Do doesn't like this for some reason. XXX: More
 	// investigation needed, but for now this will do.
@@ -522,11 +526,13 @@ func (api *Client) completeUploadExternal(ctx context.Context, fileID string, pa
 		return nil, err
 	}
 	values := url.Values{
-		"token":      {api.token},
-		"files":      {string(requestBytes)},
-		"channel_id": {params.channel},
+		"token": {api.token},
+		"files": {string(requestBytes)},
 	}
 
+	if params.channel != "" {
+		values.Add("channel_id", params.channel)
+	}
 	if params.initialComment != "" {
 		values.Add("initial_comment", params.initialComment)
 	}
@@ -555,7 +561,7 @@ func (api *Client) UploadFileV2(params UploadFileV2Parameters) (*FileSummary, er
 // UploadFileV2 uploads file to a given slack channel using 3 steps with a custom context -
 //  1. Get an upload URL using files.getUploadURLExternal API
 //  2. Send the file as a post to the URL provided by slack
-//  3. Complete the upload and share it to the specified channel using files.completeUploadExternal
+//  3. Complete the upload and if a channel is specified, post it to the specified channel using files.completeUploadExternal
 func (api *Client) UploadFileV2Context(ctx context.Context, params UploadFileV2Parameters) (file *FileSummary, err error) {
 	if params.Filename == "" {
 		return nil, fmt.Errorf("file.upload.v2: filename cannot be empty")
@@ -563,9 +569,7 @@ func (api *Client) UploadFileV2Context(ctx context.Context, params UploadFileV2P
 	if params.FileSize == 0 {
 		return nil, fmt.Errorf("file.upload.v2: file size cannot be 0")
 	}
-	if params.Channel == "" {
-		return nil, fmt.Errorf("file.upload.v2: channel cannot be empty")
-	}
+
 	u, err := api.getUploadURLExternal(ctx, getUploadURLExternalParameters{
 		altText:     params.AltTxt,
 		fileName:    params.Filename,
diff --git a/reminders.go b/reminders.go
index 53d67c0..5543a15 100644
--- a/reminders.go
+++ b/reminders.go
@@ -41,10 +41,7 @@ func (api *Client) doReminders(ctx context.Context, path string, values url.Valu
 
 	// create an array of pointers to reminders
 	var reminders = make([]*Reminder, 0, len(response.Reminders))
-	for _, reminder := range response.Reminders {
-		reminders = append(reminders, reminder)
-	}
-
+	reminders = append(reminders, response.Reminders...)
 	return reminders, response.Err()
 }
 
diff --git a/webhooks.go b/webhooks.go
index e323353..8fc149d 100644
--- a/webhooks.go
+++ b/webhooks.go
@@ -24,6 +24,8 @@ type WebhookMessage struct {
 	ReplaceOriginal bool         `json:"replace_original"`
 	DeleteOriginal  bool         `json:"delete_original"`
 	ReplyBroadcast  bool         `json:"reply_broadcast,omitempty"`
+	UnfurlLinks     bool         `json:"unfurl_links,omitempty"`
+	UnfurlMedia     bool         `json:"unfurl_media,omitempty"`
 }
 
 func PostWebhook(url string, msg *WebhookMessage) error {


Test patch:
diff --git a/files_test.go b/files_test.go
index f304a4e..59afc1c 100644
--- a/files_test.go
+++ b/files_test.go
@@ -272,4 +272,13 @@ func TestUploadFileV2(t *testing.T) {
 	if _, err := api.UploadFileV2(params); err != nil {
 		t.Errorf("Unexpected error: %s", err)
 	}
+
+	reader = bytes.NewBufferString("test no channel")
+	params = UploadFileV2Parameters{
+		Filename: "test.txt",
+		Reader:   reader,
+		FileSize: 15}
+	if _, err := api.UploadFileV2(params); err != nil {
+		t.Errorf("Unexpected error: %s", err)
+	}
 }