Advertisement
Guest User

Phonescript

a guest
Nov 6th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. root@server [~]# cat /home/tipsfora/cron_scripts/cron_callQueue.php
  2. <?php
  3. /**
  4. * cron task
  5. * every 10mins
  6. * Mon-Fri : 9:00 am to 5:00 pm Eastern Standard Time
  7. * Call center working hours
  8. */
  9.  
  10. $db_engine = 'mysql';
  11. $db_host = 'localhost';
  12. $db_name = 'tipsfora_wp_education4us';
  13. $db_user = 'tipsfora_edu4u';
  14. $db_pass = '$?[a.C50gemS';
  15. $db_table = 'twilio_phonebook';
  16. $dsn = $db_engine.':dbname='.$db_name.';host='.$db_host;
  17. $db = new PDO($dsn, $db_user, $db_pass);
  18.  
  19. # select number from database by timestamp
  20. $dbst = $db->prepare(
  21. "SELECT * FROM {$db_table}
  22. WHERE called = 0
  23. ORDER BY i_timestamp
  24. LIMIT 1");
  25.  
  26. $select = $dbst->execute();
  27.  
  28. $contact = $dbst->fetch(PDO::FETCH_ASSOC);
  29. //print_r($contact);
  30.  
  31. # make call
  32. if ($contact && is_array($contact)
  33. && array_key_exists('phone', $contact)
  34. && !empty($contact['phone'])) {
  35.  
  36. // Twilio REST API version
  37. $version = "2010-04-01";
  38. $sid = 'AC55c50e524d55e654881f60b31a63793f';
  39. $token = '57e81d2f8bcfaddcc2b7d409511ef5a4';
  40.  
  41. $twilio_no = '+97243729039';
  42. $callTo = '+1' . trim($contact['phone'], ' +');
  43.  
  44. $id = $contact['id'];
  45. $name = $contact['first'];
  46.  
  47. $url = 'http://www.education4us.com/twilio/call_center/';
  48.  
  49. // Include the Twilio PHP library
  50. require_once('/home/tipsfora/lib/twilio-php/Services/Twilio.php');
  51.  
  52. // Instantiate a new Twilio Rest Client
  53. $client = new Services_Twilio($sid, $token, $version);
  54.  
  55. try {
  56.  
  57. // Initiate a new outbound call
  58. $call = $client->account->calls->create(
  59. $twilio_no, // The number of the phone initiating the call
  60. $callTo, // The number of the phone receiving call
  61. $url.'screen-caller.php?id='.$id.'&name='.$name.'&phone='.$callTo, // The URL Twilio will request when the call is answered
  62. array()
  63. );
  64. //echo 'Started call: ' . $call->sid;
  65. } catch (Exception $e) {
  66. echo 'Error: ' . $e->getMessage();
  67. }
  68.  
  69. }
  70.  
  71. # log successful call
  72. if ($contact && is_array($contact)
  73. && array_key_exists('id', $contact)
  74. && !empty($contact['id'])) {
  75. $dbst = $db->prepare(
  76. "UPDATE {$db_table} SET
  77. called = 1, call_time = NOW()
  78. WHERE id = :id");
  79. $update = $dbst->execute(array(
  80. ':id'=>$contact['id']));
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement