home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / voice.zip / V_MBX.CMD < prev    next >
OS/2 REXX Batch file  |  1996-09-09  |  30KB  |  846 lines

  1. /* V_MBX.CMD - Voice/Fax Answer Script for FaxWorks/PMfax (REXX) */
  2. /* 
  3.                   Keller Group Inc.  September 9, 1996
  4.    You may freely use or modify this script for use with licensed
  5.         products which are developed by Keller Group Inc.
  6.       For new scripts or to share your scripts with others,
  7.                  see http://www.kellergroup.com
  8. */
  9. /*******************************************************************
  10. V_MBX.CMD - Advanced voice/fax mailbox system
  11.  
  12. For use with any of the following Keller software configurations:
  13.   Stand-alone (single-line or multiline)
  14.   LAN Shared Mode
  15.   LAN Private Mode (with fax server as router & retrieval from server log)
  16.  
  17. Features:
  18.  
  19.   Callers can:
  20.      send a fax,
  21.      leave a voice message,
  22.      listen to an announcement, or
  23.      enter the special password to enter remote retrieval mode
  24.  
  25.   In the password-protected remote retrieval mode, you can do:
  26.      greeting modification - remotely update your greeting message
  27.      voice retrieval - get voice messages by phone
  28.      fax retrieval - get fax messages, or send them to a fax number
  29.      log retrieval - get a fax of your log (or the last part of it)
  30.      "fax on demand" from log - retrieve items from log using index
  31.  
  32.   You can also set configuration values to provide:
  33.      forwarding by fax - forward all received faxes to a fax number
  34.      forwarding by voice - forward all received voice messages to phone #
  35.      forwarding by email - forward received fax and/or voice via email
  36.        and also...
  37.      paging by beeper - notify you by pager when voice or fax is received
  38.      paging by voice - notify you by calling and playing a voice message
  39.      paging by fax - notify you by sending a fax to a designated fax # 
  40.  
  41. See also:
  42.     V_MBXLAN.CMD - Advanced voice/fax mailbox system (LAN multiuser)
  43.  
  44. DESCRIPTION:
  45. -----------
  46.  
  47. This script plays your outgoing message (OGM).  The caller can press
  48. the # or * key to skip the OGM and immediately record their message,
  49. otherwise the script will provide a beep and record the caller's
  50. message if no special action is taken.
  51.  
  52. If the call is from a fax device and your fax hardware detects the
  53. caller's fax (CNG) tones, the script automatically receives the fax.
  54.  
  55. If the caller enters '2' during playing of the OGM, the script plays
  56. the "announcement" and then returns to the OGM again so that the
  57. caller can leave a message on the same call.
  58.  
  59. If the caller enters '9' during or immediately after the playing of
  60. the OGM and then enters the user-configurable access code followed by
  61. the # key, the script enters its "remote retrieval" mode so the
  62. caller can hear received voice messages, have received faxes sent to
  63. them via fax, and other features.  When in this mode, the keys on the
  64. telephone do the following:
  65.  
  66.    1 - HELP       - Play help message which describes these commands
  67.    3 - GREETING   - Enter new outgoing message (change greeting)
  68.  
  69.    4 - PREV MSG   - Play previous voice message
  70.    5 - REPLAY MSG - Play current voice message (again)
  71.    6 - NEXT MSG   - Play next voice message
  72.  
  73.    7 - GET FAXES  - Retrieve new fax messages by fax
  74.    8 - GET LOG    - Retrieve fax log by fax
  75.    9 - FOD LOG    - Retrieve voice/fax msgs from log ("fax-on-demand")
  76.  
  77. Other features are controlled by setting "script variables" as
  78. described below.  These values can cause the script to do automatic
  79. forwarding by fax, voice or email and automatic paging via beeper,
  80. voice or fax.
  81.  
  82. USAGE INSTRUCTIONS:
  83. ------------------
  84. You must be using the program with supported voice/fax hardware to
  85. use this script.  Consult the README.DOC file for tested voice/fax
  86. hardware and recommended configuration settings for your hardware.
  87. Before using this script, first test your system with our built-in
  88. voice answering machine feature by enabling "Voice" and setting the
  89. "Answer script" to * (an asterisk character) on the Voice page of the
  90. Settings notebook.  If you are using supported voice/fax hardware
  91. with the proper configuration settings, you can then use
  92. "Fax/Receive/All calls" mode to answer calls, play the outgoing
  93. message (OGM), and record a voice message (or receive a fax).
  94.  
  95. Then, to change to this advanced script, specify the full pathname of
  96. this file in the "Answer script" field on the Voice page of the
  97. settings notebook.
  98.  
  99. NOTE: The script expects to find the LIB_FOD.CMD file and its Wave
  100. audio files in the fax program (EXE) directory.  The script also uses
  101. Wave files from the c:\mmos2\sounds directory for special effects.
  102.  
  103. SCRIPT VARIABLES:
  104. ----------------
  105. The following script variable is used by this script.  Script
  106. variables are set on the Voice page of the Settings Notebook.
  107.  
  108. General:
  109.  
  110.     OGM - Pathname of the "outgoing message" file which is played
  111.     to the caller.  By default, the program sets OGM to be the
  112.     file OGM.WAV in the program directory.
  113.     Example: OGM = C:\FAX\OGM.WAV
  114.  
  115.     CODE - Access code for retrieving messages or changing
  116.     settings.  By default, the program sets CODE to be 42.  You
  117.     can change this to be any number of up to 5 digits in length.
  118.     Example: CODE = 42
  119.  
  120.     CALLER - (optional, default "Person") - Name of the person
  121.     who will be using the access code to retrieve messages/faxes
  122.     by phone.  This is used for addressing faxes when the
  123.     caller uses the access code for remote retrieval.
  124.     Example: CALLER = Jim Smith
  125.  
  126.     LOGMAXLINE - (optional, default 56) - Maximum number of log
  127.     entries, from the end of the log, to be sent to the caller
  128.     when they retrieve the log by fax.  If set to 0, then
  129.     the entire log is sent.
  130.     Example: LOGMAXLINE = 120
  131.  
  132.     EMAILCMD - (optional) - The command line to be executed to send a
  133.     fax, voice or text file via email.  We append the file pathname
  134.     to the end of this command line and execute it to tell your email
  135.     software to send the file.  If the EMAILPARAM script variable is
  136.     set, then it is appended to the command line following the file
  137.     pathname (which can be used to add additional parameters).
  138.     Email support requires the use of an email package which provides
  139.     a command line interface and is configured to automatically
  140.     send the email which is submitted to it.
  141.     Example: To demo by inserting into our log rather than emailing:
  142.            EMAILCMD = c:\fax\fxrcv -rcvd
  143.     Example for Post Road Mailer version 2.0 using its PRMFAX.EXE:
  144.            EMAILCMD = c:\postroad\prmfax
  145.            EMAILPARAM = "yourid@ibm.net" "EMAIL FAX"
  146.  
  147. Forwarding:
  148.  
  149.     FWDFAX - (optional) - A fax number.  If specified, received
  150.     faxes are automatically forwarded to the specified fax
  151.     number.  All faxes are also kept in the fax log.
  152.     Example: FWDFAX = 1 612 555-5555
  153.  
  154.     FWDVOICE - (optional) - A voice number.  If specified,
  155.     received voice messages are automatically forwarded to the
  156.     specified number.  Add comma characters to the end of the
  157.     number if additional pauses are desired before the message is
  158.     played.  This can be used to pass a voice message along to a
  159.     second answering machine or a cellular phone, but delivery is
  160.     not guaranteed since dialing delays, busy signals and other
  161.     events may interfere.
  162.     Example: FWDVOICE = 555-5555
  163.  
  164.     FWDEMAIL - (optional) - Set to FAX, VOICE or ALL.  If
  165.     specified (and if the EMAILCMD script variable is also
  166.     specified), received faxes, voice messages or both will be
  167.     forwarded by emailing the file using the EMAILCMD command
  168.     line.
  169.     Example: FWDEMAIL = ALL
  170.  
  171. Paging:
  172.  
  173.     PAGEBEEPFAX - (optional) - If paging is desired upon receipt of each
  174.     fax, this script variable is defined and is set to the dial string
  175.     which to be called for paging.  (See Paging below.)
  176.  
  177.     PAGEBEEPVOICE - (optional) - If paging is desired upon receipt of
  178.     each voice message, this script variable is defined and is set to
  179.     the dial string which to be called for paging.  (See Paging below.)
  180.  
  181.     PAGEVOICE - (optional) - A voice number.  If specified,
  182.     the system calls this number and plays the RCVD_FAX.WAV or
  183.     RCVD_MSG.WAV voice prompt file.  Add comma characters to the
  184.     end of the number if additional pauses are desired before the
  185.     message is played.
  186.     Example: PAGEVOICE = 555-5555
  187.  
  188.     PAGEFAX - (optional) - A fax number.  If specified, the
  189.     system sends a fax to this number to say that a fax or voice
  190.     message was received.  
  191.     Example: PAGEFAX = 1 612 555-5555
  192.  
  193. PAGING:
  194. ------
  195. You can have the script call your pager if you wish to be notified
  196. when a call or fax is received.  To enable paging, define and set the
  197. PAGEBEEPFAX or PAGEBEEPVOICE script variables on the Voice page of
  198. the Settings notebook.
  199.  
  200. The value of the script variable is the dial string for calling and
  201. using your paging system.  The value should include:
  202.  
  203.     1) the telephone number of your paging system,
  204.  
  205.     2) several commas (each comma delays for 2 seconds - enter
  206.     the number of commas required for the proper delay for your
  207.     paging system),
  208.  
  209.     3) your Pager ID followed by another comma (if your paging
  210.     system uses IDs to identify a specific pager - paging systems
  211.     which use a unique telephone number for each pager will not
  212.     require this step),
  213.  
  214.     4) the page message (your telephone number or some number
  215.     to show you that you have received a fax or voice message).
  216.  
  217. For example, for a paging system which does not use Pager IDs, the
  218. value might be of the form "PAGEBEEPVOICE=555-5555,,,,555-1234".  For
  219. a paging system which uses Pager IDs where your Pager ID is 123456,
  220. the value might be "PAGEBEEPVOICE=1-800-555-5555,,,,123456,555-1234".
  221.  
  222. VOICE PROMPT FILES:
  223. ------------------
  224. The script expects to find the LIB_FOD.CMD file and the following
  225. Wave audio files in the fax program (EXE) directory.  The script also
  226. uses Wave files from the c:\mmos2\sounds directory for special effects.
  227.  
  228. To record or modify your own voice prompt files, use your OS/2
  229. Multimedia microphone and record voice prompts using the "Fax/New
  230. message" command then save them to a .WAV file with the "Fax/Save
  231. file/Wave" command.  You can also use the OS/2 Digital Audio program
  232. to record, save, edit and modify the Wave files (be sure to use
  233. "Type" of Mono, 8-bit, 11.025 kHz).
  234.  
  235.     OGM.WAV - The main "outgoing message" as recorded with the
  236.     Utilities/Outgoing message command.
  237.  
  238.     ENTR_COD.WAV - Short: "Enter code."
  239.     Long: "Please enter your access code and the # key."
  240.  
  241.     ENTR_CMD.WAV - Short: "Enter command."
  242.     Long: "To play current message press 5, to play next message
  243.     press 6, to play previous message press 4...."
  244.  
  245.     ENTR_MSG.WAV - Short: "Enter message, then press # key."
  246.     Long: "Please leave your message at the beep.  Press # key to end."
  247.  
  248.     ANNOUNC.WAV - Short: "No announcement."
  249.     Long: "Our annoucement for this week is...."
  250.  
  251.     HELP.WAV - "Press 3 to change outgoing message, 4 for previous..."
  252.  
  253.     NO_MSGS.WAV - Short: "No more messages."
  254.  
  255.     RCVD_FAX.WAV - Short: "A fax has been received."
  256.  
  257.     RCVD_MSG.WAV - Short: "A voice message has been received."
  258.  
  259. And used by any fax retrieval actions (LIB_FOD.CMD procedure):
  260.  
  261.     ENTR_DOC.WAV - Short: "Enter document number and # key, or
  262.     press the # key if done."
  263.     Long: "Please enter the document number followed by the # key,
  264.     or press the # key if done.  To receive an index of available
  265.     documents, enter document 1000."
  266.  
  267.     HOW_FAX.WAV - Short: "Enter 1 if calling from fax machine, 2
  268.     if not."
  269.     Long: "If you are calling from your fax machine and are ready
  270.     to receive the fax press 1, to send the fax to a different
  271.     number press 2." 
  272.  
  273.     ENTR_FAX.WAV - Short: "Enter fax number and # key."
  274.     Long: "Please enter your fax number followed by the # key,
  275.     including 1 and area code if this is not a local call." 
  276.  
  277.     NO_FILE.WAV - Short: "File not found."
  278.     Long: "That document was not found, please try again."
  279.  
  280.     WAIT.WAV - Short: "Please wait."
  281.     Long: "Please wait while we process your request."
  282.  
  283.     THANKYOU.WAV - Short: "Thank you."
  284.  
  285. TO MODIFY THE SCRIPT:
  286. --------------------
  287. The script is REXX and uses calls from the Keller REXX API which are
  288. automatically loaded into the OS/2 REXX environment by the retail
  289. versions of Keller's fax products (version 3.0 and later).  See the
  290. Reference Manual for documentation of the FxRx and FxLn calls.  You
  291. may modify the script as desired, and then use it as the "Answer
  292. script" with Keller fax software products.
  293.  
  294. Note - For voice message retrieval, this script uses the RCVD/N_RCVD
  295. mode of FxRxFind, which means that it will report only those voice
  296. messages which have been received but not already played at the
  297. computer and not previously retrieved via phone.  If desired, you can
  298. change this to use READ/N_READ mode which will report all voice
  299. messages which have not been previously retrieved via phone (even
  300. those that have been played at the computer).  You can also retrieve
  301. any desired voice message, whether or not it has been played or
  302. retrieved, using the "fax log" and "fax-on-demand" features in this
  303. script which allow you to play any voice message by its index number.
  304.  
  305. Note - For fax message retrieval, this script uses the RCVD/N_RCVD
  306. mode of FxRxFind, which means that it will report only those faxes
  307. which have been received but not already viewed at the computer and
  308. not previously retrieved via phone.  If desired, you can change this
  309. to use READ/N_READ mode which will report all faxes which have not
  310. been previously retrieved via phone (even those that have been viewed
  311. at the computer).  You can also retrieve any desired fax, whether or
  312. not it has been viewed or retrieved, using the "fax log" and
  313. "fax-on-demand" features in this script which allow you to retrieve
  314. any fax by its index number.  In version 3 of the fax program,
  315. viewing a received fax changes its status from Rcvd to Read, but
  316. printing of faxes does NOT change the status, so you can auto-print
  317. all received faxes at the computer and still retrieve them as "Rcvd"
  318. faxes by phone. 
  319.  
  320. TO USE WITH MULTILINE VERSIONS:
  321. ------------------------------
  322. This script can be used with multiline versions of Keller fax
  323. software.  All lines are handled identically, so calls can be
  324. received on any of your "receive" lines.  If you prefer to have
  325. different lines be handled differently you can modify the script to
  326. test the LID variable.  For example, to have line 1 immediately jump
  327. to the "please enter your message" prompt, you could add a line like
  328. the following after the "call FxLnInit" line in the script: "if LID =
  329. 1 then signal voice" where "voice" is a label in the script.
  330.  
  331. *******************************************************************/
  332.  
  333.   call FxLnInit
  334.  
  335.   VOXDIR = FxRxPath( 'EXE' )    /* get voice prompts from exe dir */
  336.   LIBDIR = FxRxPath( 'EXE' )    /* get REXX subroutines from exe dir */
  337.   FODPROCEDURE = LIBDIR||'lib_fod.cmd'  /* use this external procedure */
  338.  
  339.   /* default values for script variables */
  340.   if CALLER = 'CALLER' then CALLER = 'Person'
  341.   if LOGMAXLINE = 'LOGMAXLINE' then LOGMAXLINE = 56
  342.   if EMAILCMD = 'EMAILCMD' then EMAILCMD = ''
  343.   if EMAILPARAM = 'EMAILPARAM' then EMAILPARAM = ''
  344.  
  345.   if FWDFAX = 'FWDFAX' then FWDFAX = ''
  346.   if FWDVOICE = 'FWDVOICE' then FWDVOICE = ''
  347.   if FWDEMAIL = 'FWDEMAIL' then FWDEMAIL = ''
  348.  
  349.   if PAGEBEEPFAX = 'PAGEBEEPFAX' then PAGEBEEPFAX = ''
  350.   if PAGEBEEPVOICE = 'PAGEBEEPVOICE' then PAGEBEEPVOICE = ''
  351.   if PAGEVOICE = 'PAGEVOICE' then PAGEVOICE = ''
  352.   if PAGEFAX = 'PAGEFAX' then PAGEFAX = ''
  353.  
  354.  
  355. hello:
  356.   call FxLnMsg 'OGM'                /* show in status window */
  357.     if result = 'NOTOK' then signal byebye
  358.   call FxLnPlay OGM                /* play greeting prompt */
  359.     if result = 'NOTOK' then signal byebye
  360.     if result = 'FAX' then signal fax
  361.     if result = 'DATA' then signal data
  362.  
  363.   call FxLnDtmf 1, 3, 'digits'            /* get key, if any... */
  364.     if result = 'NOTOK' then signal byebye
  365.     if result = 'FAX' then signal fax
  366.     if result = 'DATA' then signal data
  367.     if result <> 'DTMF' then signal voice
  368.  
  369.   if digits = 2 then signal announce        /* use key value... */
  370.   if digits = 9 then signal accesscode
  371.  
  372.  
  373. voice:                    /* take voice message, hangup */
  374.   call FxLnMsg "Record Msg"
  375.   call FxLnTone 1850
  376.     if result = 'NOTOK' then signal byebye
  377.   call FxLnDtmf        /* flush buffer */
  378.   call FxLnRecord
  379.     if result = 'NOTOK' then signal byebye
  380.     if result = 'FAX' then signal fax
  381.     if result = 'DATA' then signal data
  382.   /* caller can hang up or press a key to end recording */
  383.   call FxLnTone 1850, 1850, 1850
  384.   call Forwarding 'voice'
  385.   call Paging 'voice'
  386.   signal out
  387.  
  388.  
  389. fax:                    /* receive fax and hangup */
  390.   call FxLnReceive
  391.   if result = 'OK' then do
  392.     call Forwarding 'fax'
  393.     call Paging 'fax'
  394.   end
  395.   signal out
  396.  
  397.  
  398. data:                    /* report data call, hangup */
  399.   call FxLnMsg 'Data call, oh well...'
  400.   LREC.!Status = '*Data!'   /* log status of call */
  401.   signal out
  402.  
  403.  
  404. announce:                /* play annoucement, restart */
  405.   call FxLnMsg "Announcement"
  406.   call FxLnPlay VOXDIR||'ANNOUNC.WAV'
  407.     if result = 'NOTOK' then signal byebye
  408.   signal hello
  409.  
  410.  
  411. accesscode:
  412.   call FxLnMsg 'Code ???'        /* get & check access code */
  413.   call FxLnPlay VOXDIR||'ENTR_COD.WAV'
  414.     if result = 'NOTOK' then signal byebye
  415.   digits = GetNumber( 6, 10 )
  416.   if digits <> CODE then signal evil
  417.  
  418.   call FxLnMsg 'Code Mode'
  419.   call FxLnVout 'Valid code entered'
  420.   call FxRxBeep 354, 393, 295, 354, 0, 393
  421.  
  422.   call FxRxFind 'MSG', 'N_RCVD'        /* get # of new voice msgs */
  423.   if result = 'NOTOK' then do
  424.     call FxLnPlay 'c:\mmos2\sounds\BOING.wav'
  425.     signal byebye
  426.   end
  427.   n = result
  428.  
  429.   /* if no messages... stay in command mode for other (fax) commands */
  430.   if n = 0 then do
  431.         call FxLnPlay VOXDIR||'NO_MSGS.WAV'
  432.         if result = 'NOTOK' then signal byebye
  433.   end
  434.  
  435.   i = n                /* Play 1 beep for each voice message */
  436.   call FxLnMsg 'Code Mode' n 'messages'
  437.   call FxLnVout 'Beep' n 'times'
  438.   do while i > 0
  439.     call FxLnTone 2100
  440.     i = i - 1
  441.   end
  442.  
  443.   call FxLnVout 'Enter message loop'
  444.   i = 0
  445.   j = 0
  446.   do forever
  447.     call FxLnMsg 'Waiting for next command'
  448.     call FxLnPlay VOXDIR||'ENTR_CMD.WAV'
  449.     call FxLnDtmf 1, 30, 'digits'
  450.     if result <> 'DTMF' then do
  451.       signal goodbye
  452.     end
  453.     else do
  454.       call FxLnMsg 'Code Mode command' digits
  455.       call FxLnVout 'Command' digits 'entered'
  456.  
  457.  
  458.       if digits = '1' then do            /* 1 = Play help msg */
  459.         call FxLnVout 'Help message'
  460.         call FxLnPlay VOXDIR||'HELP.WAV'
  461.       if result = 'NOTOK' then signal byebye
  462.         iterate
  463.       end
  464.  
  465.  
  466.       if digits = '3' then do            /* 3 = Enter outgoing msg */
  467.         call FxLnVout 'Enter outgoing message'
  468.         call FxLnPlay VOXDIR||'ENTR_MSG.WAV'
  469.       if result = 'NOTOK' then signal byebye
  470.         call FxLnTone 1850
  471.       if result = 'NOTOK' then signal byebye
  472.         call FxLnDtmf        /* flush buffer */
  473.         call FxLnRecord OGM
  474.       if result = 'NOTOK' then signal byebye
  475.         call FxLnTone 1850, 1850, 1850
  476.         call FxLnDtmf        /* flush buffer */
  477.         call FxLnPlay OGM
  478.       if result = 'NOTOK' then signal byebye
  479.         iterate
  480.       end
  481.  
  482.  
  483.       if digits = '4' then do            /* 4 = Previous msg */
  484.         call FxLnVout 'Play previous message' i
  485.         if i <= 1
  486.     then call FxLnPlay VOXDIR||'NO_MSGS.WAV'
  487.     else do
  488.       i = i - 1
  489.           call FxLnMsg 'Code Mode command' digits 'Msg' list.i
  490.         call FxLnPlay list.i
  491.       end
  492.         iterate
  493.       end
  494.  
  495.  
  496.       if digits = '5' then do            /* 5 = Replay msg */
  497.         call FxLnVout 'Replay message' i
  498.         if i <= 0
  499.     then digits = '6'    /* replay = next if just starting */
  500.     else do
  501.           call FxLnMsg 'Code Mode command' digits 'Msg' list.i
  502.       call FxLnPlay list.i
  503.           iterate
  504.     end
  505.       end
  506.  
  507.  
  508.       if digits = '6' then do            /* 6 = Next message */
  509.         call FxLnVout 'Play next message' i j
  510.         if i = n 
  511.     then call FxLnPlay VOXDIR||'NO_MSGS.WAV'
  512.     else do
  513.         i = i + 1
  514.         if i > j then do
  515.         call FxRxFind 'MSG', 'RCVD', 'LREC'
  516.         call FxLnVout 'Found' LREC.!ID
  517.         list.i = LREC.!ID
  518.         j = i
  519.       end
  520.           call FxLnMsg 'Code Mode command' digits 'Msg' list.i
  521.         call FxLnPlay list.i
  522.         end
  523.         iterate
  524.       end
  525.  
  526.  
  527.       if digits = '7' then do            /* 7 = send rcvd faxes */
  528.         call FxLnVout 'Send rcvd faxes'
  529.         call FxLnMsg 'Code Mode command' digits
  530.         call FxRxFind 'FAX', 'N_RCVD'        /* get # of new faxes */
  531.         if result = 'NOTOK' then do
  532.           call FxLnPlay 'c:\mmos2\sounds\BOING.wav'
  533.           signal byebye
  534.         end
  535.         nfax = result
  536.         if nfax = 0 then do
  537.           call FxLnPlay VOXDIR||'NO_MSGS.WAV'
  538.           if result = 'NOTOK' then signal byebye
  539.         end
  540.         else do
  541.           ifax = nfax        /* Get faxes into list and beep per fax */
  542.           faxlist = ''
  543.           flist = ''
  544.           call FxLnMsg 'Code Mode' nfax 'faxes'
  545.           call FxLnVout 'FaxBeep' nfax 'times'
  546.           do while ifax > 0
  547.             call FxLnTone 2100
  548.             ifax = ifax - 1
  549.             call FxRxFind 'FAX', 'RCVD', 'LREC'
  550.             call FxLnVout 'Found' LREC.!ID
  551.             faxlist = AddToCsvList( LREC.!ID, faxlist )
  552.             flist = flist LREC.!ID
  553.           end
  554.           /* call our FOD procedure to do the faxing */
  555.           FODPARAMS = "FxRxPath( 'LOG' ), VOXDIR, , CALLER, faxlist," ,
  556.             "'As you requested, your received faxes are attached:' flist," ,
  557.             "'Remote fax retrieval...'"
  558.           interpret 'call' "'"||FODPROCEDURE||"'" FODPARAMS
  559.           if result = 'BYEBYE' then signal BYEBYE
  560.           if result = 'OUT' then signal OUT
  561.         end
  562.         iterate
  563.       end
  564.  
  565.  
  566.       if digits = '8' then do            /* 8 = send log */
  567.         call FxLnVout 'Send log'
  568.         call FxLnMsg 'Code Mode command' digits
  569.         call FxLnPlay VOXDIR||'WAIT.WAV'
  570.       if result = 'NOTOK' then signal byebye
  571.         call SendLog
  572.           if result = 'BYEBYE' then signal BYEBYE
  573.           if result = 'OUT' then signal OUT
  574.         iterate
  575.       end
  576.  
  577.  
  578.       if digits = '9' then do            /* 9 = FOD from log */
  579.         call FxLnVout 'FOD from log'
  580.         call FxLnMsg 'Code Mode command' digits
  581.         FODPARAMS = "FxRxPath( 'LOG' ), VOXDIR, , CALLER, , ," ,
  582.                "'FOD Retrieval...'"
  583.         interpret 'call' "'"||FODPROCEDURE||"'" FODPARAMS
  584.           if result = 'BYEBYE' then signal BYEBYE
  585.           if result = 'OUT' then signal OUT
  586.         iterate
  587.       end
  588.  
  589.  
  590.       if digits = '*' | digits = '#' then do
  591.         signal goodbye
  592.       end
  593.  
  594.  
  595.       /* otherwise, if none were matched... */
  596.       call FxLnVout 'Unknown command' i
  597.       call FxLnPlay 'c:\mmos2\sounds\EEERRUPP.wav'
  598.       iterate
  599.  
  600.     end
  601.   end
  602.  
  603.  
  604. goodbye:
  605.   call FxLnVout 'Exit Code Mode'
  606.   call FxLnPlay 'c:\mmos2\sounds\DRUMROLL.wav'
  607.   signal byebye
  608.  
  609.  
  610. evil:
  611.   call FxLnVout 'Bad code entered:' digits 'vs' CODE
  612.   call FxLnPlay 'c:\mmos2\sounds\BOO.wav'
  613.   call FxRxBeep 1318, 1396, 1318, 1090, 1318, 1396, 1318, 1090
  614.   signal byebye
  615.  
  616.  
  617. byebye:                    /* called for error cases */
  618.   LREC.!Status = ''            /* don't log anything */
  619.   signal out
  620.  
  621.  
  622. out:                    /* clean up and quit */
  623.   call FxLnTerm
  624.   exit
  625.  
  626.  
  627. /************************ Procedures ************************/
  628.  
  629.  
  630. GetNumber: procedure
  631.   /* Gets DTMF input until # or * key or "digits" are entered. */
  632.   /* TimeOut is seconds to wait for each digit (default 15).       */
  633.   parse arg digits, TimeOut
  634.   number = ''
  635.   if TimeOut = '' then TimeOut = 15  /* default to 15 seconds */
  636.   do digits
  637.     call FxLnDtmf 1, TimeOut, 'newkey'
  638.       if result <> 'DTMF' | newkey = '#' | newkey = '*' then leave
  639.     number = number||newkey
  640.   end
  641.   return number
  642.  
  643.  
  644. TmpFile: procedure
  645.   /* Generate a unique base file name using seconds since midnight */
  646.   return 'TMP'||time( S )
  647.  
  648.  
  649. AddToCsvList: procedure
  650.   /* returns a comma-separated value list with item added */
  651.   parse arg item, list
  652.   if list = ''
  653.     then list = item
  654.     else list = list||','||item
  655.   return list
  656.  
  657.  
  658. SendLog:    /* sends the log file by fax */
  659.   tmp1 = VOXDIR||TmpFile()||'.TXT'
  660.   tmp2 = VOXDIR||TmpFile()||'.FAX'
  661.   log = FxRxPath( 'LOG' )||'fax.log'
  662.  
  663.   call LineOut tmp1, 'Fax Log   ' Date('W') ' '||Date('N') ' ' Time('C')
  664.   call LineOut tmp1, ''
  665.   call LineOut tmp1, ,
  666.        'Type ID      Date    Time  Pg Status Elpsd  Name/RemoteID/CallerID'
  667.   call LineOut tmp1, ''
  668.  
  669.   if LOGMAXLINE <= 0 then do /* send the entire fax log */
  670.     do while Lines( log ) > 0
  671.       record = LineIn( log )        /* read a record from log */
  672.       if FxRxParseLog( record, 'lrec' ) = OK then do
  673.         call LogRpt tmp1
  674.       end
  675.     end
  676.   end
  677.   else do /* send the last x lines from the log */
  678.     head = 1
  679.     tail = 1
  680.     do while Lines( log ) > 0    /* collect last x lines */
  681.       buf.head = LineIn( log )
  682.       head = head + 1
  683.       if head > LOGMAXLINE then head = 1
  684.       if head = tail then tail = tail + 1
  685.       if tail > LOGMAXLINE then tail = 1
  686.     end
  687.     if tail <> head & FxRxParseLog( buf.head, 'lrec' ) = OK then do
  688.       call LogRpt tmp1
  689.     end
  690.     do while tail <> head
  691.       if FxRxParseLog( buf.tail, 'lrec' ) = OK then do
  692.         call LogRpt tmp1
  693.       end
  694.       tail = tail + 1
  695.       if tail > LOGMAXLINE then tail = 1
  696.     end
  697.   end
  698.   rc = LineOut( log )            /* close the files */
  699.   rc = LineOut( tmp1 )
  700.   call FxRxTextToFax tmp1, tmp2        /* convert text to fax */
  701.   /* call our FOD procedure to do the faxing */
  702.   FODPARAMS = "FxRxPath( 'LOG' ), VOXDIR, , CALLER, tmp2," ,
  703.           "'As you requested, the log is attached.', 'Log retrieval...'"
  704.   interpret 'call' "'"||FODPROCEDURE||"'" FODPARAMS
  705.   fodresult = result
  706.   call FxLnVout 'Deleting:' tmp1
  707.   'DEL "'||tmp1||'"'
  708.   call FxLnVout 'Deleting:' tmp2
  709.   'DEL "'||tmp2||'"'
  710.   return fodresult
  711.  
  712.  
  713. LogRpt:
  714.   /* Using global lrec., write a report line to a file */
  715.   parse arg Rfile
  716.  
  717.   if BitTest( lrec.!Flags, 256 ) then mtype = 'MSG'
  718.   else if BitTest( lrec.!Flags, 512 ) then mtype = 'Txt'
  719.   else if BitTest( lrec.!Flags, 1024 ) then mtype = 'Dat'
  720.   else mtype = 'Fax'
  721.  
  722.   if lrec.!Company = ''
  723.   then namestr = lrec.!Name
  724.   else namestr = lrec.!Name||', '||lrec.!Company
  725.  
  726.   if lrec.!Pages = 0
  727.   then pagestr = ''    /* don't show 0 pages */
  728.   else pagestr = lrec.!Pages
  729.       
  730.   call LineOut Rfile, mtype left( lrec.!ID, 6 ) ,
  731.          left( lrec.!Date, 9 ) left( lrec.!Time, 5 ) ,
  732.          right( pagestr, 2 ) left( lrec.!Status, 6 ) ,
  733.          right( lrec.!Elapsed, 5) ' '||strip( left( namestr, 46 ) )
  734.   return
  735.  
  736.  
  737. BitTest: procedure
  738.   /* Given a number and a bit number, return 1 if bit is set */
  739.   parse arg value, bit
  740.   return (value % bit) // 2
  741.  
  742.  
  743. Forwarding:
  744.   parse arg mode /* 'voice' or 'fax' */
  745.  
  746.   if mode = 'voice' then do
  747.  
  748.     /* voice forwarding */
  749.     if FWDVOICE <> '' then do
  750.       call DeliverVoice LREC.!ID FWDVOICE
  751.     end
  752.     /* email forwarding */
  753.     if EMAILCMD <> '' then do    /* using email? */
  754.       call FxLnVout 'FWDEMAIL=' FWDEMAIL 'EMAILCMD=' EMAILCMD
  755.       if FWDEMAIL = 'ALL' | FWDEMAIL = 'VOICE' then do
  756.         cmdstring = EMAILCMD '"'||FxRxIndexToFax( LREC.!ID )||'"' EMAILPARAM
  757.         cmdstring
  758.         call FxLnVout 'rc=' rc 'for' cmdstring
  759.       end
  760.     end
  761.   end
  762.  
  763.   else if mode = 'fax' then do
  764.     /* fax forwarding */
  765.     if FWDFAX <> '' then do
  766.       /* Send with default cover sheet and default "From" information */
  767.       call FxRxQueue LREC.!ID, ,
  768.          'TO='||CALLER||' at fax: '||FWDFAX||',,'||FWDFAX, ,
  769.          'INFO="Forwarded fax is attached.",*,"Forwarding fax...",*,1,2', ,
  770.          'FROM=*,*,*,*'
  771.     end
  772.     /* email forwarding */
  773.     if EMAILCMD <> '' then do    /* using email? */
  774.       call FxLnVout 'FWDEMAIL=' FWDEMAIL 'EMAILCMD=' EMAILCMD
  775.       if FWDEMAIL = 'ALL' | FWDEMAIL = 'FAX' then do
  776.         cmdstring = EMAILCMD '"'||FxRxIndexToFax( LREC.!ID )||'"' EMAILPARAM
  777.         cmdstring
  778.         call FxLnVout 'rc=' rc 'for' cmdstring
  779.       end
  780.     end
  781.  
  782.   end
  783.   return
  784.  
  785.  
  786. DeliverVoice: procedure expose LREC.
  787.   /* given a message (id# or file) and phone number, call the number */
  788.   /* and play message.  Protects LREC record while doing so.         */
  789.   parse arg msg fwdnum
  790.   call FxLnVout 'DELIVERVOICE =' msg fwdnum
  791.   call FxLnMsg 'Voice delivery of' msg 'to' fwdnum
  792.   logtmp = FxRxFormatLog( 'LREC' )    /* save the record */
  793.   do 3   /* retry in case of no dialtone, etc. */
  794.     call FxLnLine 'DIAL' fwdnum
  795.     if result = OK then do
  796.       call FxLnPlay msg
  797.       leave
  798.     end
  799.   end
  800.   call FxRxParseLog logtmp, 'LREC'    /* restore record  */
  801.   call FxLnVout 'Leaving DeliverVoice'
  802.   return
  803.  
  804.  
  805. DeliverBeeps: procedure
  806.   /* Given a phone number, call the number */
  807.   parse arg BeepNum
  808.   call FxLnMsg 'Delivery beeps to' BeepNum
  809.   do 3   /* retry in case of no dialtone, etc. */
  810.     call FxLnLine 'DIAL' BeepNum
  811.     if result = OK then leave
  812.   end
  813.   return
  814.  
  815.  
  816. Paging:
  817.   parse arg mode    /* 'voice' or 'fax' */
  818.  
  819.   call FxLnVout 'PAGING =' mode PAGEFAX PAGEVOICE
  820.   if PAGEFAX <> '' then do
  821.     if mode = 'fax'
  822.     then tmp = 'A fax was received.'
  823.     else tmp = 'A voice message was received.'
  824.     call FxRxQueue 'TO='||CALLER||' at fax: '||PAGEFAX||',,'||PAGEFAX, ,
  825.        'INFO='||'"'||tmp||'"'||',*,"Paging by fax...",*,1,2', ,
  826.        'FROM=*,*,*,*'
  827.   end
  828.  
  829.   if PAGEVOICE <> '' then do
  830.     if mode = 'fax' then do
  831.       call DeliverVoice VOXDIR||'RCVD_FAX.WAV' PAGEVOICE
  832.     end
  833.     else if mode = 'voice' then do
  834.       call DeliverVoice VOXDIR||'RCVD_MSG.WAV' PAGEVOICE
  835.     end
  836.   end
  837.  
  838.   if mode = 'fax' & PAGEBEEPFAX <> '' then do
  839.     call DeliverBeeps PAGEBEEPFAX
  840.   end
  841.   if mode = 'voice' & PAGEBEEPVOICE <> '' then do
  842.     call DeliverBeeps PAGEBEEPVOICE
  843.   end
  844.  
  845.   return
  846.