Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Added validator for attachment urls

Jake Daynes69ecce11ff42
diff --git a/api/pkg/validators/message_handler_validator.go b/api/pkg/validators/message_handler_validator.go
index 33ab4dfe..fd690e26 100644
--- a/api/pkg/validators/message_handler_validator.go
+++ b/api/pkg/validators/message_handler_validator.go
@@ -106,6 +106,28 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context
return result
}
+ if len(request.Attachments) > 10 {
+ result.Add("attachments", "you cannot attach more than 10 files to a single message")
+ }
+
+ for i, attachment := range request.Attachments {
+ if strings.TrimSpace(attachment.ContentType) == "" {
+ result.Add("attachments", fmt.Sprintf("attachment at index %d is missing content_type", i))
+ }
+
+ if strings.TrimSpace(attachment.URL) == "" {
+ result.Add("attachments", fmt.Sprintf("attachment at index %d is missing url", i))
+ } else {
+ // Basic URL validation
+ parsedURL, err := url.ParseRequestURI(attachment.URL)
+ if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
+ result.Add("attachments", fmt.Sprintf("attachment at index %d has an invalid url format", i))
+ } else if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
+ result.Add("attachments", fmt.Sprintf("attachment at index %d must use http or https scheme", i))
+ }
+ }
+ }
+
if request.SendAt != nil && request.SendAt.After(time.Now().Add(480*time.Hour)) {
result.Add("send_at", "the scheduled time cannot be more than 20 days (480 hours) in the future")
}