Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Centralised the content type check into message entities file
Jake Daynesc4f7e185582a
diff --git a/api/pkg/entities/message.go b/api/pkg/entities/message.goindex eb71f51b..6f0f75e6 100644--- a/api/pkg/entities/message.go+++ b/api/pkg/entities/message.go@@ -1,6 +1,7 @@package entitiesimport (+ "strings""time""github.com/google/uuid"@@ -233,3 +234,19 @@ func (message *Message) updateOrderTimestamp(timestamp time.Time) {message.OrderTimestamp = timestamp}}++func GetAttachmentContentType(url string) string {+ // Since there's no easy way to set a type in the CSV, defaulting to octet-stream and then just checking the file extension in the URL+ contentType := "application/octet-stream"+ lowerURL := strings.ToLower(url)+ 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"+ }+ return contentType+}diff --git a/api/pkg/handlers/discord_handler.go b/api/pkg/handlers/discord_handler.goindex 7be60f3b..729c6ce6 100644--- a/api/pkg/handlers/discord_handler.go+++ b/api/pkg/handlers/discord_handler.go@@ -303,19 +303,7 @@ func (h *DiscordHandler) createRequest(payload map[string]any) requests.MessageScontinue}- // 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"- }+ contentType := entities.GetAttachmentContentType(cleanURL)attachments = append(attachments, entities.MessageAttachment{ContentType: contentType,diff --git a/api/pkg/requests/bulk_message_request.go b/api/pkg/requests/bulk_message_request.goindex 0ab6c024..a5aca7ce 100644--- a/api/pkg/requests/bulk_message_request.go+++ b/api/pkg/requests/bulk_message_request.go@@ -43,18 +43,7 @@ func (input *BulkMessage) ToMessageSendParams(userID entities.UserID, requestIDcontinue}- // Since there's no easy way to set a type in the CSV, defaulting to octet-stream and then just checking the file extension in the URL- 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"- }+ contentType := entities.GetAttachmentContentType(cleanURL)attachments = append(attachments, entities.MessageAttachment{ContentType: contentType,