Asterisk manager API - Click to call
Par Yoann, mardi 1 avril 2008 à 15:14 :: VOIP Asterisk & Telephonie :: #117 :: rss
Voici un petit script perl qui va vous permettre de rappeler automatiquement les personnes qui en font la demande via votre site internet. Cette fonctionnalité s'appel "Click-to-call".
- Le visiteur, rempli sont numéro de téléphone au format international dans un forumaire.
- Votre téléphone sonne
- Une fois que vous avez decroché, la numération du numéro de telephone du visiteur s'effectue.
ATTENTION : Ce script est donnée à titre d'exemple. Vous devez d'adapter a votre besoin, et y ajouter des regles de sécurité.
Ici une connexion socket est étalie avec l'api de asterisk, afin de s'identifier, et de lui passer les paramêtres appelant/appeler.
#!/usr/bin/perl
use IO::Socket::INET ;
my $EOL = "\015\012";
my $BLANK = $EOL x 2;
my $AMPUSER = "admin"; # Voir Fichier /etc/asterisk/manager.conf
my $AMPPASS = "amp111";
my $CHANNEL = "SIP/1234"; # Votre extension SIP
my $WAITTIME = "30";
my $CALLERID = "WebCall <33101020304>"; # Votre numéro, visible par l'appélé et l'appelant
sub call {
my ($EXTEN) = @_;
$EXTEN = '0'.$EXTEN;
my $socket = IO::Socket::INET -> new (
PeerAddr => '127.0.0.1' ,
PeerPort => 5038 ,
Proto => 'tcp' ,
Type => SOCK_STREAM
);
$socket->autoflush(1);
#$socket -> recv ( $message , 128 ) ;
#print $message ;
print $socket "Action: Login${EOL}Username: ${AMPUSER}${EOL}Secret: ${AMPPASS}$BLANK";
print $socket "Action: originate${EOL}Channel: ${CHANNEL}${EOL}WaitTime: ${WAITTIME}${EOL}CallerId: ${CALLERID}${EOL}Exten: ${EXTEN}${EOL}Context: from-internal${EOL}Priority: 1$BLANK";
print $socket "Action: Logoff$BLANK";
}
my (%postdata,$data,$pair);
$data='';
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
my $len=$ENV{'CONTENT_LENGTH'};
if (read(STDIN,$data,$len) != $len) {print ("<H1>error reading post data </H1>"); die("Error reading 'POST' data\n"); }
}
elsif ($ENV{'REQUEST_METHOD'} eq 'GET') {
$data=$ENV{'QUERY_STRING'};
}
foreach $pair (split('&',$data)) {
my ($name,$value)=split('=',$pair);
$name=~ tr/\0//d;
$name =~ tr/+/ /;
$name =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
$postbrut{$name}=$value;
$value=~ tr/\0//d;
$value=~ tr/+/ /;
$value=~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
$postdata{$name}=$value;
}
print "Content-type: text/html\n\n";
if ($postdata{txtphonenumber} eq '') {
print <<EOF
<p>
<table width="300" border="1" bordercolor="#630000" cellpadding="3" cellspacing="0">
<tr><td>
<font size="2" face="verdana,arial,georgia" color="#630000">Enter your phone number in international format (33XXXXXXXXX), and we will call you a few seconds later!</font>
<form action="" method="post">
<input type="text" size="20" maxlength="20" name="txtphonenumber"><br>
<input type="submit" value="Call Us!">
</form>
</td></tr>
</table>
</p>
EOF
} else {
call($postdata{txtphonenumber});
print <<EOF
<p>
<table width="300" border="1" bordercolor="#630000" cellpadding="3" cellspacing="0">
<tr><td>
<font size="2" face="verdana,georgia" color="#630000">We are currently trying to call you. Please be patient, and wait for your phone to ring!<br>If your phone does not ring after 2 minutes, we apologize, but must either be out, or already on the phone.<br><a href="">Try Again</a></font>
</td></tr>
</table>
</p>
EOF
}
Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire