The docs for faxing seem a little light but I think I have managed to
put something together. It mostly works but I have a couple of
issues. The main one is identifying myself. Setting CALLERID doesn't
seem to have any effect.
How this works is that I have a script that calls Asterisk through
AMI, It defines a number of variables and does an originate. It looks
something like this:
Action: Originate
Channel: SIP/thinktel/%%(destination)s
Context: LocalSets
Exten: sendfax
Priority: 1
Timeout: 30000
Variable: faxfile=%%(faxfile)s
Variable: uid=%%(uid)s
Variable: destination=%%(destination)s
Variable: sender_name=%%(sender_name)s
Variable: sender_num=%%(sender_num)s
The variables are filled in based on who the fax was received from.
The extension looks like this. I added extra comments for
clarification.
; this extension is called via AMI
exten => sendfax,1,Verbose(0,FAX ${faxfile} to ${destination})
; something for the logs
same => n,Set(CDR(uid)=${uid})
; the user ID (uid) is a field added by us to track the user
; who sent the fax
same => n,Set(CDR(userfield)=NotSent)
; will be changed later if successful
same => n,Set(CALLERID(NAME)=${sender_name})
same => n,Set(CALLERID(NUM)=${sender_num})
; attempting to set caller ID but it doesn't work
same => n,Set(FAXOPT(headerinfo)=${sender_name})
same => n,Set(FAXOPT(localstationid=${sender_num})
; another attempt to identify ourselves
same => n,SendFax(${faxfile},d)
; faxfile is defined by AMI script
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)})
; create a string to send back to the user
; the "\n" adds a literal string and not a newline
same => n,GotoIf($["${FAXOPT(status)}" =
"SUCCESS"]?faxok)
same => n,Set(STATUS=${STATUS}\nError: ${FAXOPT(error)})
; if successful the this line is not added to the status
same => n(faxok),Verbose(0,${STATUS})
; put status into log
same => n,Set(FAXNAME=${CUT(faxfile,/,6)})
; sets the base name of the file
same =>
n,Set(FILE(/var/spool/asterisk/fax_status/${FAXNAME})=${STATUS})
; write status to file
same => n,GotoIf($["${FAXOPT(status)}" !=
"SUCCESS"]?faxfail)
; on failure skip the reset and go straight to hangup
same => n,System(/bin/mv '${faxfile}'
/var/spool/asterisk/fax_success/)
; move the file so that we don't try to send it again
same => n,Set(CDR(userfield)=${destination})
; replace this field with actual destination
same => n,Verbose(0,FAX charged to ${uid})
; for the log - actual billing uses the cdr table
same => n(faxfail),Hangup()
; all done
Please critique.
--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:darcy at Vex.Net
VoIP: sip:darcy at Vex.Net