@@ -245,30 +245,27 @@ defmodule Ask.Runtime.Session do
245
245
end
246
246
end
247
247
248
- def contact_respondent ( % { current_mode: % SMSMode { } } = session ) do
248
+ def contact_respondent ( % { schedule: schedule , current_mode: % SMSMode { } } = session ) do
249
249
token = Ecto.UUID . generate ( )
250
250
251
251
respondent = session . respondent
252
252
{ :ok , _flow , reply } = Flow . retry ( session . flow , TextVisitor . new ( "sms" ) , respondent . disposition )
253
253
channel = session . current_mode . channel
254
254
log_prompts ( reply , channel , session . flow . mode , respondent )
255
255
256
- ChannelBroker . ask ( channel . id , channel . type , session . respondent , token , reply )
256
+ { not_before , not_after } = acceptable_contact_time_window ( schedule )
257
+
258
+ ChannelBroker . ask ( channel . id , channel . type , session . respondent , token , reply , not_before , not_after )
257
259
260
+ # TODO: what happens with this when contact attempt falls outside acceptable window
258
261
respondent = Respondent . update_stats ( respondent . id , reply )
259
262
% { session | token: token , respondent: respondent }
260
263
end
261
264
262
265
def contact_respondent ( % { schedule: schedule , current_mode: % IVRMode { } } = session ) do
263
266
token = Ecto.UUID . generate ( )
264
267
265
- next_available_date_time =
266
- schedule
267
- |> Schedule . next_available_date_time ( )
268
-
269
- today_end_time =
270
- schedule
271
- |> Schedule . at_end_time ( next_available_date_time )
268
+ { not_before , not_after } = acceptable_contact_time_window ( schedule )
272
269
273
270
channel = session . current_mode . channel
274
271
@@ -277,8 +274,8 @@ defmodule Ask.Runtime.Session do
277
274
channel . type ,
278
275
session . respondent ,
279
276
token ,
280
- next_available_date_time ,
281
- today_end_time
277
+ not_before ,
278
+ not_after
282
279
)
283
280
284
281
% { session | token: token }
@@ -388,9 +385,13 @@ defmodule Ask.Runtime.Session do
388
385
flow: flow ,
389
386
respondent: respondent ,
390
387
token: token ,
391
- current_mode: % SMSMode { channel: channel }
388
+ current_mode: % SMSMode { channel: channel } ,
389
+ schedule: schedule
392
390
} = session
393
391
) do
392
+
393
+ { not_before , not_after } = acceptable_contact_time_window ( schedule )
394
+
394
395
case flow
395
396
|> Flow . step (
396
397
session . current_mode |> SessionMode . visitor ( ) ,
@@ -401,7 +402,7 @@ defmodule Ask.Runtime.Session do
401
402
if Reply . prompts ( reply ) != [ ] do
402
403
log_prompts ( reply , channel , flow . mode , respondent , true )
403
404
404
- ChannelBroker . ask ( channel . id , channel . type , respondent , token , reply )
405
+ ChannelBroker . ask ( channel . id , channel . type , respondent , token , reply , not_before , not_after )
405
406
406
407
respondent = Respondent . update_stats ( respondent . id , reply )
407
408
{ :end , reply , respondent }
@@ -422,7 +423,7 @@ defmodule Ask.Runtime.Session do
422
423
423
424
log_prompts ( reply , channel , flow . mode , respondent )
424
425
425
- ChannelBroker . ask ( channel . id , channel . type , respondent , token , reply )
426
+ ChannelBroker . ask ( channel . id , channel . type , respondent , token , reply , not_before , not_after )
426
427
427
428
respondent = Respondent . update_stats ( respondent . id , reply )
428
429
{ :ok , % { session | flow: flow , respondent: respondent } , reply , current_timeout ( session ) }
@@ -472,21 +473,16 @@ defmodule Ask.Runtime.Session do
472
473
schedule: schedule
473
474
} = session
474
475
) do
475
- next_available_date_time =
476
- schedule
477
- |> Schedule . next_available_date_time ( )
478
476
479
- today_end_time =
480
- schedule
481
- |> Schedule . at_end_time ( next_available_date_time )
477
+ { not_before , not_after } = acceptable_contact_time_window ( schedule )
482
478
483
479
ChannelBroker . setup (
484
480
channel . id ,
485
481
channel . type ,
486
482
respondent ,
487
483
token ,
488
- next_available_date_time ,
489
- today_end_time
484
+ not_before ,
485
+ not_after
490
486
)
491
487
492
488
{ :ok , % { session | respondent: respondent } , % Reply { } , current_timeout ( session ) }
@@ -1043,4 +1039,16 @@ defmodule Ask.Runtime.Session do
1043
1039
until = Schedule . next_available_date_time ( session . schedule )
1044
1040
Interval . new ( from: from , until: until ) |> Interval . duration ( :minutes )
1045
1041
end
1042
+
1043
+ defp acceptable_contact_time_window ( schedule ) do
1044
+ not_before =
1045
+ schedule
1046
+ |> Schedule . next_available_date_time ( )
1047
+
1048
+ not_after =
1049
+ schedule
1050
+ |> Schedule . at_end_time ( not_before )
1051
+
1052
+ { not_before , not_after }
1053
+ end
1046
1054
end
0 commit comments