FreePBX | Register | Issues | Wiki | Portal | Support

FPBX/Asterisk option to replace Avaya IPO "Campaigns"


That was the first thing I tried, and it got… wonky. :slight_smile:
The quotes seemed to make the NAME variable mad:

The resulting call file skips that line completely:

Even if I just remove the quotes (and leave the carets there), the resulting call file is missing that line completely - I think it’s because the carets are also use for the echo’s write command (though I was hoping that because it was double carets, the single caret wouldn’t impact - but it did):

(Tom Ray) #42

So all of this is to use the voicemail email template in the end? That is the whole goal of this?


It asks a series of questions, appends the answers into a single file, then sends the file into voicemail so that the resulting email is nicely formatted (the way Voicemail-to-Email messages are).

The subject line automatically has all the data necessary because of that VM2EM message format, and the information attached is all the answers to the questions - because of using this structure, transcription now also works without any special code in the actual macro.

(Tom Ray) #44

I understand what you’re doing with the recordings. I just wouldn’t create call files just to send the calls to voicemail for the option of a pretty formatted email.

I use the PHPMailer class for things like this. It does HTML, plain text, attachments, pretty much everything I need to do this. This is how I can send different branded VM notifications on my systems.

In this case I would have a single System() call that would send all my variables to a script that would load the PHPMailer class, and since I already use my own template for VM (based on Asterisk’s) I just call that in from another function that I can pass my variables to. This would load my template, set the email/smtp details, attach the recording and send it on it’s way and then delete the recording from the system.

The script would take a little more work than a half dozen echo lines but in the end it is much more versatile and can be used for much more than one thing. Plus it doesn’t keep calls going and having your system doing extra recordings because you’re recording once and sending it off immediately.


Based on the info in this article:

I was able to figure out the proper syntax, though the config editor thinks its invalid (red text), but it works…

I’m updating the above “final” code with this line:

same => n,system(echo “CallerID: “${CALLERID(name)}” <${CALLERID(number)}>” >> /var/lib/asterisk/sounds/${UNIQUEID}.call)


The last piece of this is, right after the last sound file, I want it to wait for a second or two, then transfer the call into a queue extension, so I’m just figuring out what that last line (of part 1) would look like, but the initial intent’s “finished” product is listed above for others to use and tweak as they desire.

Thanks everyone to those that helped me create this “Avaya IPOffice Campaign Replacement”. :slight_smile:

(Dickson) #47

So all working for you now @kristiandg? Keep us posted on its performance!

@BlazeStudios the php approach would definitely be really nice alternative, can you post some code to show us how that would be done?


Yes sir, works perfectly - Thank you!!!
And I just figured out the line(s) to put after the below to make it then transfer the call:

same => n,wait(2)
;Transfers the call to x7901001
same => n,Dial(local/7901001@from-internal)

This also got me thinking about what happens when someone calls in and hangs up on the call before finishing the process (a bunch of old partially-recorded sound files. So, when you first hit the macro, I’ve added this (ok, this is silly, but the forum isn’t displaying the asterisks I have in between the file name - to prevent accidential deleteion of regular .ulaw files - all the files the $UniqueID variable generates has two file extensions (what I believe is milliseconds, then the .ulaw) - the star-dot-star-dot-ulaw format allows it to ONLY match those files, ignoring any other .ulaw sound files in the sounds directory):

;Deletes old sound files that were never completed by past callers - older than 1 day
same => n,system(find /var/lib/asterisk/sounds/ -maxdepth 1 -type f -name ‘..ulaw’ -mtime +1 -delete)

OK, I’ve now updated the previous post with the final touches (I need to walk away or I’m going to obsess over what all I can do with this thing). lol

(Tom Ray) #49

I can at some point this weekend. I have to finish this USAC filing report first.


If you use quotes within quotes they need to be escaped with a back-slash

echo "\"name of person\" <13235551212>" >> call.file


same => n,goto(ext-local,yourqueuediallednumber,1))

(Tom Ray) #52

@dickson @kristiandg OK so this is the rough draft that I threw together. You would need PHPMailer installed on the system. The current version will work in FreePBX v14. If you have FreePBX v13 you’ll need their legacy version and will need to make adjustments accordingly.

This gives you a simple set of variables. You call on them by wrapping them in {} so CALLERID would be {CALLERID}
– CIDNAME : CallerID Name
– CIDNUM : CallerID Number
– CALLERID : CallerID Full
– DATETIME : Current Time Stamp of the notification

You can pass more vars by adding them to the $email_vars array and just calling on them by {name} in the template. So you could add $email_vars[‘user_id’] = 1; and then call on it in the template as {user_id}

same => n,System(/path/to/script.php “${CALLERID(name)}” ${CALLERID(number)} ${UNIQUEID}.wav)

The Script:

#!/usr/bin/php -q

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

 * Set Script VARS
$FROM_NAME = "FreePBX Recording"; // From Email Name
$FROM_EMAIL = ""; // From Email Address
$TO_NAME = "Jane User"; // To User Name
$TO_EMAIL = ""; // To User Email Address
$EMAIL_SUBJECT = "New Recording Notification"; // Email Subject 
$EMAIL_BODY = "/path/to/email/template.tpl"; // Path to the email body template
$EMAIL_ALT_BODY = "Please review attached recording"; // Alt Body in case of no HTML support

$SND_DIR = "/path/to/recording/dir/"; // Path to directory storing recordings. With trailing /

$SMTP_HOST = ""; 	// Your SMTP Host
$SMTP_PORT = 587; 	// Your SMTP Port
$SMTP_USER = ""; 	// Your SMTP Username
$SMTP_PWD = ""; 	// Your SMTP Password

 * Done Setting Vars. Touch nothing below here unless you need to and know what you're doing
// Raw CallerID Name
$v_cidname = $argv[1];

// Raw CallerID Num
$v_cidnum = $argv[2];

// Set Path to recording
$rec_file = $SND_DIR . $argv[3];

// Set Valid Flags to false
$valid_cnam = false;
$valid_cnum = false;

// Check the CallerID Name. 
// We only want A-Z, a-z, 0-9, underscore, space and apostrophe
if (preg_match('/[A-Za-z0-9_\' ', $v_cidname)) {
	$email_vars['CIDNAME'] = $v_cidname;
	$valid_cnam = true;

// Check CallerID Number
// We only want A-Z, a-z and 0-9
if (preg_match('/A-Za-z0-9/', $v_cidnum)) {
	$email_vars['CIDNUM'] = $v_cidnum;
	$valid_cnam = true;

// No Valid CNAM or CNUM just die.
if (!($valid_cnum && $valid_cnam)) {

// Set CallerID Name to CallerID Num if empty.
if ($email_vars['CIDNAME'] == '') {
	$email_vars['CIDNAME'] = $email_vars['CIDNUM'];

// Format Full CallerID
$email_vars['CALLERID'] = $email_vars['CIDNAME'] . " <" . $email_vars['CIDNUM'] . ">";

// Initiate PHPMailer & Build Mailer Object
$mailer = new PHPMailer;
$mailer->SMTPSecure = false;
$mailer->SMTPAutoTLS = false;
$mailer->SMTPAuth = true;
$mailer->Host = $SMTP_HOST;
$mailer->Port = $SMTP_PORT;
$mailer->Username = $SMTP_USER;
$mailer->Password = $SMTP_PWD;
$mailer->setFrom($FROM_EMAIL, $FROM_NAME);
$mailer->addAddress($TO_EMAIL, $TO_NAME);
$mailer->isHTML(true);                                  // Set email format to HTML
$mailer->Subject = $EMAIL_SUBJECT;
$mailer->Body    = buildEmail($email_vars, $EMAIL_BODY);
$mailer->AltBody = $EMAIL_ALT_BODY;

function buildEmail($vars, $template) {
	return preg_replace_callback('/\{([^\{]{1,100}?)\}/', 
								 function($match) use($vars) { 
									 return $vars[$match[1]]; 

This is the basic template.

			<td colspan="2"></td>
			<td colspan="2">Please review the attached recording</td>

(Dickson) #53

Ooo this is good! We’ve been wanting to make some changes with a client with a similar deployment. I’ll give this one a try tks!

(Tom Ray) #54

Let me know if you need anything.