How to do some task after Asterisk ReceiveFax function calling?

2.6k views Asked by At

I have asterisk Server installed: And I have created Dial-plan for Receive Fax: I want to do some task after successfully received fax. but, any line written after ReceveFax function ONLY called when Transmission is FAILED. If transmission is SUCCESS will never called any line after.

My Dial-Plan:

;######################### FAX Dialplan Implementation Start ##########################

exten => _15555551212,1,NoOp(Fax receiving from ${EXTEN})
exten => _15555551212,n,Answer
exten => _15555551212,n,Ringing
exten => _15555551212,n,Macro(inboundfax)
exten => _15555551212,n,NoOp(Done)

exten => h,1, NoOp(Completed...)

[macro-inboundfax]
exten => s,1,NoOp(**** FAX RECEIVED from ${CALLERID(num)} ${STRFTIME(${EPOCH},,%c)} ****)
exten => s,n,Set(FAXOPT(ecm)=yes)
exten => s,n,Set(FILENAME=fax-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten => s,n,Set(FAXFILE=${FILENAME}.tif)
exten => s,n,Set(FAXOPT(ecm)=yes)
exten => s,n,Set(FAXOPT(headerinfo)=Received by MYCOMPANY ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M)})
exten => s,n,Set(FAXOPT(localstationid)=5555551212)
exten => s,n,Set(FAXOPT(maxrate)=14400)
exten => s,n,Set(FAXOPT(minrate)=4800)
exten => s,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => s,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => s,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => s,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => s,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => s,n,NoOp(**** RECEIVING FAX : ${FAXFILE} ****)
exten => s,n,Set(FAX_DEST=/var/www/html/private/fax/received)
exten => s,n,Set(FAXDEST=/tmp)

exten => s,n,DumpChan(3)

exten => s,n,ReceiveFAX(${FAXDEST}/${FAXFILE})
exten => s,n,Verbose(3,- Fax receipt completed with status: ${FAXSTATUS})

exten => s,n,Verbose(Fax receipt completed with status: ${FAXSTATUS})

exten => s,n,Verbose(FaxFile moving... ${FAXDEST}/${FAXFILE} -> ${FAX_DEST}/)
exten => s,n,System(mv ${FAXDEST}/${FAXFILE} ${FAX_DEST}/)
exten => s,n,Verbose(Fax file moved.)

exten => s,n,NoOp(Mail Sending...)
;exten => s,n,System(echo | mutt -a ${FAXDEST}/${FAXFILE} -s "received fax" [email protected])
exten => s,n,NoOp(Mail Sent)

Console Log: (While Receiving Fax)

 == Using SIP RTP CoS mark 5
    -- Executing [15555551212@from-sip:1] NoOp("SIP/4001-0000000f", "Fax receiving from 15555551212") in new stack
    -- Executing [15555551212@from-sip:2] Answer("SIP/4001-0000000f", "") in new stack
    -- Executing [15555551212@from-sip:3] Ringing("SIP/4001-0000000f", "") in new stack
    -- Executing [15555551212@from-sip:4] Macro("SIP/4001-0000000f", "inboundfax") in new stack
    -- Executing [s@macro-inboundfax:1] NoOp("SIP/4001-0000000f", "**** FAX RECEIVED from 4001 Sat Jun 20 15:25:22 2015 ****") in new stack
    -- Executing [s@macro-inboundfax:2] Set("SIP/4001-0000000f", "FAXOPT(ecm)=yes") in new stack
    -- Executing [s@macro-inboundfax:3] Set("SIP/4001-0000000f", "FILENAME=fax-20150620-152522") in new stack
    -- Executing [s@macro-inboundfax:4] Set("SIP/4001-0000000f", "FAXFILE=fax-20150620-152522.tif") in new stack
    -- Executing [s@macro-inboundfax:5] Set("SIP/4001-0000000f", "FAXOPT(ecm)=yes") in new stack
    -- Executing [s@macro-inboundfax:6] Set("SIP/4001-0000000f", "FAXOPT(headerinfo)=Received by MYCOMPANY 2015-06-20 15:25") in new stack
    -- Executing [s@macro-inboundfax:7] Set("SIP/4001-0000000f", "FAXOPT(localstationid)=5555551212") in new stack
    -- Executing [s@macro-inboundfax:8] Set("SIP/4001-0000000f", "FAXOPT(maxrate)=14400") in new stack
    -- Executing [s@macro-inboundfax:9] Set("SIP/4001-0000000f", "FAXOPT(minrate)=4800") in new stack
    -- Executing [s@macro-inboundfax:10] NoOp("SIP/4001-0000000f", "FAXOPT(ecm) : yes") in new stack
    -- Executing [s@macro-inboundfax:11] NoOp("SIP/4001-0000000f", "FAXOPT(headerinfo) : Received by MYCOMPANY 2015-06-20 15:25") in new stack
    -- Executing [s@macro-inboundfax:12] NoOp("SIP/4001-0000000f", "FAXOPT(localstationid) : 5555551212") in new stack
    -- Executing [s@macro-inboundfax:13] NoOp("SIP/4001-0000000f", "FAXOPT(maxrate) : 14400") in new stack
    -- Executing [s@macro-inboundfax:14] NoOp("SIP/4001-0000000f", "FAXOPT(minrate) : 4800") in new stack
    -- Executing [s@macro-inboundfax:15] NoOp("SIP/4001-0000000f", "**** RECEIVING FAX : fax-20150620-152522.tif ****") in new stack
    -- Executing [s@macro-inboundfax:16] Set("SIP/4001-0000000f", "FAX_DEST=/var/www/html/private/fax/received") in new stack
    -- Executing [s@macro-inboundfax:17] Set("SIP/4001-0000000f", "FAXDEST=/tmp") in new stack
    -- Executing [s@macro-inboundfax:18] DumpChan("SIP/4001-0000000f", "3") in new stack
    --
    -- Dumping Info For Channel: SIP/4001-0000000f:
    -- ================================================================================
    -- Info:
    -- Name=               SIP/4001-0000000f
    -- Type=               SIP
    -- UniqueID=           1434794122.15
    -- LinkedID=           1434794122.15
    -- CallerIDNum=        4001
    -- CallerIDName=       FaxVoip SoftPhone
    -- ConnectedLineIDNum= (N/A)
    -- ConnectedLineIDName=(N/A)
    -- DNIDDigits=         15555551212
    -- RDNIS=              (N/A)
    -- Parkinglot=         default
    -- Language=           en
    -- State=              Up (6)
    -- Rings=              0
    -- NativeFormat=       (ulaw)
    -- WriteFormat=        slin
    -- ReadFormat=         ulaw
    -- RawWriteFormat=     ulaw
    -- RawReadFormat=      ulaw
    -- WriteTranscode=     Yes (slin)->(ulaw)
    -- ReadTranscode=      No
    -- 1stFileDescriptor=  26
    -- Framesin=           1
    -- Framesout=          0
    -- TimetoHangup=       0
    -- ElapsedTime=        0h0m0s
    -- DirectBridge=       <none>
    -- IndirectBridge=     <none>
    -- Context=            macro-inboundfax
    -- Extension=          s
    -- Priority=           18
    -- CallGroup=
    -- PickupGroup=
    -- Application=        DumpChan
    -- Data=               3
    -- Blocking_in=        (Not Blocking)
    --
    -- Variables:
    -- MACRO_DEPTH=1
    -- FAXDEST=/tmp
    -- FAX_DEST=/var/www/html/private/fax/received
    -- FAXFILE=fax-20150620-152522.tif
    -- FILENAME=fax-20150620-152522
    -- MACRO_PRIORITY=4
    -- MACRO_CONTEXT=from-sip
    -- MACRO_EXTEN=15555551212
    -- SIPCALLID=af6dfc5a-ee0f-1910-9de1-e06995d7f913@dsk-388
    -- SIPDOMAIN=XX.XX.XX.XX
    -- SIPURI=sip:[email protected]:5065
    -- ================================================================================
    -- Executing [s@macro-inboundfax:19] ReceiveFAX("SIP/4001-0000000f", "/tmp/fax-20150620-152522.tif") in new stack
    -- Channel 'SIP/4001-0000000f' receiving FAX '/tmp/fax-20150620-152522.tif'
  == Using UDPTL CoS mark 5
    -- Channel 'SIP/4001-0000000f' FAX session '5' started
    -- FAX handle 0: [ 026.931800 ], entering CLOSING state
    -- FAX handle 0: [ 026.931866 ], entering CLOSING state
    -- Channel 'SIP/4001-0000000f' FAX session '5' is complete, result: 'SUCCESS' (FAX_SUCCESS), error: 'NO_ERROR', pages: 2, resolution: '204x98', transfer rate: '14400', remoteSID: ''
  == Spawn extension (macro-inboundfax, s, 19) exited non-zero on 'SIP/4001-0000000f' in macro 'inboundfax'
  == Spawn extension (from-sip, 15555551212, 4) exited non-zero on 'SIP/4001-0000000f'
2

There are 2 answers

6
Vivek Raj On

[fax-rx]
exten => _X.,1,Ringing()
exten => _X.,n,Answer()
exten => _X.,n,wait(10)
exten => fax,1,Verbose(got a Fax on ${EXTEN})
exten => fax,n,NoOp(**** FAX RECEIVE ****)
exten => fax,n,Set(GLOBAL(FAXCOUNT)=$[ ${GLOBAL(FAXCOUNT)} + 1 ])
exten => fax,n,Set(FAXCOUNT=${GLOBAL(FAXCOUNT)})
exten => fax,n,Set(FAXFILE=fax-${FAXCOUNT}-rx.tif)
exten => fax,n,Set(GLOBAL(LASTFAXCALLERNUM)=${CALLERID(num)})
exten => fax,n,Set(GLOBAL(LASTFAXCALLERNAME)=${CALLERID(name)})
exten => fax,n,NoOp(**** SETTING FAXOPT ****)
exten => fax,n,Set(FAXOPT(ecm)=yes)
exten => fax,n,Set(FAXOPT(headerinfo)=MY FAXBACK RX)
exten => fax,n,Set(FAXOPT(localstationid)=1234567890)
exten => fax,n,Set(FAXOPT(maxrate)=14400)
exten => fax,n,Set(FAXOPT(minrate)=2400)
exten => fax,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => fax,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => fax,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => fax,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => fax,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => fax,n,NoOp(**** RECEIVING FAX : ${FAXFILE} ****)
exten => fax,n,ReceiveFAX(/var/spool/asterisk/fax/${FAXFILE})
; Hangup! Print FAXOPTs
exten => h,1,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => h,n,NoOp(FAXOPT(filename) : ${FAXOPT(filename)})
exten => h,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => h,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => h,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => h,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => h,n,NoOp(FAXOPT(pages) : ${FAXOPT(pages)})
exten => h,n,NoOp(FAXOPT(rate) : ${FAXOPT(rate)})
exten => h,n,NoOp(FAXOPT(remotestationid) : ${FAXOPT(remotestationid)})
exten => h,n,NoOp(FAXOPT(resolution) : ${FAXOPT(resolution)})
exten => h,n,NoOp(FAXOPT(status) : ${FAXOPT(status)})
exten => h,n,NoOp(FAXOPT(statusstr) : ${FAXOPT(statusstr)})
exten => h,n,NoOp(FAXOPT(error) : ${FAXOPT(error)})

2
MichelV69 On

You've got the right idea already ... put all your "after fax" processing here:

exten => h,1, NoOp(Completed...)

Since the ${FAXSTATUS} variable is a channel global, it persists until the end of the h extension processing. if ... then process based on it's status.