From 042c1ee65c2f4739fdb4d6c9292435b890787580 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 1 Mar 2025 22:20:49 +0100 Subject: [PATCH] Uniq results --- services/connectors/slack.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services/connectors/slack.go b/services/connectors/slack.go index 73cf741..2e87ac5 100644 --- a/services/connectors/slack.go +++ b/services/connectors/slack.go @@ -56,11 +56,23 @@ func cleanUpUsernameFromMessage(message string, b *slack.AuthTestResponse) strin return cleaned } +func uniqueStringSlice(s []string) []string { + keys := make(map[string]bool) + list := []string{} + for _, entry := range s { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +} + func generateAttachmentsFromJobResponse(j *agent.JobResult) (attachments []slack.Attachment) { for _, state := range j.State { // coming from the search action if urls, exists := state.Metadata[actions.MetadataUrls]; exists { - for _, url := range urls.([]string) { + for _, url := range uniqueStringSlice(urls.([]string)) { attachment := slack.Attachment{ Title: "URL", TitleLink: url, @@ -72,7 +84,7 @@ func generateAttachmentsFromJobResponse(j *agent.JobResult) (attachments []slack // coming from the gen image actions if imagesUrls, exists := state.Metadata[actions.MetadataImages]; exists { - for _, url := range imagesUrls.([]string) { + for _, url := range uniqueStringSlice(imagesUrls.([]string)) { attachment := slack.Attachment{ Title: "Image", TitleLink: url,