Obi202 Call Recording

This Node-Red flow monitors syslog messages generated by the Obihai 202 Analog Telephone Adaptor. Upon receiving OFF HOOK, the flow will EXEC a small shell script which uses WGET to download the audio transcript of the call. Upon completion, the file is renamed with a timestamp and the caller ID of the called or calling party in the filename.

See contents of the comment node for specifics. Obi user credentials must be provided in the get cdr html call.

2/4/2017. Updated rename_recordings.sh script to better identify the most recent recording to be renamed.

4/11/2017. Fixed a problem with embedded cr/lf in the renamed filename, which broke SCP transfer to windows hosts for outbound calls. Introduced a 2 second delay to solve a frequent race condition. Ensures CDR records are written to OBI before we read them.

Please seek the appropriate legal advice to understand the notification requirements for recording calls where you live.

[{"id":"f2245a49.734c58","type":"debug","z":"7a656f19.a599c","name":"","active":true,"console":"false","complete":"false","x":887.5,"y":600,"wires":[]},{"id":"ef48cc03.62ebc","type":"switch","z":"7a656f19.a599c","name":"Sort Obi202 OFF HOOK Messages by Port Number","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"#0 OFF HOOK","vt":"str"},{"t":"cont","v":"#1 OFF HOOK","vt":"str"},{"t":"else"}],"checkall":"false","outputs":3,"x":460.6111145019531,"y":81,"wires":[["14225bcc.8ffa84"],["ad3be012.fabc6"],[]]},{"id":"fbbabc0b.c78","type":"exec","z":"7a656f19.a599c","command":"/home/pi/record.sh","addpay":true,"append":"","useSpawn":"","timer":"","name":"Click Obi202 Record Button","x":835,"y":185.5,"wires":[[],["aba6f81f.02e898"],[]]},{"id":"7e6806e5.17fb88","type":"comment","z":"7a656f19.a599c","name":"Listens for OFFHOOK events from Obi202 ATA syslog output and executes wget call to record the call.  Renames recording when done.","info":"UDP Node: udp 1514\n-------------------------------------------------------------------------------\nreceives syslog events on port 1514 (does not require node-red run as root). \nRequires you administer your obi device to output syslog to ip address of node-red host using port 1514.  Change to suit your needs.  \n\nSwitch Node: Sort Obi202 OFF HOOK Messages\n-------------------------------------------------------------------------------\nSwitch node matches on OFF HOOK events.  Port 0 messages sent to output 1, Port\n1 messages sent to output 2\n\nChange Nodes: Port X OFF HOOK\n-------------------------------------------------------------------------------\nSince we already know which port is off hook, replace the whole message with\n0 or 1, which will be used by the next Exec node as the shell script argument\n\nFunction Node: Store Port# in Flow Context\n-------------------------------------------------------------------------------\nSet context.flow.port to the current port number in use.  Allows us to use this later.\n\nExec Node: Click Obi202 Record Button\n-------------------------------------------------------------------------------\nContents of /home/pi/record.sh script called by Exec:\n==========================================================\ncd /opt/recordings\nwget http://admin:[email protected]/record.au?port=$1\n==========================================================\n\n* Assumes you want to store recordings in /opt/recordings (change as needed)\n* Assumes Obi device is at 192.168.1.xxx.  replace with your devices IP Address\n* Append msg.payload ensures port # from previous change node is sent to script\n* Exec node waits for recording to complete before passing control along the\n  chain.\n  \nwww-request node: Get Last CDR Record from Obi202\n-------------------------------------------------------------------------------\nNow that the call has ended, wouldn't it be nice if we could rename the file with the phone number that was calling or that called?  GETs the\nhttp://obiipaddress/callhistory.htm web page\n\nHTML node: Obi Call History\n-------------------------------------------------------------------------------\ngrabs just the list of <td> elements from the web page and passes them alog as an array.\n  \nRepeat node: Limit 1st record only\n-------------------------------------------------------------------------------\ndiscards all but the 1st 9 <td> elements found in the callhistory.htm, effectively limiting the data set to approximately the 1st CDR record\n\nSwitch node: Isolate Phone Number\n-------------------------------------------------------------------------------\nreturns any phone number between 4 and 23 characters in length using a regular expression, or From GT1() if not found ****** This matches Google voice on service provider #1 and may vary depending on your installation.\n\nFunction node: Concatenate Port and CallerID\n-------------------------------------------------------------------------------\nappends the caller id to the value found in context.flow.port and passes it along to the next exec node.\n\nExec Timestamp Recording:\n-------------------------------------------------------------------------------\nSaved recordings get names in the form of record.au?port=x which isn't good.\nRename the file, incorporating the curent date and time resolved to seconds.\n\nContents of /home/pi/rename_recording.sh script called by 2nd Exec Node:\n====================\ncd /opt/recordings\nfn=$(ls -t record.au*| head -n1)\nmv -f -- \"$fn\" record_$(date +%F-%H-%M-%S)-$2.au\n====================\nAssumes files are in /opt/recordings\nmoves (renames) file with a new timestamped filename preserving extension .au\n\nCatch Node: catch all\n-------------------------------------------------------------------------------\nHere to catch errors\n\nDebug Node: msg.payload\n-------------------------------------------------------------------------------\nHere to provide debug outputs\n\nSwitch node: Delete uninteresting syslog messages\n-------------------------------------------------------------------------------\nAllows you to control what gets stored in your log file, should you choose to log messages.  If not, delete this and the following node.\n\nFile node: Syslog.log\n-------------------------------------------------------------------------------\nAlloss you to log any syslog output from your obi device.","x":493,"y":20,"wires":[]},{"id":"723d7be6.2e8ac4","type":"exec","z":"7a656f19.a599c","command":"/home/pi/rename_recording.sh","addpay":true,"append":"","useSpawn":"","timer":"","name":"Rename and Timestamp Recording","x":810,"y":459.5,"wires":[[],["f2245a49.734c58"],[]]},{"id":"14225bcc.8ffa84","type":"change","z":"7a656f19.a599c","name":"Port 0 OFF HOOK","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":863.5,"y":56,"wires":[["2b464a3c.cf1a66"]]},{"id":"ad3be012.fabc6","type":"change","z":"7a656f19.a599c","name":"Port 1 OFF HOOK","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":863.5,"y":98,"wires":[["2b464a3c.cf1a66"]]},{"id":"9654aa02.fc8768","type":"catch","z":"7a656f19.a599c","name":"","scope":null,"x":461.5,"y":600,"wires":[["f2245a49.734c58"]]},{"id":"76f1eb28.e946f4","type":"file","z":"7a656f19.a599c","name":"Syslog.log","filename":"/opt/recordings/syslog.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":127.5,"y":600,"wires":[]},{"id":"4551fcd5.e056c4","type":"switch","z":"7a656f19.a599c","name":"Delete uninteresting syslog messages","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"OPTIONS","vt":"str"},{"t":"cont","v":"<7> sendto","vt":"str"},{"t":"cont","v":"<7> RxFrom:","vt":"str"},{"t":"else"}],"checkall":"true","outputs":4,"x":194.5,"y":522,"wires":[[],[],[],["76f1eb28.e946f4"]]},{"id":"2b464a3c.cf1a66","type":"function","z":"7a656f19.a599c","name":"Store Port# in Flow Context","func":"context.flow.port = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":380.5,"y":186,"wires":[["fbbabc0b.c78"]]},{"id":"4c52b42b.7de74c","type":"change","z":"7a656f19.a599c","name":"Grab the Caller ID","rules":[{"t":"change","p":"payload","pt":"msg","from":"(From).*\\((\\d{4,23})\\)","fromt":"re","to":"$1-$2","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"(To) GT1\\((\\d{4,23})\\)","fromt":"re","to":"$1-$2","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"From Gt1()","fromt":"str","to":"From_unknown_caller","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":863.5,"y":363,"wires":[["9d2518a1.bdbbf8"]]},{"id":"3e9efe45.4baf02","type":"www-request","z":"7a656f19.a599c","name":"Get Last CDR Record From Obi202","method":"GET","ret":"txt","url":"http://OBi202/callhistory.htm","tls":"","x":411.5,"y":269,"wires":[["c09d6b5b.3a8788"]]},{"id":"c09d6b5b.3a8788","type":"html","z":"7a656f19.a599c","name":"Obi Call History","tag":"td","ret":"text","as":"multi","x":878.5,"y":269,"wires":[["4615cb6c.c2d154"]]},{"id":"4615cb6c.c2d154","type":"repeat","z":"7a656f19.a599c","name":"Limit 1st record only","repetitions":"9","elseOutput":true,"outputs":2,"x":361.5,"y":367,"wires":[["55e92d69.400b04"],[]]},{"id":"55e92d69.400b04","type":"switch","z":"7a656f19.a599c","name":"Isolate Phone Number","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":".+(\\d{4,23})\\)","vt":"str","case":false},{"t":"regex","v":"From GT1()","vt":"str","case":true}],"checkall":"true","outputs":2,"x":614,"y":364,"wires":[["4c52b42b.7de74c"],["4c52b42b.7de74c"]]},{"id":"9d2518a1.bdbbf8","type":"function","z":"7a656f19.a599c","name":"Concatenate Port and CallerID","func":"var myString = context.flow.port;\nmyString = myString + \" \";\nmsg.payload = myString + msg.payload.trim();\nreturn msg;","outputs":1,"noerr":0,"x":391.5,"y":459,"wires":[["723d7be6.2e8ac4"]]},{"id":"5131082.26078f8","type":"udp in","z":"7a656f19.a599c","name":"Obi202 Syslog","iface":"","port":"1514","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":106,"y":81,"wires":[["ef48cc03.62ebc","4551fcd5.e056c4"]]},{"id":"aba6f81f.02e898","type":"delay","z":"7a656f19.a599c","name":"Delay 2 Seconds","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":220,"wires":[["3e9efe45.4baf02"]]}]
tomlynn

Flow Info

created 7 months, 2 weeks ago
updated 2 months, 2 weeks ago

Node Types

Core
  • catch (x1)
  • change (x3)
  • comment (x1)
  • debug (x1)
  • delay (x1)
  • exec (x2)
  • file (x1)
  • function (x2)
  • html (x1)
  • switch (x3)
  • udp in (x1)
Other

Tags

  • VoIP
  • telephony
  • obi
  • obihai
  • obi202
  • recording
  • call
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option