This describes a context that is a wrapper for a generic call file format. The idea is to do some processing of variables in a call file before deciding to make the outbound call.
The problem is that two processes run in Asterisk. I used to be able to tell the difference between the two and route one to 'nullcontext' below so that I didn't get duplication of the call.
Here is a call file:
---
Channel: Local/s@timedcontext/n
Callerid:XXXXXXXXXX
RetryTime:300
WaitTime:30
MaxRetries: 3
Context: timedcontext
Extension:s
Priority:1
SetVar:INTERNAL_MACRO_EXTENSION=wo-notification
SetVar:CALL_EXPIRATION=20071227000000
SetVar:PLAYFILE=2a0103d439882c9e6dc344949efbd198
SetVar:TZ_OFFSET=-1
SetVar:PHONE_NUMBER=17817619228
SetVar:DAVESVAR=<<xmlcalldata>>
SetVar:EARLIEST_CALLTIME=09
SetVar:LATEST_CALLTIME=08
SetVar:IVRUNIQUEID=2a0103d439882c9e6dc344949efbd198
---
[timedcontext]
exten => s,1,SetCDRUserField(${DAVESVAR})
exten => s,2,Answer
exten => s,3,Gotoif($[${LEN(${CALL_EXPIRATION})} <= 0]?timed-nullcontext,s,1:s,4) ;this used to be where I could re-route one of the processes and kill it when the other one finished
exten => s,4,NoOp('~~~~~~~~~~~~~ FRAMEWORK CHANNEL IN PROGRESS ~~~~~~~~~~~~~~')
exten => s,5,SetGlobalVar(TIME_RESTRICTION_LATE=21) ;set latest call time to 8pm (20:00) put into main extension file??
exten => s,6,SetGlobalVar(TIME_RESTRICTION_EARLY=09) ;set earliest call time to 9pm (9) put into main extension file??
exten => s,7,Macro(channel-ok-to-call,s,10,${CALL_EXPIRATION},${TZ_OFFSET})
exten => s,8,SetVar(TEMP=${UNIQUEID:0:10}${UNIQUEID:11:1})
exten => s,9,Dial(${OUT_3}/${PHONE_NUMBER}|60|gM(${INTERNAL_MACRO_EXTENSION}^${PLAYFILE}^${TEMP}^${IVRUNIQUEID})) ;dave added the g
exten => s,10,NoOp('~~~~~~~~~~~~~ LEAVING FRAMEWORK CHANNEL ~~~~~~~~~~~~~~')
exten => s,11,Hangup;end the call
[macro-channel-ok-to-call]
exten => s,1,SetVar(currentHour=$[${TIMESTAMP:9:2} + ${ARG4}])
exten => s,2,SetVar(TSFORMATTED=${TIMESTAMP:0:8}${TIMESTAMP:9:6})
exten => s,3,GotoIf($[${currentHour} < 0]?s,4:s,5});check to see if current hour < 0 ie 1-3 is 1am + -3 hour offest which is -2 or 20:00 (24+-2)
exten => s,4,SetVar(currentHour=$[24 + ${currentHour}])
exten => s,5,NoOp(checking if ${TSFORMATTED} is < ${ARG3}...)
exten => s,6,GotoIf($[${TSFORMATTED} < ${ARG3}]?s,8:s,7);check if the call has expired
exten => s,7,Goto(${MACRO_CONTEXT},${ARG1},${ARG2})
exten => s,8,GotoIf($[${currentHour} < ${TIME_RESTRICTION_LATE}]?s,9:${MACRO_CONTEXT},${ARG1},${ARG2});check if we are past the late time boundary
exten => s,9,GotoIf($[${currentHour} >= ${TIME_RESTRICTION_EARLY}]?s,10:${MACRO_CONTEXT},${ARG1},${ARG2});check if we are before the early time boundary
exten => s,10,NoOp('~~~~~~~~~~~ LEAVING OK TO CALL CHECK - IT IS OK TO CALL ~~~~~~~~~~~~~')
[timed-nullcontext]
exten => s,1,NoCDR()
exten => s,2,SetVar(TEMP=${UNIQUEID:0:10}${UNIQUEID:11:1})
exten => s,3,NoOp('~~~~~~~~~~~~ WAITING IN NULL CONTEXT ~~~~~~~~~~~~~')
exten => s,4,Wait(5)
exten => s,5,NoOp('~~~~~~~~~~~~ CHECKING IF CALL FINISHED - GLOBAL VAR IS: FINISHED_'${TEMP}' value is: '${FINISHED_${TEMP}}'~~~~~~~~~~~~~')
exten => s,6,GoToIf($[${LEN(${FINISHED_${TEMP}})} >= 1]?timedcontext,s,10:s,7)
exten => s,7,Goto(s,2)
[macro-wo-reminder]
exten => s,1,Wait(2)
exten => s,2,Background(wo-reminder-start)
exten => s,3,Background(/var/www/html/asterisk/sound/${ARG1})
exten => s,4,Background(wo-reminder-repeat)
exten => s,5,Wait(3)
exten => s,6,Background(wo-reminder-start)
exten => s,7,Background(/var/www/html/asterisk/sound/${ARG1})
exten => s,8,Background(wo-reminder-finish)
exten => s,9,SetGlobalVar(FINISHED_${ARG2}=true)
exten => s,10,Hangup
[macro-wo-notification]
exten => s,1,NoOp(*************** IN Macro wo notification **********************)
exten => s,2,Wait(8)
;
; Play the sound files
; WE are using Read() because exten => 1,1... etc. was not working
exten => s,3,Background(/var/www/html/asterisk/message_part_1)
exten => s,4,Background(/var/www/html/asterisk/sound/${ARG1}) ; "play outbound msg"
exten => s,5,Background(/var/www/html/asterisk/message_part_2)
exten => s,6,Read(notif_var,/var/www/html/asterisk/new_how_to_ack,1,skip,1,3); "Press 2 to replay or 1 to acknowledge receiving this message"
exten => s,7,GotoIf($["${notif_var}" = "1"]?s-ack,1:s,8)
exten => s,8,GotoIf($["${notif_var}" = "2"]?s,10:s,9) ; replay if 2 pressed
exten => s,9,GotoIf($["${notif_var}" = ""]?s,10:i,1) ; if nothing pressed, run message again. else, run invalid
;
; Play the sound files again if nothing was entered the first time
exten => s,10,Wait(7)
exten => s,11,Background(/var/www/html/asterisk/message_part_1)
exten => s,12,Background(/var/www/html/asterisk/sound/${ARG1}) ; "play outbound msg"
exten => s,13,Background(/var/www/html/asterisk/message_part_2)
exten => s,14,Read(notif_var,/var/www/html/asterisk/new_how_to_ack,1,skip,1,3)
exten => s,15,GotoIf($["${notif_var}" = "1"]?s-ack,1:s,16) ; goodby and record ack status
exten => s,16,GotoIf($["${notif_var}" = "2"]?s,10:s,17) ; replay if 2 pressed
exten => s,17,GotoIf($["${notif_var}" = ""]?s,18:i,1) ; if nothing pressed, run timedout. else, run invalid
;
; Play the sound files again if nothing was entered the first time
exten => s,18,Wait(3)
exten => s,19,Background(/var/www/html/asterisk/message_part_1)
exten => s,20,Background(/var/www/html/asterisk/sound/${ARG1}) ; "play outbound msg"
exten => s,21,Background(/var/www/html/asterisk/message_part_2)
exten => s,22,Read(notif_var,/var/www/html/asterisk/new_how_to_ack,1,skip,1,3)
exten => s,23,GotoIf($["${notif_var}" = "1"]?s-ack,1:s,24) ; goodby and record ack status
exten => s,24,GotoIf($["${notif_var}" = "2"]?s,19:s,25) ; replay if 2 pressed
exten => s,25,GotoIf($["${notif_var}" = ""]?t,1:i,1) ; if nothing pressed, run timedout. else, run invalid
;
; 1 Pressed. Gooodby Ack
exten => s-ack,1,NoOp("******************************* IN GOODBY ACK **********************************")
exten => s-ack,2,agi(crs_wo_notification_put.php|username=ivrwsuser|password=XXXXXXX|ivr_process=update_call|ivruniqueid=${ARG3}|status=ack)
exten => s-ack,3,SetGlobalVar(FINISHED_${ARG2}=true)
exten => s-ack,4,Playback(inbound/tygoodbye)
;exten => s-ack,5,SetVar(MACRO_RESULT=CONTINUE) ;Hangup the called party and continue on in the dialplan from where you called Dial
;
; Invalid number pressed
exten => i,1,NoOp(************ Invalid selection **********)
exten => i,2,Playback(pbx-invalid)
exten => i,3,Goto(s,10)
;
; Execute this when caller hangs up
exten => h,1,NoOp(***** IN HANGUP *********)
exten => h,2,agi(crs_wo_notification_put.php|username=ivrwsuser|password=XXXXXXX|ivr_process=update_call|ivruniqueid=${ARG3}|status=fail)
exten => h,3,SetGlobalVar(FINISHED_${ARG2}=true)
exten => h,4,SetVar(MACRO_RESULT=CONTINUE) ;Hangup the called party and continue on in the dialplan from where you called Dial
;
; Timed out.
exten => t,1,Playback(vm-goodbye)
exten => t,2,NoOp(*********** Goodby playback - failed ***************)
exten => t,3,agi(crs_wo_notification_put.php|username=ivrwsuser|password=XXXXXXX|ivr_process=update_call|ivruniqueid=${ARG3}|status=fail)
exten => t,4,SetGlobalVar(FINISHED_${ARG2}=true)
exten => t,5,SetVar(MACRO_RESULT=CONTINUE) ;Hangup the called party and continue on in the dialplan from where you called Dial