Skip to content

Commit 53112cb

Browse files
Added same validation to bulk message
1 parent b5bfdb4 commit 53112cb

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

api/pkg/validators/message_handler_validator.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context
114114
if strings.TrimSpace(attachment.ContentType) == "" {
115115
result.Add("attachments", fmt.Sprintf("attachment at index %d is missing content_type", i))
116116
}
117-
117+
118118
if strings.TrimSpace(attachment.URL) == "" {
119119
result.Add("attachments", fmt.Sprintf("attachment at index %d is missing url", i))
120120
} else {
121-
// Basic URL validation
122121
parsedURL, err := url.ParseRequestURI(attachment.URL)
123122
if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
124123
result.Add("attachments", fmt.Sprintf("attachment at index %d has an invalid url format", i))
@@ -178,6 +177,27 @@ func (validator MessageHandlerValidator) ValidateMessageBulkSend(ctx context.Con
178177
return result
179178
}
180179

180+
if len(request.Attachments) > 10 {
181+
result.Add("attachments", "you cannot attach more than 10 files to a single message")
182+
}
183+
184+
for i, attachment := range request.Attachments {
185+
if strings.TrimSpace(attachment.ContentType) == "" {
186+
result.Add("attachments", fmt.Sprintf("attachment at index %d is missing content_type", i))
187+
}
188+
189+
if strings.TrimSpace(attachment.URL) == "" {
190+
result.Add("attachments", fmt.Sprintf("attachment at index %d is missing url", i))
191+
} else {
192+
parsedURL, err := url.ParseRequestURI(attachment.URL)
193+
if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
194+
result.Add("attachments", fmt.Sprintf("attachment at index %d has an invalid url format", i))
195+
} else if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
196+
result.Add("attachments", fmt.Sprintf("attachment at index %d must use http or https scheme", i))
197+
}
198+
}
199+
}
200+
181201
_, err := validator.phoneService.Load(ctx, userID, request.From)
182202
if stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
183203
result.Add("from", fmt.Sprintf("no phone found with with 'from' number [%s]. Install the android app on your phone to start sending messages", request.From))

0 commit comments

Comments
 (0)