;
; A2Billing extensions config
;

	

; For standard inbound call
[a2billing]
exten => _X.,1,NoOp(A2Billing Start)
exten => _X.,n,DeadAgi(a2billing.php,1)
exten => h,1,Hangup


; To standard Outbound the callback - this is used internally by the callback daemon
[a2billing-callback]
exten => _X.,1,DeadAgi(a2billing.php,1,callback)
exten => h,1,Hangup


; Inbound callback scenario
; it will perform a CallerID authentication before calling back the person, not everybody is allowed to use the callback
[a2billing-cid-callback]
exten => _X.,1,DeadAgi(a2billing.php,1,cid-callback,34) ;last parameter is the callback area code
exten => h,1,Hangup

; The following context won't hangup directly but prompt the caller to enter his destination number, cid authentication will be used.
[a2billing-cid-prompt-callback]
exten => _X.,1,DeadAgi(a2billing.php,1,cid-prompt-callback,34) ;last parameter is the callback area code
exten => _X.,n,Hangup

; Inbound callback scenario
; it will just callback the person after this callback context rang 
[a2billing-all-callback]
; the next 4 lines are to strip the leading 0 
;exten => _X.,1,GotoIf($["${CALLERID(num):0:1}" != "0"]?nozeroatstart)
;exten => _X.,n,NoOp(Changing Caller ID number from ${CALLERID(num)} to ${CALLERID(num):1})
;exten => _X.,n,Set(CALLERID(num)=${CALLERID(num):1})
;exten => _X.,n(nozeroatstart),NoOp(Start A2Billing)
exten => _X.,1,DeadAgi(a2billing.php,1,all-callback,34) ;last parameter is the callback area code
exten => h,1,Hangup

; !!! note : the 34 number is used for international callback, let s say that my server is in UK but that my DID is in Spain
; The system will need to know that it have to add up 34 to callback this person 


[a2billing-predictivedialer]
exten => _X.,1,DeadAgi(a2billing.php,1,predictivedialer)	
exten => h,1,Hangup


[a2billing-did]
exten => _X.,1,DeadAgi(a2billing.php,1,did)
exten => h,1,Hangup


[a2billing-conference-moderator]
exten => _X.,1,DeadAgi(a2billing.php,1,conference-moderator)
exten => h,1,Hangup


[a2billing-conference-member]
exten => _X.,1,DeadAgi(a2billing.php,1,conference-member)
exten => h,1,Hangup


[a2billing-conference-room]
exten => _X.,1,Answer()
exten => _X.,n,NoOp(Start Conference)
;exten => _X.,n(record),Set(MEETME_RECORDINGFILE=/var/spool/asterisk/meetme/conference_recording-${EPOCH}-${USER});
;exten => _X.,n,MeetMe(${EXTEN},rdTMc) ;Make new Room and record call. 
exten => _X.,n,MeetMe(${EXTEN},dTMc) ;Make new Room
exten => _X.,n,Hangup()


[a2billing-voucher]
exten => _X.,1,Answer(1)
exten => _X.,n,DeadAgi(a2billing.php,1,voucher)
;exten => _X.,n,AGI(a2billing.php,1,voucher,44) ; will add 44 in front of the callerID for the CID authentication
exten => h,1,Hangup


[a2billing_dispatch]
exten => _X.,1,Gotoif($[${RAND(0,100)} < 50]?${EXTEN},3:${EXTEN},5)
exten => _X.,2,Hangup
; REDIRECT TO A2BILLING
exten => _X.,3,Goto(a2billing,${EXTEN},1)
exten => _X.,4,Hangup
; REDIRECT TO OTHER SERVER WITH A2BILLING
exten => _X.,5,Goto(a2billing-second-server,${EXTEN},1)
exten => h,1,Hangup


[a2billing-second-server]
;exten => _X.,1,Dial(IAX2/${EXTEN}@IP_SECOND_SERVER)
exten => _X.,1,Dial(SIP/${EXTEN}@IP_SECOND_SERVER)
; Use canreinvite to not pass the media through the first box


; As fourth parameter we pass the reference ID of the Agent 
[a2billing_autocreate_example]
exten => _X.,1,DeadAgi(a2billing.php,1,standard,0,%REF_AGENT%)
exten => h,1,Hangup


; Example to extra the account code from the sip Header
[a2billing-sipheader-account]
exten => _X.,1,NoOp(A2Billing Start)
exten => _X.,2,Set(A2Bacc=${SIP_HEADER(A2B-Account)})
exten => _X.,3,NoOp(A2Bacc=${A2Bacc})
exten => _X.,4,Gotoif($[${LEN(${A2Bacc})} > 1]?${EXTEN}|5:${EXTEN}|6)
exten => _X.,5,Set(CDR(accountcode)=${A2Bacc})
exten => _X.,6,DeadAgi(a2billing.php,1)
exten => h,1,Hangup


; A2Billing Echo Test
[a2billing-echotest]
exten => _X.,1,NoOp(A2Billing Echo Test Start)
exten => _X.,1,Playback(demo-echotest) ; Let them know what's going on
exten => _X.,2,Echo ; Do the echo test
exten => _X.,3,Playback(demo-echodone) ; Let them know it's over