Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Added attachment file type check to CreateRequest
Jake Daynesa0fc868569bc
diff --git a/api/pkg/handlers/discord_handler.go b/api/pkg/handlers/discord_handler.goindex 95591c2b..d556dc45 100644--- a/api/pkg/handlers/discord_handler.go+++ b/api/pkg/handlers/discord_handler.go@@ -8,9 +8,11 @@ import ("encoding/json""fmt""os"+ "strings""github.com/google/uuid"+ "github.com/NdoleStudio/httpsms/pkg/entities""github.com/NdoleStudio/httpsms/pkg/repositories""github.com/NdoleStudio/httpsms/pkg/requests""github.com/NdoleStudio/httpsms/pkg/services"@@ -290,10 +292,42 @@ func (h *DiscordHandler) createRequest(payload map[string]any) requests.MessageS}return ""}+ var attachments []entities.MessageAttachment+ attachmentURLsStr := getOption("attachment_urls")++ if attachmentURLsStr != "" {+ urls := strings.Split(attachmentURLsStr, ",")+ for _, u := range urls {+ cleanURL := strings.TrimSpace(u)+ if cleanURL == "" {+ continue+ }++ // Same as with bulk CSV attachments, can't easily ask for the MIME type so+ // just inferring based on the file extension+ contentType := "application/octet-stream"+ lowerURL := strings.ToLower(cleanURL)+ if strings.HasSuffix(lowerURL, ".jpg") || strings.HasSuffix(lowerURL, ".jpeg") {+ contentType = "image/jpeg"+ } else if strings.HasSuffix(lowerURL, ".png") {+ contentType = "image/png"+ } else if strings.HasSuffix(lowerURL, ".gif") {+ contentType = "image/gif"+ } else if strings.HasSuffix(lowerURL, ".mp4") {+ contentType = "video/mp4"+ }++ attachments = append(attachments, entities.MessageAttachment{+ ContentType: contentType,+ URL: cleanURL,+ })+ }+ }return requests.MessageSend{- From: getOption("from"),- To: getOption("to"),- Content: getOption("message"),+ From: getOption("from"),+ To: getOption("to"),+ Content: getOption("message"),+ Attachments: attachments,}}