Redial Midterm: Cloud Contacts
Proposal:
Creating a VoIP Phonebook that gives people access to their contacts without relying on a physical device.
Background:
This semester, I am taking Redial: Interactive Telephony at Tisch’s ITP with prof. Chris Kairalla and my midterm, a VoIP phonebook, will be part of a larger calling card system.
From my conversations with outreach and social workers, homeless individuals who are given communication tools such as cell phones, voice mail or phone cards tend to regain a sense of identity and show more desire to attain housing and employment. Organizations who support them also benefit in being able to communicate with, locate, and build better rapport with their homeless clients.
By using a VoIP phonebook, clients do not have to rely on a written list or on a cell phone’s memory to access their contacts, useful for when a client loses a phone or it runs out of electrical charge/funds. It can be accessed from any device that can call the phonebook’s number.
Overview:
Clients call 1-212-660-0239 Extension 108 to access their phonebooks.
When clients call the phonebook for the first time, the program acknowledges this and records their name. The program then leads the clients to add their first contact.
Clients can add to or change their contacts by pressing 0 from the main menu. They will have a choice between the numbers 2 and 9 to associate their contacts with.
Returning clients can choose between extensions 1 to 9, which are associated with their contact’s phone number. Their first contact, extension 1, will always be their case worker and clients will not be able to alter it.
When a client calls a contact person, the program says aloud the numbers that it is dialing. If the contact also uses the phonebook, the program replaces the digits with a recording of their name. This is a rudimentary feature of the larger social network that I am planning to integrate into the calling card system.
Dialplan / PHP AGI:
Segments of the Extensions.conf that are relevant to the operations are pasted below.
[aw75_midterm] ; Midterm
exten => s,1,AGI(/home/aw75/asterisk_agi/phonebook_greet.php); Greets to phonebook
exten => s,2,Background(/home/aw75/asterisk_sounds/pbk/dialexten);
exten => s,n,Background(/home/aw75/asterisk_sounds/pbk/dialzero);
exten => s,n,WaitExten(15);
exten => s,n,Goto(aw75_midterm,s,2) ; playback loop
exten => _X,1,AGI(/home/aw75/asterisk_agi/phonebook.php); Goes to phonebook
exten => 0,1,AGI(/home/aw75/asterisk_agi/phonebook_add.php); Adds to phonebook
Currently, I am using three separate PHP scripts, but am realizing I probably could do with just one. But for now, the three I am using are pasted below.
phonebook_greet.php
#!/usr/bin/php -q
<?PHP
require('/var/lib/asterisk/agi-bin/phpagi.php');
$agi = new AGI();
/* Define Caller's Info */
$callerid = '1'.$agi->request["agi_callerid"];
/*Greet old user*/
if(file_exists('/home/aw75/pbk/'.$callerid.'/1.txt'))
{
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/welcomeback');
sleep(1);
$agi->goto('aw75_midterm','s',2);
}
/*Greet new user*/
else
{
mkdir('/home/aw75/pbk/'.$callerid, 0755);
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/hellowelcome');
sleep(1);
/*Record name*/
while($accept!=1){
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/sincefirst');
sleep(1);
$agi->record_file('/home/aw75/pbk/'.$callerid.'/name', 'ul', '0123456789#*', 10000, 0, true, 5);
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/hello');
$agi->stream_file('/home/aw75/pbk/'.$callerid.'/name');
sleep(1);
$name = $agi->get_data('/home/aw75/asterisk_sounds/pbk/nameright', 10000, 1);
$accept = $name['result'];
}
$pbk = '/home/aw75/pbk/'.$callerid.'/1.txt';
$dialout = 13479054627;
$file = fopen($pbk,'w');
fwrite($file, $dialout);
fclose($file);
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/letsadd');
sleep(1);
$agi->goto('aw75_midterm',0,1);
}
/* End AGI Scripting */
?>
phonebook_add.php
#!/usr/bin/php -q
<?PHP
require('/var/lib/asterisk/agi-bin/phpagi.php');
$agi = new AGI();
/* Define Caller's Info */
$callerid = '1'.$agi->request["agi_callerid"];
/*Define extension*/
$getextension = $agi->get_data('/home/aw75/asterisk_sounds/pbk/dial29', 10000, 1);
$extension = $getextension['result'];
if($extension < 2){
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/notvalidentry');
$agi->goto('aw75_midterm',0,1);
}
else
{
$agi->say_digits($extension);
/*Define number to dial*/
$getdialout = $agi->get_data('/home/aw75/asterisk_sounds/pbk/enternumber', 10000, 11);
$dialout = $getdialout['result'];
if(strlen($dialout) < 11){
//Real number check to be added in the future
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/notvalidnumber');
$agi->goto('aw75_midterm',0,1);
}
else {
if(file_exists('/home/aw75/pbk/'.$dialout.'/name.ul')) {
$agi->stream_file('/home/aw75/pbk/'.$dialout.'/name');
sleep(1);
}
else {
$agi->say_digits($dialout);
}
/*Write to file*/
$pbk = '/home/aw75/pbk/'.$callerid.'/'.$extension.'.txt';
$file = fopen($pbk,'w');
fwrite($file, $dialout);
fclose($file);
$agi->goto('aw75_midterm','s',2);
}
}
/* End AGI Scripting */
?>
phonebook.php
#!/usr/bin/php -q
<?PHP
require('/var/lib/asterisk/agi-bin/phpagi.php');
$agi = new AGI();
/* Define Caller's Info */
$callerid = '1'.$agi->request["agi_callerid"];
$extension = $agi->request["agi_extension"];
/*Define number to dial*/
$pbk = '/home/aw75/pbk/'.$extension.'.txt';
$file = fopen($pbk,'r');
$dialout = fgets($file);
fclose($file);
$agi->stream_file('/home/aw75/asterisk_sounds/pbk/calling');
if(file_exists('/home/aw75/pbk/'.$dialout.'/name.ul'))
{
$agi->stream_file('/home/aw75/pbk/'.$dialout.'/name');
sleep(1);
}
else
{
$agi->say_digits($dialout);
}
$agi->exec('DIAL SIP/itp_jnctn/'.$dialout.',10,t');
/* End AGI Scripting */
?>
Future:
I hope to finish a fleet of VoIP tools that underserved populations may utilize as my final project, a low-cost open source calling card system. The phonebook that I’m presenting as my midterm will be further refined and play a major role within the calling card system.