Click to dial (Simple webpage layout and php script)


#1

Can anyone see a problem with the below, except for the fact the HTML fields are not all there.

Here is the HTML Part (notice its has not been updated to match PHP.)

-- index.html --:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> 
<head> <title>Interactive Calling</title> <meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1"> </head> <body>
<form name="calling" method="post" action="place-call.php">
     <table>
       <tr>
         <td>Phone:</td>
         <td><input name="caller" type="text" id="un">
       </td>
       </tr>
       <tr>
         <td>&nbsp;</td>
         <td><input type="submit" name="Submit" value="Call Me Now"></td>
       </tr>
     </table>
   </form>
   <br/>
</html>

And Here is the PHP part:

[code]<?php

error_reporting( E_ALL );

$caller = $_GET[ “caller” ];
if( $caller == “” )
{ $caller = $_POST[ “caller” ]; }
if( $caller == “” )
{ $caller = “15197777777”; }

$callee = $_GET[ “callee” ];
if( $callee == “” )
{ $callee = $_POST[ “callee” ]; }
if( $callee == “” )
{ $callee = “15198888888”; }

$station_to_call = “SIP/SIPPROVIDER/$calee”; $spool_dir =
"/var/spool/asterisk/outgoing"; $temp_dir = $spool_dir . “/tmp” .
$caller; $call_file = $temp_dir . “/$caller.call”;

mkdir( $temp_dir );

$file = fopen( $call_file, “w” );
fputs( $file, “Channel: $station_to_call\n” ); fputs( $file,
“Callerid: $caller\n” ); fputs( $file, “MaxRetries: 1\n” ); fputs(
$file, “RetryTime: 60\n” ); fputs( $file, “WaitTime: 30\n” ); fputs(
$file, “Context: dial_auto\n” ); fputs( $file, “Extension: $caller\n” ); fputs( $file, “Priority: 1\n” ); fclose( $file );

rename( $call_file, $spool_dir."/$caller.call" ); rmdir( $temp_dir );

Header( “302 Moved” );
Header( “Location: index.html” );

?>

[/code]


#2

we have something similar, but instead of building a CALL file, i connect to the manager via a socket and issue an originate command - it’s noticably faster (almost instantaneous) to ring the target phone, plus you can re-use the code to do other things via the manager interface (we use it for live call monitoring, taking agents in and out of queue, etc).

i can post the code if anyone is interested - it ain’t much, but it works.


#3

please post


#4

here goes, this is a function that allows you to send all of your socket params to asterisk…it’s soemthing i wrote a while back, and it was pretty quick and dirty, so all of you PHP gurus please be gentle.

[code]function send_socket($socket_host,$socket_login, $socket_pass, $socket_port,$socket_errno,$socket_errstr,$socket_timeout, $socket_action, $socket_command)
{
$socket = fsockopen($socket_host,$socket_port,$socket_errno,$socket_errstr,$socket_timeout);
if (!$socket)
{
return “$socket_errstr - $socket_errno”;
}

fputs($socket, “Action: Login\r\n”);
fputs($socket, “UserName: $socket_login\r\n”);
fputs($socket, “Secret: $socket_pass\r\n\r\n”);

if($socket_action==‘Command’ && $socket_action != ‘’)
{
fputs($socket, “Action: $socket_action\r\n”);
fputs($socket, “Command: $socket_command\r\n\r\n”);
}
elseif ($socket_action != ‘’)
{
fputs($socket, “Action: $socket_action\r\n\r\n”);
}

fputs($socket, “Action: Logoff\r\n\r\n”);

while (!feof($socket)) {
$output .= fread($socket, 8192);
}

fclose($socket);

return $output;
}
[/code]

so, to initiate a call, i’d do soemthing like this:

$number = '91'.$_GET['number'];
$extension = 'sip/'.$_GET['ext'];

$action = "Originate\r\n";
$action .= "Channel: $extension\r\n";
$action .= "Extension: $number\r\n";
$action .= "Context: from-inside\r\n";
$action .= "Priority: 1\r\n";
$action .= "Timeout: 5000\r\n";

$output = send_socket($socket_host,$socket_login, $socket_pass, $socket_port,$socket_errno, $socket_errstr, $socket_timeout, $action, '');

that’s it, in a nutshell…keep in mind that i do not use the originate command to initiate outgoing calls, so there might be one or two things wrong with this, but it should be fairly close.

have fun.


#5

Zero, your PHP code is messed up, majorly…

The html:
Remove the
id="un"
from the code, not needed.

The PHP:

You refer to a filed called “callee”, its not in your HTML!
(Which you wrote tho…)

Note, you dont need the _get in PHP, you can always refer to passed variables by its simple name !

Also, i assume for now you are using ZAP channel ?
Or SIP via internet ?
Cause the dial command needs the technologie in your callfile as well, its missing so far…

Lets assume ZAP configured as group 1, change it to your need.

Also, lets raise the retrys - since you need no retrytime without a retry :stuck_out_tongue:

<?php 

if ($caller=="") 
{
   echo "Dude....how should i call you back without a number, genius...";
   echo "<br>Go back and try again!";
   exit;
}

Dont worry with tempfiles in the outgoing directory:
Asterisk cant acces it while PHP has it hands on it, so no problem here !
Write it directly, no need to copy.
Copy is only suggested for users creating a file in the outgoing directory and then filling it with eg. "kate".

$station_to_call="SIP/SIPPROVIDER/".$caller;
$spool_dir="/var/spool/asterisk/outgoing";
//^^^^^^make sure the webserver has rights/access to this Dir !!!!

$call_file = $spool_dir . "/".$caller."call"; 

$file = fopen( $call_file, "w" ); 

fputs( $file, "Channel: ZAP/g1/". $caller."\n" );
fputs( $file, "MaxRetries: 3\n" ); 
fputs( $file, "RetryTime: 45\n" );
fputs( $file, "WaitTime: 30\n" );
fputs( $file, "Context: dial_auto\n" ); 
//(Note: Are you sure your extensions exist here? And the context does?)

fputs( $file, "Extension: 55-55-50".$caller."\n" );
fputs( $file, "Priority: 1\n" );
fclose( $file ); 

Header( "Location: index.html" ); 

?>

Ok, try this one. Might have some errors, i have not tested it, but should work (“should”…i love this word…:stuck_out_tongue: )


#6

LOL, sorry whois…our postings crossed, i had mine like 2 hours in the editor while having a meeting here…then i hit SUBMIT.


#7

no worries Richard - hell, i’m not even sure my code is all that great - i just know that it works for us…lol


#8

It should, its a common sniplet floating around in the net.

Generally, its the approach of using the manager application to initiate a call via port 5038.

My approach was to generate a callfile.

So two different ways but both with the same result :stuck_out_tongue:

The manager solution has an advantage:
You can spawn the call in the default context with caller-ID and !NAME! the moment the call is initiated, which a callfile cannot.

The advantage of the callfile is, that it checks itselfs if the called party is free and retrys if not so - you dont need to handle that manually.

Which isnt THAT biggie btw, i programmed a
"callback when busy"-function on our PSNT interface, which isnt supported by our telco.

So i did it “by hand” - which is working, yay :stuck_out_tongue:


#9

Hi

Personaly I use the manager method. I did use a callfile method but “correctly” as to call files, Ie written in a location then moved to the outgoing directory so doesnt get acted upon while writing.
I also pass form data to the set via the callerid. so users know what the calls about and who the caller is.

Ian