home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / voice2.zip / V_MBX.CMD < prev    next >
OS/2 REXX Batch file  |  1997-06-19  |  32KB  |  910 lines

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