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_num=6475551212 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. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
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. On Mon, May 21, 2018 at 10:49 AM, D'Arcy Cain <darcy at vybenetworks.com> wrote:> 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_num=6475551212 > > 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. > > -- > D'Arcy J.M. Cain > Vybe Networks Inc. > http://www.VybeNetworks.com/ > IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com > > > > > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Check out the new Asterisk community forum at: https://community.asterisk. > org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >-- A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects. ---Heinlein -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20180521/ef553f6d/attachment.html>
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:> 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_num=6475551212 > > 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. >
On 2018-05-21 08:04 PM, John Kiniston wrote:> 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.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? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
On 2018-05-22 02:17 AM, Yves wrote:> you could > > - use "global variables" > - use the asterisk built in databaseBoth of those seem difficult as the process is split between Asterisk and an external script.> - 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...)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. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
On 5/21/18 1:49 PM, D'Arcy Cain wrote:> I am having troubles with sending faxes. I hope someone can help me > work out a better method.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.