Isolate functions
This commit is contained in:
@@ -177,6 +177,39 @@ func generateAttachmentsFromJobResponse(j *types.JobResult) (attachments []slack
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scanImagesInMessages(api *slack.Client, ev *slackevents.MessageEvent) (*bytes.Buffer, string) {
|
||||||
|
imageBytes := new(bytes.Buffer)
|
||||||
|
mimeType := "image/jpeg"
|
||||||
|
|
||||||
|
// Fetch the message using the API
|
||||||
|
messages, _, _, err := api.GetConversationReplies(&slack.GetConversationRepliesParameters{
|
||||||
|
ChannelID: ev.Channel,
|
||||||
|
Timestamp: ev.TimeStamp,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
xlog.Error(fmt.Sprintf("Error fetching messages: %v", err))
|
||||||
|
} else {
|
||||||
|
for _, msg := range messages {
|
||||||
|
if len(msg.Files) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, attachment := range msg.Files {
|
||||||
|
if attachment.URLPrivate != "" {
|
||||||
|
xlog.Debug(fmt.Sprintf("Getting Attachment: %+v", attachment))
|
||||||
|
// download image with slack api
|
||||||
|
mimeType = attachment.Mimetype
|
||||||
|
if err := api.GetFile(attachment.URLPrivate, imageBytes); err != nil {
|
||||||
|
xlog.Error(fmt.Sprintf("Error downloading image: %v", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageBytes, mimeType
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Slack) handleChannelMessage(
|
func (t *Slack) handleChannelMessage(
|
||||||
a *agent.Agent,
|
a *agent.Agent,
|
||||||
api *slack.Client, ev *slackevents.MessageEvent, b *slack.AuthTestResponse, postMessageParams slack.PostMessageParameters) {
|
api *slack.Client, ev *slackevents.MessageEvent, b *slack.AuthTestResponse, postMessageParams slack.PostMessageParameters) {
|
||||||
@@ -197,34 +230,7 @@ func (t *Slack) handleChannelMessage(
|
|||||||
message := replaceUserIDsWithNamesInMessage(api, cleanUpUsernameFromMessage(ev.Text, b))
|
message := replaceUserIDsWithNamesInMessage(api, cleanUpUsernameFromMessage(ev.Text, b))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
imageBytes := new(bytes.Buffer)
|
imageBytes, mimeType := scanImagesInMessages(api, ev)
|
||||||
mimeType := "image/jpeg"
|
|
||||||
|
|
||||||
// Fetch the message using the API
|
|
||||||
messages, _, _, err := api.GetConversationReplies(&slack.GetConversationRepliesParameters{
|
|
||||||
ChannelID: ev.Channel,
|
|
||||||
Timestamp: ev.TimeStamp,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
xlog.Error(fmt.Sprintf("Error fetching messages: %v", err))
|
|
||||||
} else {
|
|
||||||
for _, msg := range messages {
|
|
||||||
if len(msg.Files) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, attachment := range msg.Files {
|
|
||||||
if attachment.URLPrivate != "" {
|
|
||||||
xlog.Debug(fmt.Sprintf("Getting Attachment: %+v", attachment))
|
|
||||||
// download image with slack api
|
|
||||||
mimeType = attachment.Mimetype
|
|
||||||
if err := api.GetFile(attachment.URLPrivate, imageBytes); err != nil {
|
|
||||||
xlog.Error(fmt.Sprintf("Error downloading image: %v", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
agentOptions := []types.JobOption{
|
agentOptions := []types.JobOption{
|
||||||
types.WithUUID(ev.ThreadTimeStamp),
|
types.WithUUID(ev.ThreadTimeStamp),
|
||||||
|
|||||||
Reference in New Issue
Block a user