Looking For Better Fax Handling
I am having troubles with sending faxes. I hope someone can help me work out a better method.
Basically we have a special address that our users can send to. It winds up on our Asterisk server which runs a Python script that parses the message for attachments and the phone number from the recipient address. The attachments are converted to TIFF and stored in a folder with various information encoded into the file name such as phone number and retry information. That all works fine.
A separate process picks up the files and sends them using an AMI script like this:
Action: Originate Channel: SIP/provider/%(destination)s Context: LocalSets CallerID: Vybe Consulting Inc Fax Service <6475551212>
Exten: sendfax Priority: 1
Timeout: 30000
Variable: faxfile=%(faxfile)s Variable: uid=%(uid)s Variable: destination=%(destination)s Variable: sender_name=Vybe Consulting Inc Fax Service Variable: sender_numd75551212
It then renames the file encoding the next retry time and incrementing the number of retries.
The same script checks for files in a success folder and sends the users a confirmation message that the fax was sent. The files are moved into the success folder by Asterisk using this dialplan:
sendfax,1,Verbose(0,FAX ${faxfile} to ${destination})
same => n,Set(FAXOPT(headerinfo)=${sender_name})
same => n,Set(FAXOPT(localstationid)=${sender_num})
same => n,SendFax(${faxfile},d)
same => n,Set(STATUS=Status: ${FAXOPT(status)})
same => n,Set(STATUS=${STATUS}\nRemote ID: ${FAXOPT(remotestationid)})
same => n,Set(STATUS=${STATUS}\nMaxrate: ${FAXOPT(maxrate)})
same => n,Set(STATUS=${STATUS}\nMinrate: ${FAXOPT(minrate)})
same => n,Set(STATUS=${STATUS}\nECM: ${FAXOPT(ecm)})
same => n,Set(STATUS=${STATUS}\nnumber of pages: ${FAXOPT(pages)})
same => n,Set(STATUS=${STATUS}\nRate: ${FAXOPT(rate)})
same => n,Set(STATUS=${STATUS}\nResolution: ${FAXOPT(resolution)})
same => n,GotoIf($[“${FAXOPT(status)}” = “SUCCESS”]?faxok)
same => n,Set(STATUS=${STATUS}\nError: ${FAXOPT(error)})
same => n(faxok),Verbose(0,FAX ${destination} Status (S): ${STATUS})
same => n,Set(FAXNAME=${CUT(faxfile,/,6)})
same => n,Set(FILE(/fax_status/${FAXNAME})=${STATUS})
same => n,GotoIf($[“${FAXOPT(status)}” != “SUCCESS”]?faxfail)
same => n,System(/bin/mv ‘${faxfile}’ ‘/fax_success/${FAXNAME}’)
same => n,Set(CDR(userfield)=${destination})
same => n,Verbose(0,FAX to ${destination} charged to ${uid})
same => n(faxfail),Verbose(0,FAX ${destination} Status (F): ${STATUS})
same => n,Hangup()
My problem is that if the faxes get too big it starts sending it again before the previous one has finished. I can’t raise the retry limit too far because sometimes the receiver is busy and we have to retry in a reasonable time.
Is there a way to get a token from the AMI script that I can use to determine later if Asterisk is still busy with the fax before I try sending it again?
Or, am I approaching this all wrong? Is there a better method of doing this?
I am running Asterisk 13.19.0 on NetBSD/amd64 7.1.0.
7 thoughts on - Looking For Better Fax Handling
Lock files.
Create one when you start sending the fax, on your retry process check for a lock file and if one exists don’t retry.
you could
– use “global variables”
– use the asterisk built in database
– mv the file to temporary folder _before_ faxing (would be the most easy solution as you already know how to mv a file via asterisk…)
regards, yves
Am 21.05.2018 um 19:49 schrieb D’Arcy Cain:
Your suggestion is to create a lock file for each fax (there could be many concurrent ones) and have the dialplan remove it on either success or failure? That sounds doable. I will give that some thought.
Other than that, does my method seem like a reasonable approach?
Both of those seem difficult as the process is split between Asterisk and an external script.
True. This or John Kiniston’s idea of lock files could work. I guess I
would need to have some process to move it back if it is still there after an hour or so in case something went wrong. The same sort of thing would be needed for John’s solution as well.
It sure would be nice if I could query Asterisk to see if the fax process was still running.
Thanks.
of course you can query asterisk asterisk and look, if your fax is still running…:
asterisk -rx “fax show sessions” lists you all acive fax sessions…
yves
Am 22.05.2018 um 12:19 schrieb D’Arcy Cain:
—
I have a project that I like to use to send faxes. It might be able to drop into your environment pretty easily.
https://github.com/jkister/astelegraph
I use samba to get the files from the workstation to the server, but using SSH or email is just as easy — it’ll pick up files dropped in
/var/spool/asterisk/fax/raw.
—
Well, yes but how do I know which channel I am looking for? When I say
“I” I mean my program. I am sure that my brain can figure it out but my brain needs to be off doing other things.
—
D’Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/
IM:darcy@Vex.Net VoIP: sip:darcy@VybeNetworks.com
—