February 19, 2008

Some Dialplans & AGI tricks

Send mail with attach file
I found the example from here. The script use for send email and attach attach recording file. ( convert to mp3 by lame)

#!/usr/bin/php -q

include ("ast_db_connects.php");
// Invoke Asterisk PHP Library
require ("phpagi.php");
$agi = new AGI($cfgfile = "/etc/asterisk/phpagi.conf");
// Class for sending via Sendmail
require ("class.phpmailer.php");
$vmail_ext = $agi->get_var("VMAIL_EXT");
// Initialize database
$db_query = "SELECT * FROM short_dials WHERE dial_code='$vmail_ext'";
$db_link = mysql_connect($db_host, $db_user, $db_pass);
if (!db_link)
die('Could not connect: ' . mysql_error());
@mysql_select_db($db_name) or die("Unable to select database");
//Fetch the email address and name of the person
$db_result = mysql_query($db_query);
$db_rows = mysql_numrows($db_result);
echo "" . $db_rows . "\n\n";
if ($db_rows > 0)
$email_address = mysql_result($db_result, 0, "email");
$email_name = mysql_result($db_result, 0, "name");
//Convert audio file from wav to mp3
exec("lame -h /tmp/asterisk/voicemail.wav /tmp/asterisk/voicemail.mp3");
// Send email
$mail = new PHPMailer();
$mail->From = "joe@blow.net";
$mail->FromName = "Joe Blow";
$mail->AddAddress("$email_address", "$email_name");
$mail->AddReplyTo("joe@blow.net", "Joe Blow");
$mail->Subject = "MP3 Voicemail from Mr Blow";
$mail->Body = "Hello,\n\nAttached is a voicemail from me! Should play in your RealPlayer or Windows Media Player.\n\nRegards,\n\nJoe";
if (!$mail->Send())
echo "mess up\n";
echo "Mailer Error: " . $mail->ErrorInfo;
echo "Success\n";

Send to Voicemail if the call is not available
I found from http://astbill.com/node/399.

; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well

exten => s,1,AGI(astlocal.agi,${ARG1})
exten => s,2,Dial(SIP/${MACRO_EXTEN},20); Ring the interface, 20 seconds maximum
exten => s,3,Goto(s-${DIALSTATUS},1); Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => s-NOANSWER,1,Voicemail(u${VOICEMAIL}); If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1); If they press #, return to start

exten => s-BUSY,1,Voicemail(b${VOICEMAIL}); If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1); If they press #, return to start

exten => _s-.,1,Goto(s-NOANSWER,1); Treat anything else as no answer
exten => a,1,VoicemailMain(${VOICEMAIL}); If they press *, send the user into VoicemailMain

uwsg.indiana.edu: asterisk-uug.pdf
vlug.org: VLUG-Telephony.pdf
wiki.ekiga.org: Asterisk and Voicemail
cavazos.com.mx: Asterisk-AGI
astricon.net: Asterisk in the Free World dialup
Asterisk tips ivr menu

No comments: