Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@server [~]# cat /home/tipsfora/cron_scripts/cron_callQueue.php
- <?php
- /**
- * cron task
- * every 10mins
- * Mon-Fri : 9:00 am to 5:00 pm Eastern Standard Time
- * Call center working hours
- */
- $db_engine = 'mysql';
- $db_host = 'localhost';
- $db_name = 'tipsfora_wp_education4us';
- $db_user = 'tipsfora_edu4u';
- $db_pass = '$?[a.C50gemS';
- $db_table = 'twilio_phonebook';
- $dsn = $db_engine.':dbname='.$db_name.';host='.$db_host;
- $db = new PDO($dsn, $db_user, $db_pass);
- # select number from database by timestamp
- $dbst = $db->prepare(
- "SELECT * FROM {$db_table}
- WHERE called = 0
- ORDER BY i_timestamp
- LIMIT 1");
- $select = $dbst->execute();
- $contact = $dbst->fetch(PDO::FETCH_ASSOC);
- //print_r($contact);
- # make call
- if ($contact && is_array($contact)
- && array_key_exists('phone', $contact)
- && !empty($contact['phone'])) {
- // Twilio REST API version
- $version = "2010-04-01";
- $sid = 'AC55c50e524d55e654881f60b31a63793f';
- $token = '57e81d2f8bcfaddcc2b7d409511ef5a4';
- $twilio_no = '+97243729039';
- $callTo = '+1' . trim($contact['phone'], ' +');
- $id = $contact['id'];
- $name = $contact['first'];
- $url = 'http://www.education4us.com/twilio/call_center/';
- // Include the Twilio PHP library
- require_once('/home/tipsfora/lib/twilio-php/Services/Twilio.php');
- // Instantiate a new Twilio Rest Client
- $client = new Services_Twilio($sid, $token, $version);
- try {
- // Initiate a new outbound call
- $call = $client->account->calls->create(
- $twilio_no, // The number of the phone initiating the call
- $callTo, // The number of the phone receiving call
- $url.'screen-caller.php?id='.$id.'&name='.$name.'&phone='.$callTo, // The URL Twilio will request when the call is answered
- array()
- );
- //echo 'Started call: ' . $call->sid;
- } catch (Exception $e) {
- echo 'Error: ' . $e->getMessage();
- }
- }
- # log successful call
- if ($contact && is_array($contact)
- && array_key_exists('id', $contact)
- && !empty($contact['id'])) {
- $dbst = $db->prepare(
- "UPDATE {$db_table} SET
- called = 1, call_time = NOW()
- WHERE id = :id");
- $update = $dbst->execute(array(
- ':id'=>$contact['id']));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement