I am making a file upload bot for slack . Since fileUpload got depreciated , i was using 3 step process of getting the external URL , uploading that URL and then completing that file upload.
Error recieved is
./main.go:62:19: api.GetFilesUploadURLExternal undefined (type *slack.Client has no field or method GetFilesUploadURLExternal)
./main.go:62:57: undefined: slack.GetFilesUploadURLExternalParams
./main.go:116:16: api.CompleteFilesUploadExternal undefined (type *slack.Client has no field or method CompleteFilesUploadExternal)
./main.go:116:56: undefined: slack.CompleteFilesUploadExternalParams
I am getting error in the following functions(error red line is coming under bold line):
func getUploadURL(ctx context.Context, api *slack.Client, filePath string) (string, string, error) {
fileInfo, err := os.Stat(filePath)
if err != nil {
return "", "", fmt.Errorf("error getting file info: %w", err)
}
resp, err := api.**GetFilesUploadURLExternal**(ctx, &slack.**GetFilesUploadURLExternalParams**{
Filename: filepath.Base(filePath),
Length: int(fileInfo.Size()),
})
if err != nil {
return "", "", fmt.Errorf("error getting upload URL: %w", err)
}
return resp.UploadURL, resp.FileID, nil
}
and
func completeUpload(ctx context.Context, api *slack.Client, fileID, channelID string) error {
_, err := api.**CompleteFilesUploadExternal**(ctx, &slack.**CompleteFilesUploadExternalParams**{
Files: []slack.FileSummary{
{ID: fileID},
},
ChannelID: channelID,
})
if err != nil {
return fmt.Errorf("error completing upload: %w", err)
}
return nil
}
also , main function is
func main() {
api := slack.New("TOKEN_BOT")
ctx := context.Background()
filePath := "example.pdf"
channelID := "CHANNELID"
// Step 1: Get upload URL
uploadURL, fileID, err := getUploadURL(ctx, api, filePath)
if err != nil {
fmt.Printf("Error getting upload URL: %vn", err)
return
}
// Step 2: Upload file to URL
err = uploadFileToURL(uploadURL, filePath)
if err != nil {
fmt.Printf("Error uploading file: %vn", err)
return
}
// Step 3: Complete upload
err = completeUpload(ctx, api, fileID, channelID)
if err != nil {
fmt.Printf("Error completing upload: %vn", err)
return
}
fmt.Println("File uploaded successfully!")
}
i have also tried
api := &slack.Client{
token:"TOKEN_BOT",
}
O-auth permissions are :-
channel:read
chat:write
file:read
file:write
im:read
im:write
mpim:history
remote_files:read
remote:files:write
remote_files:share
I do not understand why is it being considered undefined , with it being part of the latest file?can anyone please help?
Ansh Malgotra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6