I want that conference recordings should automatically be available to add to IVR.
I created a script, but im getting errors.
- when i go to the preview, i can’t listen to the recording
- when i call in and select that from the IVR menu, the call gets disconnected
See script
#!/bin/bash
MONITOR_DIR="/var/spool/asterisk/monitor"
RECORDINGS_DIR="/var/lib/asterisk/sounds/custom"
# Find the most recent audio file
latest_file=$(find "$MONITOR_DIR" -type f \( -name "*.wav" -o -name "*.mp3" -o -name "*.gsm" \) -printf "%T@ %p\n" | sort -n | tail -1 | cut -d ' ' -f2)
# Check if a file was found
if [ -n "$latest_file" ]; then
# Get file creation time in dd_mm_yy_hh_mm format
creation_time=$(stat -c %y "$latest_file" | awk '{print $1, $2}' | sed 's/[:-]/ /g' | awk '{printf "%02d_%02d_%02d_%02d_%02d", $3, $2, substr($1,3,2), $4, $5}')
# Get file extension
ext="${latest_file##*.}"
# Define new filename format
new_name="${creation_time}_Conference_Recording.${ext}"
# Rename only if needed
if [ "$(basename "$latest_file")" != "$new_name" ]; then
mv "$latest_file" "$MONITOR_DIR/$new_name"
fi
# Copy file to FreePBX system recordings directory
cp "$MONITOR_DIR/$new_name" "$RECORDINGS_DIR/"
# Set correct ownership and permissions
chown asterisk:asterisk "$RECORDINGS_DIR/$new_name"
chmod 644 "$RECORDINGS_DIR/$new_name"
# Register recording in FreePBX database
mysql asterisk -e "INSERT INTO recordings (displayname, filename, description) VALUES ('$new_name', 'custom/$new_name', 'Conference Recording') ON DUPLICATE KEY UPDATE filename='custom/$new_name';"
# Apply FreePBX changes
fwconsole reload
fi