PDA

View Full Version : Is there a variable for the result of the fax?



epretlac
07-22-08, 02:19 PM
Q: I need to to know if fax transmitted or failed, what are my options?

A: PIKATxFax() and PIKARxFax() apps feedback several variables to the dialplan. The information below also appears in the man page (# man chan_pika).

Upon completion, the following variables are set to retrieve details about the FAX session for use in dial plans or logging.

REMOTESTATIONID
Sets the receiver CSID.

FAXPAGES
Set to the number of pages sent or received.

FAXBITRATE
Set to the rate used during transmission.

FAXRESOLUTION
Set to the resolution used during transmission.

FAXRESULT
Set to the result of the FAX session. The possible return values are:
PKH_FAX_RESULT_SUCCESSFUL All images transferred, no protocol errors.
PKH_FAX_RESULT_NOFAX No fax machine was detected.
PKH_FAX_RESULT_PARTIAL Some or all images transferred, but a protocol error occurred.
PKH_FAX_RESULT_NEG_FAILED Image transfer could not be negotiated.
PKH_FAX_RESULT_FAILED_TO_TRAIN Line quality prevented image transfer.
PKH_FAX_RESULT_PROTOCOL_ERROR Protocol error occurred.
PKH_FAX_RESULT_PROTOCOL_ERROR Protocol error occurred.
FAILED The FAX session failed. The FAXLASTERROR variable provides more detailed information.

FAXLASTERROR
If FAXRESULT returns "FAILED", this variable provides further details about the cause of the failure.

For example:
PKH_ERROR_LICENSE_VIOLATION No PIKA fax licenses available (added in chan_pika-3.3).


FAXRESULT=FAILED, FAXLASTERROR= PKH_ERROR_LICENSE_VIOLATION



Below is a sample dialplan that illustrates how these variables can be used in a dialplan to determine whether a fax was successful or not and to use that result to resend a fax if necessary. This example uses Asterisk call files to send (and resend) faxes.

------------------------------------------------------------------------------
; PIKA extensions.conf file sample
;
; This dialplan example demonstrates how to use PIKA's FAXRESULT variables.
;
; ------------------------------------------------------------------------------
[general]
static=yes
writeprotect=no
autofallthrough=yes
clearglobalvars=no
priorityjumping=no
;---------------------------------------
; PIKA SAMPLE CONFIGURATION
;---------------------------------------
[from-zaptel]
exten => s,1,Wait,1 ; Wait a second
exten => s,n,NoOp(Answer the call)
exten => s,n,Answer ; Answer the line
exten => s,n,Wait,1 ; Wait a second
exten => s,n,BackGround(vm-enter-num-to-call)
exten => s,n,WaitExten

include => internal

[internal]
exten => _8X.,1,Set(LOCALHEADERINFO="PIKARxFax Test Page %P Time: %H:%M To: %l From: %r")
exten => _8X.,n,Set(RXFAXFILE=/tmp/pikafax-${UNIQUEID}.tif)
exten => _8X.,n,Wait,1
exten => _8X.,n,PikaRxfax(${RXFAXFILE})
exten => _8X.,n,NoOp(${FAXRESULT})
exten => _8X.,n,NoOp(${FAXLASTERROR})
exten => _8X.,n,NoOp(${REMOTESTATIONID})
exten => _8X.,n,NoOp(${FAXPAGES})
exten => _8X.,n,NoOp(${FAXBITRATE})
exten => _8X.,n,NoOp(${FAXRESOLUTION})
exten => _8X.,n,Set(DIALNUM=${EXTEN:1})
exten => _8X.,n,Hangup
exten => h,1,GotoIf($["${FAXRESULT}" = "PKH_FAX_RESULT_SUCCESSFUL"]?FAXSUCCEED:FAXFAILED)
exten => h,n(FAXSUCCEED),Set(SENDFILE=/tmp/send-${UNIQUEID}.txt) ;create a call file to send the fax out to a fax machine
exten => h,n,System(sleep 30)
exten => h,n,System(echo "Channel: Zap/g0/${DIALNUM}" >> ${SENDFILE})
exten => h,n,System(echo "WaitTime: 120" >> ${SENDFILE})
exten => h,n,System(echo "MaxRetries: 1" >> ${SENDFILE})
exten => h,n,System(echo "Context: autocall" >> ${SENDFILE})
exten => h,n,System(echo "Extension: s" >> ${SENDFILE})
exten => h,n,System(echo "Priority: 1" >> ${SENDFILE})
exten => h,n,System(echo "Set: TXFAXFILE=${RXFAXFILE}" >> ${SENDFILE})
exten => h,n,System(echo "Set: DIALNUM=${DIALNUM}" >> ${SENDFILE})
exten => h,n,System(echo "Callerid: Forward the received fax to a fax machine" >> ${SENDFILE})
exten => h,n,System(cp ${SENDFILE} /var/spool/asterisk/outgoing/.)
exten => h,n,System(rm -f ${SENDFILE})
exten => h,101(FAXFAILED),NoOp(PikaRXFAX Failed)

[autocall]
exten => s,1,Answer
exten => s,n,Set(LOCALSTATIONID=1078)
exten => s,n,Set(LOCALHEADERINFO="PIKATxFax Forwarded %P Time: %H:%M To: %l From: %r")
exten => s,n,Wait,1
exten => s,n,NoOp(${TXFAXFILE})
exten => s,n,PikaTxfax(${TXFAXFILE})
exten => s,n,NoOp(${FAXRESULT})
exten => s,n,NoOp(${FAXLASTERROR})
exten => s,n,NoOp(${REMOTESTATIONID})
exten => s,n,NoOp(${FAXPAGES})
exten => s,n,NoOp(${FAXBITRATE})
exten => s,n,NoOp(${FAXRESOLUTION})
exten => s,n,Hangup
exten => h,1,GotoIf($["${FAXRESULT}" = "PKH_FAX_RESULT_SUCCESSFUL"]?FAXSUCCEED:FAXFAILED)
exten => h,n(FAXFAILED),NoOp(Fax call failed with status ${FAXRESULT} , error ${FAXLASTERROR} , this is where I try again after 30 seconds.)
exten => h,n,Set(RETRYFAXFILE=/tmp/retryfax-${UNIQUEID}.txt)
exten => h,n,System(sleep 30)
exten => h,n,System(echo "Channel: Zap/g0/${DIALNUM}" >> ${RETRYFAXFILE})
exten => h,n,System(echo "WaitTime: 120" >> ${RETRYFAXFILE})
exten => h,n,System(echo "MaxRetries: 1" >> ${RETRYFAXFILE})
exten => h,n,System(echo "Context: autocall_retry" >> ${RETRYFAXFILE})
exten => h,n,System(echo "Extension: s" >> ${RETRYFAXFILE})
exten => h,n,System(echo "Priority: 1" >> ${RETRYFAXFILE})
exten => h,n,System(echo "Callerid: RE-Forward the received fax to a fax machine" >> ${RETRYFAXFILE})
exten => h,n,System(echo "Set: TXFAXFILE=${RXFAXFILE}" >> ${SENDFILE})
exten => h,n,System(echo "Set: DIALNUM=${DIALNUM}" >> ${SENDFILE})
exten => h,n,System(cp ${RETRYFAXFILE} /var/spool/asterisk/outgoing/)
exten => h,n,System(rm -f ${RETRYFAXFILE})
exten => h,101(FAXSUCCEED),NoOp(PikaTxFax succeeded)

[autocall_retry]
exten => s,1,Answer
exten => s,n,Set(LOCALSTATIONID=1078)
exten => s,n,Set(LOCALHEADERINFO="PIKATxFax Forwarded %P Time: %H:%M To: %l From: %r")
exten => s,n,Wait, 1
exten => s,n,NoOp(${TXFAXFILE})
exten => s,n,PikaTxfax(${TXFAXFILE})
exten => s,n,NoOp(${FAXRESULT})
exten => s,n,NoOp(${FAXLASTERROR})
exten => s,n,NoOp(${REMOTESTATIONID})
exten => s,n,NoOp(${FAXPAGES})
exten => s,n,NoOp(${FAXBITRATE})
exten => s,n,NoOp(${FAXRESOLUTION})
exten => s,n,Hangup


Eric Pretlac
PIKA Support