@@ -161,14 +161,16 @@ func (service *PhoneNotificationService) Send(ctx context.Context, params *Phone
161161
162162// PhoneNotificationScheduleParams are parameters for sending a notification
163163type PhoneNotificationScheduleParams struct {
164- UserID entities.UserID
165- Owner string
166- Source string
167- Encrypted bool
168- Contact string
169- Content string
170- SIM entities.SIM
171- MessageID uuid.UUID
164+ UserID entities.UserID
165+ Owner string
166+ Source string
167+ Encrypted bool
168+ Contact string
169+ Content string
170+ SIM entities.SIM
171+ MessageID uuid.UUID
172+ ExactSendTime bool
173+ ScheduledSendTime * time.Time
172174}
173175
174176// Schedule a notification to be sent to a phone
@@ -195,6 +197,35 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
195197 UpdatedAt : time .Now ().UTC (),
196198 }
197199
200+ // Bypass rate-limit and schedule window logic for exact send time
201+ if params .ExactSendTime && params .ScheduledSendTime != nil {
202+ scheduledAt := * params .ScheduledSendTime
203+ if scheduledAt .Before (time .Now ().UTC ()) {
204+ scheduledAt = time .Now ().UTC ()
205+ }
206+ notification .ScheduledAt = scheduledAt
207+ if err = service .phoneNotificationRepository .ScheduleExact (ctx , notification ); err != nil {
208+ msg := fmt .Sprintf ("cannot schedule exact notification for message [%s] to phone [%s]" , params .MessageID , phone .ID )
209+ return service .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
210+ }
211+
212+ if err = service .dispatchMessageNotificationScheduled (ctx , params , notification ); err != nil {
213+ ctxLogger .Error (err )
214+ }
215+
216+ if err = service .dispatchMessageNotificationSend (ctx , params .Source , notification ); err != nil {
217+ return service .tracer .WrapErrorSpan (span , err )
218+ }
219+
220+ ctxLogger .Info (fmt .Sprintf (
221+ "message with id [%s] exact notification scheduled for [%s] with id [%s]" ,
222+ params .MessageID ,
223+ notification .ScheduledAt ,
224+ notification .ID ,
225+ ))
226+ return nil
227+ }
228+
198229 var schedule * entities.MessageSendSchedule
199230 if phone .ScheduleID != nil {
200231 schedule , err = service .sendScheduleRepository .Load (ctx , params .UserID , * phone .ScheduleID )
0 commit comments