After a couple of days I gathered a dialplan I thought was working. Well, may be the weird handling of the variable __SendURL
is avoidable. Nevertheless, I think that the system call System(/var/www/writedlr.php...)
should performed anyway - no matter if the call fails, cancels or succeeds. However, there are some calls in my log that appear not to run the system call. How come?
The callfile initates a local call on fax_caller,faxout,1 and connects the remote end to fax_caller,faxsend,1
[fax_caller]
; Start
exten => faxout,1,NoOp(** Fax caller **)
same => n,Set(__SendDLR=1)
same => n,Dial(${ChannelPrefix}:${ReceiverPhoneNr}@${ChannelPostfix},,b(fax_outgoing_init^faxout^1(${SenderPhoneNr},${ChannelPostfix})))
; Sending fax
exten => faxsend,1,NoOp(** Sending fax **)
same => n,Set(__SendDLR=1)
same => n,SendFAX(/var/spool/asterisk/fax/${TIFF_FILE},dfs)
same => n,NoOp(** Fax status: ${FAXSTATUS})
same => n,GotoIf($[ "${FAXSTATUS}" = "SUCCESS" ]?lSuccess:lFailed)
same => n(lSuccess),NoOp(Success)
same => n,Set(status=OK)
same => n,Set(pages=${FAXPAGES})
same => n,Goto(lReady)
same => n(lFailed),NoOp(Failed)
same => n,Set(status=failed)
same => n,Set(pages=0)
same => n,Goto(lReady)
same => n(lReady),NoOp(** Ready **)
same => n,Gosub(dlrsend,1(${__SendDLR},${status},${pages},${DLR_URL}))
; Delivery notification
exten => dlrsend,1,NoOp(** Sending Delivery Notification: **)
same => n,Set(doDLR=${ARG1})
same => n,Set(status=${ARG2})
same => n,Set(pages=${ARG3})
same => n,Set(DLR_URL=${ARG4})
same => n,GotoIf($[ "${doDLR}" = "0" ]?lDLRready:)
same => n,System(/var/www/writedlr.php -u '${DLR_URL}' -s '${status}' -n '${pages}' -t '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}')
same => n,Set(__SendDLR=0)
same => n(lDLRready),NoOp(** DLR ready **)
same => n,Return()
; Failed
exten => failed,1,NoOp(** Fax failed **)
same => n,Gosub(dlrsend,1(1,failed,0,${DLR_URL}))
[fax_outgoing_init]
exten => faxout,1,NoOp(** Fax, pre-dial hook **)
same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<sip:${ARG1}@${ARG2}>")
same => n,Return()