News:

On Tuesday September 6th the forum will be down for maintenance from 9:30 PM to 11:59 PM PDT

Main Menu

Script to record call in progress

Started by MYOBi, January 21, 2012, 12:26:33 PM

Previous topic - Next topic

ubergoober

#60
I've made another update to the Node-Red flow.  I've added the ability to reboot your Obi periodically.  It checks to see if there's a call in progress before restarting the device.

The other addition is automatic filing of your recordings into sub directories based on date.

This works very well on an inexpensive, headless Raspberry Pi computer.  Neither of the new features are directly connected to the call recorder, but they are in the same flow for ease of installation.  

Next addition will be a web service call method to stop recording.  
After that, I'm working on assembling the individual syslog digits dialed messages on outbound calls in order to know the remote party number before the session is established.  This will unlock the ability to program a list of numbers that you want to automatically record.  So you don't have to record everything, and nor will you have to manually start recording.

Please let me know if you have any other ideas for the OBI.

threehappypenguins

#61
Quote from: ubergoober on January 09, 2020, 10:47:37 PMI've updated my Node-Red based call recording flow at: https://flows.nodered.org/flow/1acb62db43de9b7f8bc0750f02307d54

It allows you to trigger recording manually with a URL or you can use syslog to trigger recording on all calls.  It no longer uses shell scripts to do the work and is a lot more accurate in it's identification of the remote caller ID.  It will rename the recording to include the date and remote caller ID and if you install FFMPEG on your LINUX system it will convert the recording to mp3 to save space.

Enjoy!

Thank you for doing this! I am a total noob with Node-RED (or node in general). I have an Obi 202. I also have an Odroid HC4 running OMV on Debian and installed Node-RED via a Portainer stack, so it's running on Docker. I cannot get this to run (I want to record all calls automatically). I'm confused about the "wires."

You said,
QuoteIf you decide you want to record all calls, then disconnect the wire from the 1st and second function nodes.

From my understanding, the first Function node is "Simulate Syslog Off Hook Message when user sends proper urlencoded method" and the second Function node is "Set Defaults and Determine Off Hook Port Number". Is that correct? If so, they are not connected by a wire by default when I import your script. So leave it as is?

Secondly, you said
QuoteConnect the wire from the Obi Syslog UDP in node to the 2nd function node.

So this means I connect a wire from "Obi Syslog on UDP 1514" to "Set Defaults and Determine Off Hook Port Number"?

I can't get it to work. And I don't know how to get the debug to work. I tried connecting the debug to "Obi Syslog on UDP 1514" but it won't work. I made sure I changed the IP addresses for 192.168.1.47 to 192.168.1.6 (which is my Obi 202). And in my Obi 202, I changed the port from 514 to 1514 in the device admin (but I need to leave "Server" just above it blank/default"? Or do I add 192.168.1.38 which is my Odroid HC4?). I also added basic authentication wherever the flow indicated as well, having the user as "admin" and putting in my password (what I use to log into the local Obi page). I am definitely on port 0 for the phone calls (not port 1).

I did click "Deploy" whenever I would make changes.

I'm just trying to make sense of all this.

threehappypenguins

I have it all figured out. Two problems. One, for "server" in the Device admin in the Obi, I indeed must put 192.168.1.38 which is my machine running Node-RED. The other problem was my Docker Node-RED container settings. I needed to tell the host to forward port UDP 1514 to 1514 within the container. NOW it works. If anyone is wondering, this is my docker compose for my Portainer stack:

---
version: "2"
services:
  node-red:
    image: nodered/node-red
    container_name: node-red
    environment:
      - PUID=1000
      - PGID=100
      - TZ=Canada/Atlantic
    volumes:
      - /srv/dev-disk-by-uuid-088953ed-6887-487c-bd44-d5f86dc93383/AppData/Nodered:/data
    ports:
      - 1880:1880
      - 1514:1514/UDP
    restart: unless-stopped

And then of course, I needed to create a folder called "recordings" within the data folder, and in the script for "func":"msg.filePath = \"/opt/recordings/\"; I changed it to "func":"msg.filePath = \"/data/recordings/\";.

threehappypenguins

#63
I had to make a few changes. For one thing, because I have Node-RED running in a docker container, I couldn't figure out how to tell the script to use either ffmpeg from my host system, or from another container with ffmpeg. So I finally gave that up and just entered the Node-RED container shell and installed ffmpeg:

sudo docker ps (and I took note of the container ID)
sudo docker exec -it --user=root f4d6abb9d6d9 bash (sub f4d6abb9d6d9 with whatever your container ID is)
apk add ffmpeg (this Alpine command installs ffmpeg)

The other major change was the script to create the mp3. It would do funky things like try to create the following (example): /data/recordings/record_7/1/2023,-11-32-21-AM_5551239876.mp3

I think what is meant to happen is it creates a file called record_7-1-2023,-11-32-21-AM_5551239876.mp3 but it has slashes instead of dashes and because the folders record_7 and 1 don't exist, the mp3 file is never made. Plus there's the weird, random comma in there. Here is a script that will create a file such as 2023-07-01_11-32-21_5551239876.mp3 right in the /data/recordings folder (or /opt/recordings or whatever you want):

Double click on the node Clear Flow CID Variables / build command for next exec node to Rename File and convert to MP3 and change the script to this (substituting the folderPath with whatever your folder is where you want your recordings):

msg.payload = "";

var now = new Date();
var month = String(now.getMonth() + 1).padStart(2, "0");
var day = String(now.getDate()).padStart(2, "0");
var year = now.getFullYear();
var hours = String(now.getHours()).padStart(2, "0");
var minutes = String(now.getMinutes()).padStart(2, "0");
var seconds = String(now.getSeconds()).padStart(2, "0");

var timestamp = `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;

msg.now = timestamp;

// Clear the CID flow variable for this call only.
if (msg.port === "0") {
    var cid = flow.get("port0cid");
    flow.set("port0cid", "unknown");
}
if (msg.port === "1") {
    var cid = flow.get("port1cid");
    flow.set("port1cid", "unknown");
}

// Folder path
var folderPath = "/data/recordings/";
msg.folderPath = folderPath;

// Build Linux command to post-process the file, including renaming and conversion to MP3
var newName = folderPath + timestamp + "_" + cid + ".mp3";
msg.newName = newName;
msg.payload = "ffmpeg -i " + msg.filename + " " + newName + " && rm " + msg.filename;
return msg;

At this point, I'm not entirely sure what will happen with the other nodes with scripts for archiving and whatnot, but for now, it records the call automatically for me, and converts it to an mp3, which is top priority for me right now.

For reference, the original script is this:

msg.payload = "";
var now = new Date();
now = now.toLocaleString();
now = now.replace(/[ :]/g, "-");
msg.now = now;
// Clear the CID flow variable for this call only.
if (msg.port === "0") {
    var cid = flow.get("port0cid");
    flow.set("port0cid", "unknown");
}
if (msg.port === "1") {
    var cid = flow.get("port1cid");
    flow.set("port1cid", "unknown");
}

//Build Linux Command to post-process the file which includes renaming
//and possibly conversion to MP3
var newName = msg.filePath + "record_" + now + "_" + cid + ".mp3";
msg.newName = newName;
msg.payload = "ffmpeg -i " + msg.filename + " " + newName + " && rm " + msg.filename;
return msg;

formerlyubergoober

Hello, ThreeHappyPenguins!
I wrote the node-red flow you've based your automations on.  For whatever reason, when I needed a password reset to access Obitalk, they forced me to re-enroll using a different username, so I tried to make it plain I'd previously used ubergoober as my handle.

I'm so glad that someone is getting some use out of the recording flow.  I have to admit there's some stuff in there that isn't optimal.  I'm hoping you worked around it.  I have always thought that node-red is so easy to work with and since it's cross-platform the solution wasn't restricted to a specific OS.

Glad you had an open mind.

Ubergoober