File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,6 +106,28 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context
106106 return result
107107 }
108108
109+ if len (request .Attachments ) > 10 {
110+ result .Add ("attachments" , "you cannot attach more than 10 files to a single message" )
111+ }
112+
113+ for i , attachment := range request .Attachments {
114+ if strings .TrimSpace (attachment .ContentType ) == "" {
115+ result .Add ("attachments" , fmt .Sprintf ("attachment at index %d is missing content_type" , i ))
116+ }
117+
118+ if strings .TrimSpace (attachment .URL ) == "" {
119+ result .Add ("attachments" , fmt .Sprintf ("attachment at index %d is missing url" , i ))
120+ } else {
121+ // Basic URL validation
122+ parsedURL , err := url .ParseRequestURI (attachment .URL )
123+ if err != nil || parsedURL .Scheme == "" || parsedURL .Host == "" {
124+ result .Add ("attachments" , fmt .Sprintf ("attachment at index %d has an invalid url format" , i ))
125+ } else if parsedURL .Scheme != "http" && parsedURL .Scheme != "https" {
126+ result .Add ("attachments" , fmt .Sprintf ("attachment at index %d must use http or https scheme" , i ))
127+ }
128+ }
129+ }
130+
109131 if request .SendAt != nil && request .SendAt .After (time .Now ().Add (480 * time .Hour )) {
110132 result .Add ("send_at" , "the scheduled time cannot be more than 20 days (480 hours) in the future" )
111133 }
You can’t perform that action at this time.
0 commit comments