Tuesday, April 6, 2021

Asterisk Post Call Recording Script configuration

This code shows how to alter a file with the Post Call Recording script.  But in general shows a bit of how the process of making this asterisk feature work

I did worked on trying to get that AGENT ID variable via dialplan, but I just couldn't figure it out in Issabel. The Callcenter system in that is very tied in and I just wasn't able to figure it out. If someone else can show me, that would be fantastic.

I know that is value is stored in the QUEUE. LOG file as each call is sent to an agent. So using the "Post Call Recording Script", at the end of each call, I use a shell script that is automatically activated. This script searches the queue.log file for the unqiue callID and the value "COMPLETEAGENT". This indicates the end of a queue call. The shell parses the entry and pulls out the agent id, Then it renames the sound recording by adding on the AGENTXXXX ID.

So a call that went to queue Agent ID "9989", the recording changes from this:

rg-600-1000-20210331-213521-1617237321.105.wav

and becomes this:

rg-600-1000-20210331-213521-1617237321.105-Agent9989.wav

Here's how i did it:

You don't need any modifications to the Issabel diaplan. The only thing you have to do in Issabel is activate "Post Call Recording Script"

PBX -> "Advanced Settings"

HiddenMenu

You will need to activate "Display Readonly Settings"

and "Override Readonly Settings" Set them both to "TRUE" then click on the Green checkbox on the right side.

You wlll get prompted that you will need to "REFRESH THE PAGE" which you will have to.
Once both boxes are set to "TRUE" and you have pressed the checkbox, click on "ADVANCED SETTINGS" again to refresh.

Now scroll down and you will see

"Post Call Recording Script"

In that box put in this. The quotes around the path and script are required. Asterisk $variables are substituted with a "hat" symbol

HiddenMenu

"/etc/asterisk/updateagent.sh" ^{UNIQUEID} ^{MIXMONITOR_FILENAME}

This is the code that will run after the caller hangsup and the call recording is completed processing.
After each call, the "updateagent.sh" shell script is activated and it passes the UniqueID of the call as well as the current file location

Select the green check mark to the right of this box. Then press APPLY SETTINGS

Now we need to create a shell script.

In /etc/asterisk create a file called "updateagent.sh" (you can of course put this file in your preferential own directory, just make sure the path in the config in Issabel reflects it. You can also change the name.

In side this file you will want to copy in the following into that file and then save it.

#!/bin/bash

#This line finds the agent number in the queue_log file.  It then parses out any extra data to get the number value
#It will find thise 1617240353|1617234166.70|NONE|Agent/9989|AGENTLOGOFF|SIP/1000-00000028|6182 and finish with
#this "9989"
agentnumber=$(grep $1.*COMPLETEAGENT /var/log/asterisk/queue_log | awk -F "|" '{ print $4 }' | awk -F "/" '{ print $2 }')

#this line finds the file type you are using.  They are usually .WAV, but in case its something else we want to account for that
filetype=$(echo $2 | awk -F "." '{ print $3 }')

#This creates a new file name based on the AGENTID and the FileType you are using
newfilename=$(echo $2 | awk -F "." '{ print $1"."$2}')-Agent$agentnumber.$filetype

mv $2 $newfilename
#This rg-600-1000-20210331-213521-1617237321.105.wav
#becomes
#rg-600-1000-20210331-213521-1617237321.105-Agent-9989.wav

Now you will need to make the file executable

chmod u+x updateagent.sh

And now you need to change ownership to allow asterisk PBX to run it

chown asterisk:asterisk updateagent.sh

And that should be it. Make a test call and see if it works. If you have problems, just take out the code in "Post Call Recording Script" and will let you troubleshoot.

MODIFICATION TO PASS OTHER VARIABLES

You can pass additional variables into the script with two modifications

In the Call Record Script you can add more entries by adding them after the MixMonitor entry. Every variable that would be in asterisk needs to have the $ changed to a ? (hat) symbol. So if you wanted to pass $'CONTEXT' and $'EPOCH' data, you can add it. Very important to have "quotes" around the shellscript path. Many examples on internet forget to include this requirement

"/etc/asterisk/updateagent.sh" ^{UNIQUEID} ^{MIXMONITOR_FILENAME} ^{CONTEXT} ^{EPOCH}

THEN in the updateagent.sh script, you just need to alter the "newfilename" entry by adding a $3 and then a $4 like the example below. These would represent the 2 additional values.

newfilename=$(echo $2 | awk -F "." '{ print $1"."$2}')-Agent$agentnumber-$3-$4.$filetype

Save and you should be able to run the file. If the variables are passed correctly, you'll see them appear in the filename, something like this: (DialPlanVar1 and Var2)

rg-600-1000-20210331-230350-1617242630.111-Agent9989-DialPlanVar1-DialPlanVar2.wav

If the data is NOT available, they will just look like this: (you'll see the - that are delimiters)

rg-600-1000-20210331-230350-1617242630.111-Agent--.wav

    No comments:

    Post a Comment

    Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.