Skip to content

Commit

Permalink
Merge pull request #639 from innogames/change_upload_api
Browse files Browse the repository at this point in the history
use new slack file upload API
  • Loading branch information
brainexe authored Nov 28, 2024
2 parents 71e3aea + 36461e4 commit 4c7ceac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions client/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type SlackClient interface {
GetUserPresence(user string) (*slack.UserPresence, error)

// UploadFile uploads a file to Slack
UploadFile(params slack.FileUploadParameters) (*slack.File, error)
UploadFile(params slack.UploadFileV2Parameters) (*slack.FileSummary, error)

// PinMessage will pin a message to the channel
PinMessage(channel string, timestamp string) error
Expand Down Expand Up @@ -331,8 +331,8 @@ func (s *Slack) GetUserPresence(user string) (*slack.UserPresence, error) {
}

// UploadFile uploads a file to Slack
func (s *Slack) UploadFile(params slack.FileUploadParameters) (*slack.File, error) {
return s.Client.UploadFile(params)
func (s *Slack) UploadFile(params slack.UploadFileV2Parameters) (*slack.FileSummary, error) {
return s.Client.UploadFileV2(params)
}

// GetUserIDAndName returns the user-id and user-name based on a identifier. If can get a user-id or name
Expand Down
9 changes: 4 additions & 5 deletions command/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/csv"
"fmt"
"io"
"sort"
"time"

Expand Down Expand Up @@ -48,10 +47,10 @@ func (c *exportCommand) exportChannel(match matcher.Result, message msg.Message)
if lines >= limit {
c.SendMessage(message, fmt.Sprintf("Attention: The export is limited to %d messages.", limit))
}
_, err = c.UploadFile(slack.FileUploadParameters{
_, err = c.UploadFile(slack.UploadFileV2Parameters{
Filename: "export.csv",
Filetype: "csv",
Channels: []string{message.Channel},
FileSize: buffer.Len(),
Channel: message.Channel,
ThreadTimestamp: message.Timestamp,
Reader: buffer,
InitialComment: fmt.Sprintf("Export %d messages from channel <#%s|%s>", lines, channelID, channelName),
Expand Down Expand Up @@ -91,7 +90,7 @@ func getConversations(client client.SlackClient, channelID string) ([]slack.Mess
return messages, nil
}

func exportChannelMessagesToBuffer(client client.SlackClient, channelID string) (io.Reader, int, error) {
func exportChannelMessagesToBuffer(client client.SlackClient, channelID string) (*bytes.Buffer, int, error) {
buffer := new(bytes.Buffer)
messages, err := getConversations(client, channelID)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions command/openai/dalle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (c *openaiCommand) sendImageInSlack(image DalleResponseImage, message msg.M
}
defer resp.Body.Close()

_, err = c.SlackClient.UploadFile(slack.FileUploadParameters{
_, err = c.SlackClient.UploadFile(slack.UploadFileV2Parameters{
Filename: "dalle.png",
Filetype: "png",
Channels: []string{message.Channel},
ThreadTimestamp: message.Timestamp,
FileSize: int(resp.ContentLength),
Reader: resp.Body,
Channel: message.Channel,
ThreadTimestamp: message.Timestamp,
InitialComment: fmt.Sprintf("Dall-e prompt: %s", image.RevisedPrompt),
})

Expand Down
2 changes: 1 addition & 1 deletion command/openai/dalle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestDalle(t *testing.T) {

slackClient.On(
"UploadFile",
mock.MatchedBy(func(params slack.FileUploadParameters) bool {
mock.MatchedBy(func(params slack.UploadFileV2Parameters) bool {
assert.Equal(t, "dalle.png", params.Filename)
return true
}),
Expand Down
12 changes: 6 additions & 6 deletions mocks/SlackClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c7ceac

Please sign in to comment.