Friday, June 18, 2010

BroadCast Voice message through Asterisk

Broad casting Message through Asterisk
Creating a call file to call 1000 context default in the sip.conf file

; set the caller ID to sales call placing the call
; A correct Caller ID may be required when using some VOIP to PSTN gateway services.
;
; cat < /var/spool/asterisk/tmpoutgoing
; Channel: SIP/1000
; Callerid: sales call
; MaxRetries: 5
; RetryTime: 300
; WaitTime: 45
; Context:
default
; Extension: 1234
; Priority: 1
; EOF
; mv /var/spool/asterisk/tmp01 /var/spool/asterisk/outgoing


This is a sample section from an extensions.conf file showing how to auto-dial an outbound కాల్

[default]

exten=> 1234,1,Answer()
exten => 1234,2,Wait(1)
exten =>
1234,3,Background(welcome to company) ; "play outbound msg"
exten =>
1234,4,Background(preview ) ; "Press 1 to replay or 2 to acknowledge receiving this మెసేజ్ ప్రెస్ తో కాంటాక్ట్ యువర్ agent"
exten => 1,1,Goto(default ,1234,3) ; replay message
exten => 2,1,Goto(bye,1,1) ; acknowledge message
exten => t,1,Playback(vm-goodbye) timeout play bye
exten => t,2,hangup hangup


[bye]

exten=> 1,Playback(thank u for your valuable time)
exten=> 2,palyback(goodbye)
exten => 3,Hangup()


If you have good knowledge in agi scripting

through orignate commands

Agi scritping using agi::asterisk and net ::telenet

#!/usr/bin/perl


# Namespace Declarartion
#####################################################################################################
use Asterisk::AGI;
use Net::Telnet;

$US='_';
######################################################################################################

$AGI = new Asterisk::AGI;

$|=1;
while() {
chomp;
last unless length($_);
if ($V)
{

if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}

if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1;}
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
if (/^agi_type\:\s+(.*)$/) {$type = $1;}
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
if (/^agi_context\:\s+(.*)$/) {$context = $1;}

}



&Originate();


sub Originate
{

$Username = "cron";
$Secret = "1234";
$MyPhone = "SIP/1000";
$MyPhoneEscaped = "SIP\\/1000";

# Connect to localhost via telnet on the Asterisk manager port.
$TelnetClient = new Net::Telnet (Timeout => 10,
Errmode => "die",
Host => "localhost",
Port => 5038);

# Login with our username and secret.
$TelnetClient->open ();
$TelnetClient->print ("Action: Login");
$TelnetClient->print ("Username: $Username");
$TelnetClient->print ("Secret: $Secret");
$TelnetClient->print ("");

# Check for login success.
($Prematch, $Match) = $TelnetClient->waitfor ("/Message: .*/");


if (($Prematch =~ m/Success/) && ($Match =~ m/Authentication/)) {
print "Good authentication.\n";
}
else {
print "Authentication failed.\n";
exit;
}


print "Dialing $CurrentNumber...\n";
$TelnetClient->print ("Action: Originate");
$TelnetClient->print ("Channel: $MyPhone");
$TelnetClient->print ("Exten: 1234");
$TelnetClient->print ("Priority: 2");
$TelnetClient->print ("Callerid: \"nagarjuna\" <$CurrentNumber>");
$TelnetClient->print ("");

($Prematch, $Match) = $TelnetClient->waitfor ("/Message: .*/");

if (($Match =~ m/Originate/) && ($Prematch =~ m/Success/)) {
$OriginateSuccess = 1;
print "Origination success.\n";
}
else {
print "Origination failure.\n";
sleep (2);
}

print "Waiting...\n";

$OnThePhone = 1;

while ($OnThePhone) {
($Prematch, $Match) = $TelnetClient->waitfor (match => "/Uniqueid: .*/",
timeout => 60);
print "Event detected.\n";

if (($Prematch =~ m/Hangup/) && ($Prematch =~ m/$MyPhoneEscaped/)) {
$OnThePhone = 0;
}
}
}
##################################Check 200 Reply ####################################

sub checkresult {
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/) {
$res =~ /result=(-?\d+)/;
if (!length($1)) {
print STDERR "FAIL ($res)\n";
$fail++;
} else {
print STDERR "PASS ($1)\n";
$pass++;
}
}
else {
print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}



1 comment:

  1. Good post....One Problem...Data is not inserting into CDR database for .call file...any solution for that...

    ReplyDelete