Skip to content

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

Fix some defaults

Acho Arnoldb6a79c0a8f55
diff --git a/api/pkg/entities/phone.go b/api/pkg/entities/phone.go
index 218f17ae..b92ab1ab 100644
--- a/api/pkg/entities/phone.go
+++ b/api/pkg/entities/phone.go
@@ -26,21 +26,21 @@ type Phone struct {
// MessageExpirationDuration returns the message expiration as time.Duration
func (phone *Phone) MessageExpirationDuration() time.Duration {
- return time.Duration(phone.MessageExpirationSeconds) * time.Second
+ return time.Duration(int(phone.MessageExpirationSecondsSanitized())) * time.Second
}
// MessageExpirationSecondsSanitized returns the message expiration seconds with default of 1 hour
func (phone *Phone) MessageExpirationSecondsSanitized() uint {
if phone.MessageExpirationSeconds == 0 {
- return 60 * 60 // 1 hour
+ return 10 * 60 // 10 minutes
}
return phone.MessageExpirationSeconds
}
-// MaxSendAttemptsSanitized returns the max send attempts replacing 0 with 1
+// MaxSendAttemptsSanitized returns the max send attempts replacing 0 with 2
func (phone *Phone) MaxSendAttemptsSanitized() uint {
if phone.MaxSendAttempts == 0 {
- return 1
+ return 2
}
return phone.MaxSendAttempts
}
diff --git a/api/pkg/services/message_service.go b/api/pkg/services/message_service.go
index 081b2228..d77ce6b6 100644
--- a/api/pkg/services/message_service.go
+++ b/api/pkg/services/message_service.go
@@ -408,7 +408,7 @@ func (service *MessageService) HandleMessageSending(ctx context.Context, params
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
- ctxLogger.Info(fmt.Sprintf("message with id [%s] in after adding send attempt", message.ID))
+ ctxLogger.Info(fmt.Sprintf("message with id [%s] updated after adding send attempt", message.ID))
return nil
}
diff --git a/api/pkg/services/phone_service.go b/api/pkg/services/phone_service.go
index c3a99db2..cf8749a1 100644
--- a/api/pkg/services/phone_service.go
+++ b/api/pkg/services/phone_service.go
@@ -174,7 +174,7 @@ func (service *PhoneService) createPhone(ctx context.Context, params PhoneUpsert
// Android has a limit of 30 SMS messages per minute without user permission, to be safe let's use 10 messages per minute
// https://android.googlesource.com/platform/frameworks/opt/telephony/+/master/src/java/com/android/internal/telephony/SmsUsageMonitor.java#80
MessagesPerMinute: 10,
- MessageExpirationSeconds: 15 * 60, // 15 minutes
+ MessageExpirationSeconds: 10 * 60, // 10 minutes
MaxSendAttempts: 2,
SIM: params.SIM,
PhoneNumber: phonenumbers.Format(&params.PhoneNumber, phonenumbers.E164),
@@ -202,7 +202,7 @@ func (service *PhoneService) update(phone *entities.Phone, params PhoneUpsertPar
if phone.FcmToken != nil {
phone.FcmToken = params.FcmToken
}
- if params.MessagesPerMinute != nil {
+ if params.MessagesPerMinute != nil && *params.MessagesPerMinute > 0 {
phone.MessagesPerMinute = *params.MessagesPerMinute
}