Skip to content

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

Increase send time to 20 days into the future

Acho Arnold5bf56930218d
diff --git a/api/pkg/requests/message_send_request.go b/api/pkg/requests/message_send_request.go
index 0285807d..c07a9a28 100644
--- a/api/pkg/requests/message_send_request.go
+++ b/api/pkg/requests/message_send_request.go
@@ -22,7 +22,7 @@ type MessageSend struct {
Encrypted bool `json:"encrypted" example:"false" validate:"optional"`
// RequestID is an optional parameter used to track a request from the client's perspective
RequestID string `json:"request_id" example:"153554b5-ae44-44a0-8f4f-7bbac5657ad4" validate:"optional"`
- // SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone.
+ // SendAt is an optional parameter used to schedule a message to be sent in the future. The time is considered to be in your profile's local timezone and you can queue messages for up to 20 days (480 hours) in the future.
SendAt *time.Time `json:"send_at" example:"2022-06-05T14:26:09.527976+03:00" validate:"optional"`
}
diff --git a/api/pkg/validators/bulk_message_handler_validator.go b/api/pkg/validators/bulk_message_handler_validator.go
index 4c31ea51..9881c53f 100644
--- a/api/pkg/validators/bulk_message_handler_validator.go
+++ b/api/pkg/validators/bulk_message_handler_validator.go
@@ -224,8 +224,8 @@ func (v *BulkMessageHandlerValidator) validateMessages(messages []*requests.Bulk
result.Add("document", fmt.Sprintf("Row [%d]: The message content must be less than 1024 characters.", index+2))
}
- if message.SendTime != nil && message.SendTime.After(time.Now().Add(24*time.Hour)) {
- result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] cannot be more than 24 hours in the future.", index+2, message.SendTime.Format(time.RFC3339)))
+ if message.SendTime != nil && message.SendTime.After(time.Now().Add(420*time.Hour)) {
+ result.Add("document", fmt.Sprintf("Row [%d]: The SendTime [%s] cannot be more than 20 days (420 hours) in the future.", index+2, message.SendTime.Format(time.RFC3339)))
}
}
return result
diff --git a/api/pkg/validators/message_handler_validator.go b/api/pkg/validators/message_handler_validator.go
index 78cfd024..33ab4dfe 100644
--- a/api/pkg/validators/message_handler_validator.go
+++ b/api/pkg/validators/message_handler_validator.go
@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"strings"
+ "time"
"github.com/NdoleStudio/httpsms/pkg/repositories"
"github.com/NdoleStudio/httpsms/pkg/services"
@@ -105,6 +106,10 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context
return result
}
+ 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")
+ }
+
_, err := validator.phoneService.Load(ctx, userID, request.From)
if stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
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))