home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Fax / AVMN199D.LHA / avminstall / rexx / answervoice.avm < prev    next >
Encoding:
Text File  |  1995-08-19  |  14.2 KB  |  554 lines

  1. /* TITLE: avm:rexx/answervoice.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. answervoiceStart:
  23. parse arg servername faxscript datascript distinctivering 'CID$' acidname '$' acidnumber '$'
  24. call setclip(address() || 'FAXSCRIPT', faxscript)
  25. call setclip(address() || 'DATASCRIPT', datascript)
  26. call setclip(address() || 'CIDNAME', acidname)
  27. call setclip(address() || 'CIDNUMBER', acidnumber)
  28.  
  29. introtype = getclip('AVMIntroductionType')
  30. if upper(introtype) = 'DAYOFWEEK' then
  31.   intronumber = dayofweek2num()
  32. else if upper(introtype) = 'TIMEOFDAY' then
  33.   intronumber = timeofday2num()
  34. else if upper(introtype) = 'RANDOM' then
  35.   intronumber = random(1,7, time('s'))
  36. else if introtype = "" then
  37.   intronumber = 1
  38. else intronumber = introtype
  39. call playAVoiceErrorOK('avm:voices/intro'||intronumber)
  40.  
  41. startup:
  42. simple = getclip('AVMSimpleAnsweringMachine')
  43. if upper(simple) = 'YES' then call simplestartup
  44. else call multistartup
  45. exit
  46.  
  47. answervoiceDone:
  48. 'playvoice' 'avm:voices/Goodbye'
  49. call stdPlayXX(rc)
  50. exit
  51.  
  52. /* TITLE: avm:rexx/simplestdtail.avm */
  53. /* This is the standard tail */
  54. exit
  55.  
  56. exit
  57.  
  58. mailboxDir: procedure
  59.     parse arg mailbox
  60.  
  61.     return 'avmmbox:' || mailbox || '/'
  62.  
  63. logFile: procedure
  64.     parse arg mailbox, magiccookie
  65.  
  66.     return 'avmmbox:' || mailbox || '/logs/' || magiccookie
  67.  
  68. voiceFile: procedure
  69.     parse arg mailbox, magiccookie
  70.  
  71.         if (verify(magiccookie, '/:', 'M') = 0) then
  72.           return 'avmmbox:' || mailbox || '/voices/' || magiccookie
  73.         else
  74.           return magiccookie
  75.  
  76. makeUniqueFile: procedure
  77.     if arg() ~= 0 then do
  78.         rc = "makeUniqueFile: bad args"
  79.         signal error
  80.     end
  81.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  82.  
  83. convertToDate: procedure
  84.     if arg() ~= 1 then do
  85.         rc = "convertToDate: bad args"
  86.         signal error
  87.     end
  88.     parse arg timeInC
  89.  
  90.     actualTime = (timeInC - (2922)*86400) // (86400)
  91.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  92.  
  93.     return actualDate /* returning it in 'internal' format */
  94.  
  95. convertToTime: procedure
  96.     if arg() ~= 1 then do
  97.         rc = "convertToTime: bad args"
  98.         signal error
  99.     end
  100.     parse arg timeInC
  101.     
  102.     actualTime = (timeInC - (2922)*86400) // (86400)
  103.  
  104.     return actualTime
  105.  
  106. cTime: procedure
  107.     /* 2922 = 8*365 + 2 */
  108.     /* 86400 = 24*60*60 */
  109.     return (date('i')+2922)*86400 + time('s')
  110.  
  111. /* this returns a handle that you must use after initializing log. */
  112. initLogEntry: procedure expose log.
  113.     if arg() ~= 0 then do
  114.         rc = "initLogEntry: bad args"
  115.         signal error
  116.     end
  117.     
  118.     drop log.
  119.         log. = ''
  120.  
  121.         acidname = getclip(address() || 'CIDNAME')
  122.         acidnumber = getclip(address() || 'CIDNUMBER')
  123.  
  124.     /* 2922 = 8*365 + 2 */
  125.     /* 86400 = 24*60*60 */
  126.     log.time = (date('i')+2922)*86400 + time('s')
  127.     log.cidname = acidname
  128.     log.cidnumber = acidnumber
  129.  
  130.     return
  131.  
  132. loadLogEntry: procedure expose log.
  133.     if arg() ~= 2 then do
  134.         rc = "loadLogEntry: bad args"
  135.         signal error
  136.     end
  137.     parse arg mailbox, handle
  138.  
  139.         drop log.
  140.         log. = ''
  141.  
  142.     if ~exists(mailboxDir(mailbox)) then do
  143.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  144.         return
  145.     end
  146.  
  147.     opened = open(handle, logFile(mailbox, handle), 'r')
  148.         if opened then do
  149.         call showDebugger('Loading entry' logFile(mailbox, handle))
  150.         do while ~eof(handle)
  151.             line = readln(handle)
  152.             parse upper var line variable '=' value
  153.             log.variable = value
  154.         end
  155.         call close(handle)
  156.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  157.     return
  158.  
  159. /* pass a handle here */
  160. saveLogEntry: procedure expose log.
  161.     if arg() ~= 2 then do
  162.         rc = "saveLogEntry: bad args"
  163.         signal error
  164.     end
  165.     parse arg mailbox, handle
  166.  
  167.     if ~exists(mailboxDir(mailbox)) then do
  168.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  169.         return
  170.     end
  171.  
  172.     opened = open(handle, logFile(mailbox, handle), 'w')
  173.  
  174.     if opened then do
  175.         call showDebugger('Saving entry' logFile(mailbox, handle))
  176.         call writeln(handle, 'TYPE=' || log.type)
  177.         call writeln(handle, 'TIME=' || log.time)
  178.         call writeln(handle, 'LENGTH=' || log.length)
  179.  
  180.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  181.  
  182.         call writeln(handle, 'CIDNAME=' || log.cidname)
  183.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  184.  
  185.         call writeln(handle, 'COMMENT=' || log.comment)
  186.  
  187.         call writeln(handle, 'FILENAME=' || log.filename)
  188.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  189.  
  190.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  191.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  192.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  193.  
  194.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  195.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  196.  
  197.         call close(handle)
  198.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  199.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  200.  
  201.     return
  202.  
  203. /* pass a handle here */
  204. updateLogEntry: procedure expose log.
  205.     if arg() ~= 2 then do
  206.         rc = "updateLogEntry: bad args"
  207.         signal error
  208.     end
  209.     parse arg mailbox, handle
  210.  
  211.     if ~exists(mailboxDir(mailbox)) then do
  212.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  213.         return
  214.     end
  215.  
  216.     if ~exists(logFile(mailbox, handle)) then do
  217.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  218.         return
  219.     end
  220.     opened = open(handle, logFile(mailbox, handle), 'w')
  221.  
  222.     if opened then do
  223.         call showDebugger('Updating entry' logFile(mailbox, handle))
  224.         call writeln(handle, 'TYPE=' || log.type)
  225.         call writeln(handle, 'TIME=' || log.time)
  226.         call writeln(handle, 'LENGTH=' || log.length)
  227.  
  228.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  229.  
  230.         call writeln(handle, 'CIDNAME=' || log.cidname)
  231.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  232.  
  233.         call writeln(handle, 'COMMENT=' || log.comment)
  234.  
  235.         call writeln(handle, 'FILENAME=' || log.filename)
  236.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  237.  
  238.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  239.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  240.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  241.  
  242.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  243.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  244.  
  245.         call close(handle)
  246.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  247.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  248.  
  249.     return
  250.  
  251.  
  252.  
  253. showDebugger: procedure
  254.     if arg() ~= 1 then do
  255.         say "showDebugger: ERROR"
  256.         exit 20
  257.     end
  258.  
  259.     parse arg debuggerInfo
  260.     
  261.     firstLine = sourceline(1)
  262.     parse var firstLine '/*' 'TITLE:' title '*/'
  263.     if showlist('p', 'AVMLOGGER') then
  264.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  265.     else
  266.         say title ':' debuggerInfo
  267.  
  268.     return 
  269.  
  270. /*-----------------------------------------------------------------------*/
  271. /*                         signal processing                             */
  272.  
  273. arexxerror:
  274. error:
  275.     call showDebugger("Error" rc "at line" sigl)
  276.     exit 20
  277.  
  278. break_c:
  279. halt:
  280.     call showDebugger("Halt/Break_C at line" sigl)
  281.     exit 20
  282.  
  283. novalue:
  284.     call showDebugger("No value at line" sigl)
  285.     exit 20
  286.  
  287. syntax:
  288.     call showDebugger("Syntax error" rc "at line" sigl)
  289.     exit 20
  290.  
  291. /* TITLE: avm:rexx/stdplayvoice.avm */
  292. stdPlayXX:
  293. procedure
  294. parse arg ret
  295.  
  296. rs.normal = 0
  297. rs.keydetected = 1
  298. rs.quietdetected = 2
  299. rs.silencedetected = 3
  300. rs.faxdetected = 4
  301. rs.datadetected = 5
  302. rs.busydetected = 8
  303. rs.timedout = 10
  304. rs.signaldetected = 12
  305. rs.overflow = 14
  306. rs.error = 16
  307. /* CB 0000 */
  308.  
  309. select
  310.   when ret=rs.faxdetected then signal stdfax
  311.   when ret=rs.datadetected then signal stddata
  312.   when ret=rs.busydetected then signal stdbusy
  313.   when ret=rs.signaldetected then signal stdabort
  314.   when ret=rs.overflow then signal stderror
  315.   when ret=rs.error then signal stderror
  316.   otherwise nop
  317. end
  318. return
  319.  
  320.  
  321. aapresentmenu:
  322. /* TITLE: avm:rexx/presentmenu.avm */
  323. procedure expose pmRetries pmTimesAround
  324. parse arg filename, valid, retries
  325. timesaround = retries
  326. pmTimesAround = timesaround
  327. pmRetries = retries
  328.  
  329. rs.normal = 0
  330. rs.keydetected = 1
  331. rs.quietdetected = 2
  332. rs.silencedetected = 3
  333. rs.faxdetected = 4
  334. rs.datadetected = 5
  335. rs.busydetected = 8
  336. rs.timedout = 10
  337. rs.signaldetected = 12
  338. rs.overflow = 14
  339. rs.error = 16
  340. /* CB 0000 */
  341.  
  342. aapresentmenuloop:
  343. 'playvoice' filename
  344. a_=rc
  345. if 0 then nop
  346. else if a_=4 then do;return rs.faxdetected;end
  347. else if a_=5 then do;return rs.datadetected;end
  348. else if a_=8 then do;return rs.busydetected;end
  349. else if a_=12 then do;return rs.signaldetected;end
  350. else if a_=14 then do;return rs.error;end
  351. else if a_=16 then do;return rs.error;end
  352.  
  353. 'readnkeys' '1' '5'
  354. a_=rc
  355. if a_=0 then value=result
  356. if 0 then nop
  357. else if a_=0 then signal aapresentmenuvalue
  358. else if a_=4 then do;return rs.faxdetected;end
  359. else if a_=5 then do;return rs.datadetected;end
  360. else if a_=8 then do;return rs.busydetected;end
  361. else if a_=10 then signal aapresentmenutimeout
  362. else if a_=12 then do;return rs.signaldetected;end
  363. else if a_=14 then do;return rs.error;end
  364. else if a_=16 then do;return rs.error;end
  365. return rs.error
  366.  
  367. aapresentmenutimeout:
  368. 'flushphonebuffer'
  369.  
  370. 'playvoice' 'avm:voices/TimedOut'
  371. a_=rc
  372. if 0 then nop
  373. else if a_=4 then do;return rs.faxdetected;end
  374. else if a_=5 then do;return rs.datadetected;end
  375. else if a_=8 then do;return rs.busydetected;end
  376. else if a_=12 then do;return rs.signaldetected;end
  377. else if a_=14 then do;return rs.error;end
  378. else if a_=16 then do;return rs.error;end
  379.  
  380. timesaround = timesaround - 1; pmTimesAround = timesaround
  381. if timesaround <= 0 then return rs.timedout
  382. signal aapresentmenuloop
  383.  
  384. aapresentmenuvalue:
  385. if pos(value, valid) = 0 then signal aainvalid
  386. return '=' || value
  387.  
  388. aainvalid:
  389. 'flushphonebuffer'
  390.  
  391. 'playvoice' 'avm:voices/BadChoice'
  392. a_=rc
  393. if 0 then nop
  394. else if a_=4 then do;return rs.faxdetected;end
  395. else if a_=5 then do;return rs.datadetected;end
  396. else if a_=8 then do;return rs.busydetected;end
  397. else if a_=12 then do;return rs.signaldetected;end
  398. else if a_=14 then do;return rs.error;end
  399. else if a_=16 then do;return rs.error;end
  400.  
  401. timesaround = timesaround - 1; pmTimesAround = timesaround
  402. if timesaround <= 0 then return rs.timedout
  403. signal aapresentmenuloop
  404.  
  405.  
  406. stdabort:
  407. exit
  408.  
  409. stdbusy:
  410. exit
  411.  
  412. stderror:
  413. exit
  414.  
  415. stdtimedout:
  416. exit
  417.  
  418. stdfaxinstruct:
  419. 'playvoice' 'avm:voices/FaxStarting'
  420. a_=rc
  421. if 0 then nop
  422. else if a_=1 then do;call checkifabort;end
  423. else if a_=8 then signal stdbusy
  424. else if a_=12 then signal stdabort
  425.  
  426. stdfax:
  427. faxscript = getclip(address() || 'FAXSCRIPT')
  428. if faxscript = '' then faxscript = 'handlefax'
  429. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  430. else address rexx faxscript address() 'anonymous'
  431. exit
  432.  
  433. stddatainstruct:
  434. 'playvoice' 'avm:voices/DataStarting'
  435. a_=rc
  436. if 0 then nop
  437. else if a_=1 then do;call checkifabort;end
  438. else if a_=8 then signal stdbusy
  439. else if a_=12 then signal stdabort
  440.  
  441. stddata:
  442. datascript = getclip(address() || 'DATASCRIPT')
  443. if datascript = '' then datascript = 'handledata'
  444. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  445. else address rexx datascript address()
  446. exit
  447.  
  448. checkifabort:
  449. 'readnkeys' '1' '3'
  450. a_=rc
  451. if a_=0 then value=result
  452. if 0 then nop
  453. else if a_=0 then do;if value = '*' then signal stdabort;end
  454. else if a_=8 then signal stdbusy
  455. else if a_=12 then signal stdabort
  456. else if a_=14 then signal stderror
  457. else if a_=16 then signal stderror
  458. return
  459.  
  460.  
  461. /* TITLE: avm:rexx/startup.avm */
  462. multistartup:
  463. /* This is where it all begins */
  464.  
  465. InitialMenu:
  466. call aapresentmenu('avm:voices/InitialMessage', '0123456789#*', '1')
  467. a_=result
  468. if 0 then nop
  469. else if a_='=0' then signal InitialMenu
  470. else if a_='=1' then do;call level0;end
  471. else if a_='=2' then do;mailbox = 'anonymous'; signal stdfaxinstruct;end
  472. else if a_='=3' then signal InitialMenu
  473. else if a_='=4' then signal InitialMenu
  474. else if a_='=5' then do;mailbox = 'anonymous'; signal stddatainstruct;end
  475. else if a_='=6' then signal InitialMenu
  476. else if a_='=7' then signal InitialMenu
  477. else if a_='=8' then signal InitialMenu
  478. else if a_='=9' then signal InitialMenu
  479. else if a_='=#' then do;return;end
  480. else if a_='=*' then signal stdabort
  481. else if a_=4 then do;mailbox = 'anonymous'; signal stdfax;end
  482. else if a_=5 then do;mailbox = 'anonymous'; signal stddata;end
  483. else if a_=8 then signal stdbusy
  484. else if a_=10 then signal startupTimedOut
  485. else if a_=12 then signal stdabort
  486. else if a_=14 then signal stderror
  487. else if a_=16 then signal stderror
  488. signal InitialMenu
  489.  
  490. startupTimedOut:
  491. answerpri = upper(getclip('AVMAnswerPriority'))
  492. if answerpri = 'FAX' then do; mailbox = 'anonymous'; signal stdfax; end
  493. else if answerpri = 'DATA' then do; mailbox = 'anonymous'; signal stddata; end
  494. do;call 'avmrexxalt:processmailbox'('anonymous');if symbol('RESULT')~='VAR' then exit;end
  495.  
  496. /* We're done */
  497. signal answervoiceDone
  498.  
  499. level0:
  500. call aapresentmenu('avm:voices/level0', '0123#*', '3')
  501. a_=result
  502. if 0 then nop
  503. else if a_='=0' then signal level0
  504. else if a_='=1' then do;call 'avmrexxalt:processmailbox'('mailbox1');if symbol('RESULT')~='VAR' then exit;end
  505. else if a_='=2' then do;call 'avmrexxalt:processmailbox'('mailbox2');if symbol('RESULT')~='VAR' then exit;end
  506. else if a_='=3' then do;call 'avmrexxalt:processmailbox'('anonymous');if symbol('RESULT')~='VAR' then exit;end
  507. else if a_='=#' then do;return;end
  508. else if a_='=*' then signal answervoiceDone
  509. else if a_=4 then do;mailbox = 'anonymous'; signal stdfax;end
  510. else if a_=5 then do;mailbox = 'anonymous'; signal stddata;end
  511. else if a_=8 then signal stdbusy
  512. else if a_=10 then signal answervoiceDone
  513. else if a_=12 then signal stdabort
  514. else if a_=14 then signal stderror
  515. else if a_=16 then signal stderror
  516. signal level0
  517.  
  518.  
  519. /* TITLE: avm:rexx/simplestartup.avm */
  520. simplestartup:
  521. do;call 'avmrexxalt:processmailbox'('anonymous');if symbol('RESULT')~='VAR' then exit;end
  522.  
  523. signal answervoiceDone
  524.  
  525.  
  526. timeOfDay2num:
  527. currentHours = time('hours')
  528. if currentHours < 12 then ret = 1
  529. else if currentHours < 18 then ret = 2
  530. else ret = 3
  531. return ret
  532.  
  533. dayOfWeek2num:
  534. procedure
  535. day=upper(date('Weekday'))
  536. d_.Monday=1;d_.Tuesday=2;d_.Wednesday=3
  537. d_.Thursday=4;d_.Friday=5;d_.Saturday=6
  538. d_.Sunday=7
  539. return d_.day
  540.  
  541. playAVoiceErrorOK:
  542. procedure
  543. parse arg toPlay
  544.  
  545. 'playvoice' toPlay
  546. a_=rc
  547. if 0 then nop
  548. else if a_=4 then signal stdfax
  549. else if a_=5 then signal stddata
  550. else if a_=8 then signal stdbusy
  551. else if a_=12 then signal stdabort
  552. return
  553.  
  554.