Post Call Recording Script Update for Freepbx 15? Worked fine in 14


(Sentinel) #1

I have a script that emails the extension after a recording is placed to the extension that records the messages. Works fine in Freepbx 14 but I get invalid message saying it cannot find the email. I am assuming I need to update the following:

Find Email Address of recording extension

. <(grep AMPDB /etc/amportal.conf) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.

What do I need to update here to work in 15?


(Jared Busch) #2

Change the grep to /etc/freepbx.conf


(Sentinel) #3

I changed this

# Find Email Address of recording extension

. <(grep AMPDB /etc/freepbx.conf) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.

Now I get no email at all


#4

Replace

. <(grep AMPDB /etc/freepbx.conf)

with

source <(grep AMPDB /etc/freepbx.conf |cut -d "'" -f2,4|tr "'" '=')

(Sentinel) #5

I don’t have a . <

I updated and now it’s sending all the emails to root@domain.com for some reason


#6

You need it (and had it in your post) , it is an alias for source which is more readable that sets the variable like ‘ASTDBUSER=fred’ but freepbx.conf don’t look like that whereas amportal.conf does ,

Start with baby steps, fist

grep AMPDB /etc/freepbx.conf

will show your AMPDB creds, then replace the $AMPDB’s apropos and replace = ${trigext} with like '%NNN%' in

mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where  `default_extension`  = ‘${trigext}’;’

likely you won’t need a wild card for default_extension and


(Sentinel) #7

Okay I found and updated but I still get

!!! No Valid email found for 1000 !!!

There is indeed an email.

Updated to:

#!/bin/bash

This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk

Post Recording Setting in Advanced Settings = “/var/lib/asterisk/bin/recordscript.sh ^{TIMESTR} ^{CRM_SOURCE} ^{MIXMONITOR_FILENAME} ^{DIALEDPEERNUMBER} ^{DYNAMIC_WHO_ACTIVATED}”

$1 - Time String

$2 - Source

$3 - File

$4 - Destination

$5 - Who activated recording

$6 - This extension in case destination is empty use this

var1=$(echo $1 | cut -f2 -d=) # timestamp
var2=$(echo $2 | cut -f2 -d=) # source
var3=$(echo $3 | cut -f2 -d=) # file name
var4=$(echo $4 | cut -f2 -d=) # destination
var5=$(echo $5 | cut -f2 -d=) # who activated
var6=$(echo $6 | cut -f2 -d=) # this extension -> destination
echo -e “$var1 $var2 $var3 $var4 $var5 $var6” >> /tmp/recording-script.log

Default Email to use incase we don’t get a valid match

defem="test@domain.com"

$DTS - Date & Time the recording started

DTS=$(date ‘+%m/%d/%Y %r’ --date="$(echo -n “$var1” | sed -r ‘s/([0-9]{4})([01][0-9])([0-3][0-9])-([0-2][0-9])([0-5][0-9])([0-5][0-9])/\1/\2/\3 \4:\5:\6/’)" 2>/dev/null)

$DTE - Date & Time the recording ended

DTE=$(date ‘+%m/%d/%Y %r’)

$DT - Set the timestamp in the MSG to one of the above timestamps

DT=$DTS

MSG="" # Initialize MSG arg

Find Email Address of recording extension

source <(grep AMPDB /etc/freepbx.conf |cut -d “’” -f2,4|tr “’” ‘=’) # Source DB Creds
email="" # Blank out email arg just in case
valem="[[:graph:]]+@[[:graph:]]+.[[:graph:]]+" # Set regex to validate email addresses
trigext=$(echo -n $var5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) # Set Triggering extension
email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse ‘select email from userman_users where default_extension = ‘${trigext}’;’ 2>/dev/null)" # Get email address for trigext from userman.
if [ "$var4"x == “x” ]
then
var4=$trigext
fi

Check that we have a valid email address

if ! [[ $email =~ $valem ]]
then
MSG="$MSG !!! No Valid email found for ${trigext} !!!\n"
MSG="$MSG !!! Defaulting to ${defem} !!!\n"
email=$defem
fi

Compile Message

MSG="$MSG You have a new call recording to listen to: \n"
MSG="$MSG The call date and time was $DT \n"
MSG="$MSG The call was from $var2 \n"
MSG="$MSG The call was to $var4 \n"
MSG="$MSG Please see the attached file \n\n"

Debug Values to add to MSG

#MSG="$MSG Attachment:\t${3}\n"
#MSG="$MSG Who Activeated:\t${5}\n"
#MSG="$MSG WhoAct-Basic:\t${trigext}\n"
#MSG="$MSG Email Addr:\t${email}\n"

Testing Destination so you don’t have to flood an email box

echo -e “$MSG” >> /tmp/recording-script.log

Email MSG and attachment

echo -e “$MSG” | which mail -a $var3 -s “New Call Recording” $email

exit 0

indent preformatted text by 4 spaces


#8

as I said ${trigext} as written is IMHO highly suspect, just replace it with 1234 and try again


(Sentinel) #9

if I replace with 1234, I get no email


#10

Do you have an email set for extension 1234?
Do you even have an extension 1234?


(Jared Busch) #11

also, post the full script, inside a code block as no one seriously wants to help when it is illegible.


(Sentinel) #12

yes I do

> #!/bin/bash
> 
> # This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk
> # Post Recording Setting in Advanced Settings = "/var/lib/asterisk/bin/recordscript.sh ^{TIMESTR} ^{CRM_SOURCE} ^{MIXMONITOR_FILENAME} ^{DIALEDPEERNUMBER} ^{DYNAMIC_WHO_ACTIVATED}"
> # $1	- Time String
> # $2	- Source
> # $3	- File
> # $4	- Destination
> # $5	- Who activated recording
> # $6    - This extension in case destination is empty use this
> 
> var1=$(echo $1 | cut -f2 -d=) # timestamp
> var2=$(echo $2 | cut -f2 -d=) # source 
> var3=$(echo $3 | cut -f2 -d=) # file name
> var4=$(echo $4 | cut -f2 -d=) # destination
> var5=$(echo $5 | cut -f2 -d=) # who activated
> var6=$(echo $6 | cut -f2 -d=) # this extension -> destination
> echo -e "$var1 $var2 $var3 $var4 $var5 $var6" >> /tmp/recording-script.log
> # Default Email to use incase we don't get a valid match
> defem="test@domain.com"
> 
> # $DTS - Date & Time the recording started
> DTS=$(date '+%m/%d/%Y %r' --date="$(echo -n "$var1" | sed -r 's/([0-9]{4})([01][0-9])([0-3][0-9])-([0-2][0-9])([0-5][0-9])([0-5][0-9])/\1\/\2\/\3 \4:\5:\6/')" 2>/dev/null)
> 
> # $DTE - Date & Time the recording ended
> DTE=$(date '+%m/%d/%Y %r')
> 
> # $DT - Set the timestamp in the MSG to one of the above timestamps
> DT=$DTS
> 
> MSG="" 	# Initialize MSG arg
> 
> # Find Email Address of recording extension
> source <(grep AMPDB /etc/freepbx.conf |cut -d "'" -f2,4|tr "'" '=')																								# Source DB Creds
> email=""																																						# Blank out email arg just in case
> valem="[[:graph:]]+@[[:graph:]]+\.[[:graph:]]+"																			# Set regex to validate email addresses
> trigext=$(echo -n $var5 | egrep --color -o "\/[0-9]{2,5}-" | egrep -o "[[:digit:]]*")	# Set Triggering extension
> email="$(mysql -u$AMPDBUSER -p$AMPDBPASS -D $AMPDBNAME -Bse 'select email from userman_users where `default_extension` = '${trigext}';' 2>/dev/null)"		# Get email address for trigext from userman.
> if [ "$var4"x == "x" ] 
> 	then 
> 	var4=$trigext
> fi	
> # Check that we have a valid email address
> if ! [[ $email =~ $valem ]]
> 	then
> 		MSG="$MSG !!! No Valid email found for 1000 !!!\n"
> 		MSG="$MSG !!! Defaulting to ${defem} !!!\n"
> 		email=$defem
> fi
> 
> # Compile Message
> MSG="$MSG You have a new call recording to listen to: \n"
> MSG="$MSG The call date and time was $DT \n"
> MSG="$MSG The call was from $var2 \n"
> MSG="$MSG The call was to $var4 \n"
> MSG="$MSG Please see the attached file \n\n"
> 
> ## Debug Values to add to MSG
> #MSG="$MSG Attachment:\t${3}\n"
> #MSG="$MSG Who Activeated:\t${5}\n"
> #MSG="$MSG WhoAct-Basic:\t${trigext}\n"
> #MSG="$MSG Email Addr:\t${email}\n"
> 
> ## Testing Destination so you don't have to flood an email box
> echo -e "$MSG" >> /tmp/recording-script.log
> 
> # Email MSG and attachment
> echo -e "$MSG" | `which mail` -a $var3 -s "New Call Recording" $email
> 
> exit 0

(Sentinel) #13

I obviously replaced the wrong section. What part did you want 1234 or in my case 1000. I even updated all ${trigext options and get no email


#14

In the script there is

trigext=$(echo -n $var5 | egrep --color -o “/[0-9]{2,5}-” | egrep -o “[[:digit:]]*”) 

where $Var5 is ^{DYNAMIC_WHO_ACTIVATED}, which the fifth parameter in the call to the script, just replace initially ${trigext} with 1000 to test. (color !! WTF is that doing there!! )

paste a sample ^{DYNAMIC_WHO_ACTIVATED} and we can likely write a nice sed expression


(Sentinel) #15

trying this now. Couldn’t tell you. Sangoma did this a few years ago on a ticket


(Sentinel) #16

I get the email, but it says !!! No Valid email found for !!! and doesn’t’ list an extension


#17

It needs a complete rewrite by someone more patient than me to be useful again, I would pay Sangoma to fix it.


(Sentinel) #18

Thanks for your help :slight_smile: It seems so close!


(Jared Busch) #19

Everytime it executes it writes the variables to a log.

Did you verify what was written there?


(Sentinel) #20

I opened a case with Sangoma