private function twilio_token() { include APPPATH . '../vendor/twilio/sdk/Services/Twilio/Capability.php'; $capability = new Services_Twilio_Capability($this->config->item('twilio_account_sid'), $this->config->item('twilio_auth_token')); $capability->allowClientOutgoing($this->config->item('twilio_app_sid')); $token = $capability->generateToken(); return $token; }
function cn_browser_record_shortcode() { // twilio account codes, found in twilio account // production $accountSid = 'ACffb19fe3b7d08d4aa16089e200b47061'; $authToken = '55b1273b328b91e083d44f551ccf3072'; $token = new Services_Twilio_Capability($accountSid, $authToken); // production $token->allowClientOutgoing('AP3574db8be33441918142805cc0a10352'); $output = ''; $output .= '<div align="center">'; $output .= '<input type="button" class="callbutton" id="call" value="Start Recording"/>'; $output .= '<input type="button" class="stopbutton" id="stop" value="Stop Recording" style="display:none;"/>'; $output .= '<div id="status">'; $output .= 'Offline'; $output .= '</div>'; $output .= '</div>'; $output .= '<script type="text/javascript">'; $output .= 'jQuery(document).ready(function(){'; $output .= 'Twilio.Device.setup("' . $token->generateToken() . '",{"debug":true});'; $output .= 'jQuery("#call").click(function() {'; $output .= 'Twilio.Device.connect();'; $output .= '});'; $output .= 'jQuery("#stop").click(function() {'; $output .= 'connection.sendDigits("#");'; $output .= '});'; $output .= 'jQuery("#hangup").click(function() {'; $output .= 'Twilio.Device.disconnectAll();'; $output .= '});'; $output .= 'Twilio.Device.ready(function (device) {'; $output .= 'jQuery("#status").text("Ready to start recording");'; $output .= '});'; $output .= 'Twilio.Device.offline(function (device) {'; $output .= 'jQuery("#status").text("Offline");'; $output .= '});'; $output .= 'Twilio.Device.error(function (error) {'; $output .= 'jQuery("#status").text(error);'; $output .= '});'; $output .= 'Twilio.Device.connect(function (conn) {'; $output .= 'connection=conn;'; $output .= 'jQuery("#status").text("On Air");'; $output .= 'jQuery("#status").css("color", "red");'; $output .= 'toggleCallStatus();'; $output .= '});'; $output .= 'Twilio.Device.disconnect(function (conn) {'; $output .= 'jQuery("#status").text("Recording ended");'; $output .= 'jQuery("#status").css("color", "black");'; $output .= 'toggleCallStatus();'; $output .= '});'; $output .= 'function toggleCallStatus(){'; $output .= 'jQuery("#call").toggle();'; $output .= 'jQuery("#stop").toggle();'; $output .= '};'; $output .= '})'; $output .= '</script>'; return $output; }
public static function VOIP($USER) { require_once 'controllers/v-controllers/twilio/Twilio/Capability.php'; echo '<script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script>'; $capability = new Services_Twilio_Capability($TWILIO['SID'], $TWILIO['TOKEN']); $capability->allowClientOutgoing($TWILIO['ASID']); $capability->allowClientIncoming($USER['username']); $token = $capability->generateToken(); }
function testDecodeWithAuthToken() { try { $token = new Services_Twilio_Capability('AC123', 'foo'); $payload = JWT::decode($token->generateToken(), 'foo'); } catch (UnexpectedValueException $e) { $this->assertTrue(false, "Could not decode with 'foo'"); } }
public function Capability($userId, $companyId = NULL) { if ($companyId && array_key_exists($companyId, $this->config)) { $capability = new \Services_Twilio_Capability($this->config[$companyId]['sid'], $this->config[$companyId]['token']); } else { $capability = new \Services_Twilio_Capability($this->config['sid'], $this->config['token']); } $userId = str_replace("-", "", $userId); $capability->allowClientIncoming($userId); if ($companyId && array_key_exists($companyId, $this->config)) { $capability->allowClientOutgoing($this->config[$companyId]['app_sid']); } else { $capability->allowClientOutgoing($this->config['app_sid']); } return $capability->generateToken(3600 * 24); }
function loadTwilioClient() { global $current_user, $sugar_config; //var_dump($current_user);die(); $agentId = md5($current_user->id); $twilio_connector = new ext_rest_twilio(); $accountSid = $twilio_connector->getProperty('twilio_account_id'); $authToken = $twilio_connector->getProperty('twilio_auth_token'); $appSid = $twilio_connector->getProperty('twilio_app_id'); $capability = new Services_Twilio_Capability($accountSid, $authToken); $capability->allowClientOutgoing($appSid); $capability->allowClientIncoming($agentId); $token = $capability->generateToken(); $twilio_client_tpl = "custom/include/Twilio/twilio_client.tpl"; $smarty = new Sugar_Smarty(); $smarty->assign("TWILIO_TOKEN", $token); $smarty->assign("SITE_URL", $sugar_config['site_url']); echo $smarty->fetch($twilio_client_tpl); }
/** * Generate a capability token for Twilio Client * * @param string $allow_incoming * @return string */ function generate_capability_token($allow_incoming = true) { $ci =& get_instance(); $capability = new Services_Twilio_Capability($ci->twilio_sid, $ci->twilio_token); $user_id = intval($ci->session->userdata('user_id')); $user = VBX_user::get(array('id' => $user_id)); $params = array('user_id' => $user->user_id); $token = null; try { $capability->allowClientOutgoing($ci->application_sid, $params); if ($allow_incoming) { $capability->allowClientIncoming($user->id); } $token = $capability->generateToken(VBX_Settings::CLIENT_TOKEN_TIMEOUT); } catch (Exception $e) { log_message('error', $e->getMessage()); } return $token; }
function twilio_call() { $myoptions = get_option('twilio_settings'); // set your AccountSid and AuthToken from www.twilio-message.com/user/account // $AccountSid = "AC83cb26bcf5ba5aa750d0ffe50e299b22"; // $AuthToken = "96617fb14d4ee91f4fbef6edf8682ed6"; $AccountSid = $myoptions['twilio_account_sid']; $AuthToken = $myoptions['twilio_auth_token']; // put your Twilio Application Sid here //$appSid = 'APf8a37ec0049142b87441bd9dc56fa19f'; $appSid = $myoptions['twilio_app_sid']; $post = get_post($_POST['skillid']); $advisor = $post->post_author; $advisor_mobile = get_user_meta($advisor, 'mobile_number', true); // put your default Twilio Client name here $clientName = $_POST['skillid']; $capability = new Services_Twilio_Capability($AccountSid, $AuthToken); $capability->allowClientOutgoing($appSid); $capability->allowClientIncoming($clientName); $token = $capability->generateToken(); $return = array('token' => $token, 'mobile' => $advisor_mobile); wp_send_json_success($return); }
/** * @return array */ public function AjaxTwilioGetToken() { $oAccount = $this->getAccountFromParam(); $oTenant = null; if ($this->oApiTenants) { $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->getTenantById($oAccount->IdTenant) : $this->oApiTenants->getDefaultGlobalTenant(); } $mToken = false; if ($oTenant && $this->oApiCapability->isTwilioSupported($oAccount) && $oTenant->isTwilioSupported() && $oTenant->TwilioAllow && $oAccount->User->TwilioEnable && file_exists(PSEVEN_APP_ROOT_PATH . 'libraries/Services/Twilio.php')) { try { include PSEVEN_APP_ROOT_PATH . 'libraries/Services/Twilio.php'; // Twilio API credentials $sAccountSid = $oTenant->TwilioAccountSID; $sAuthToken = $oTenant->TwilioAuthToken; // Twilio Application Sid $sAppSid = $oTenant->TwilioAppSID; $sTwilioPhoneNumber = $oTenant->TwilioPhoneNumber; $bUserTwilioEnable = $oAccount->User->TwilioEnable; $sUserPhoneNumber = $oAccount->User->TwilioNumber; $bUserDefaultNumber = $oAccount->User->TwilioDefaultNumber; $oCapability = new \Services_Twilio_Capability($sAccountSid, $sAuthToken); $oCapability->allowClientOutgoing($sAppSid); \CApi::Log('twilio_debug'); \CApi::Log('twilio_account_sid-' . $sAccountSid); \CApi::Log('twilio_auth_token-' . $sAuthToken); \CApi::Log('twilio_app_sid-' . $sAppSid); \CApi::Log('twilio_enable-' . $bUserTwilioEnable ? 'true' : 'false'); \CApi::Log('twilio_user_default_number-' . ($bUserDefaultNumber ? 'true' : 'false')); \CApi::Log('twilio_number-' . $sTwilioPhoneNumber); \CApi::Log('twilio_user_number-' . $sUserPhoneNumber); \CApi::Log('twilio_debug_end'); //$oCapability->allowClientIncoming('TwilioAftId_'.$oAccount->IdTenant.'_'.$oAccount->User->TwilioNumber); if ($bUserTwilioEnable) { if ($bUserDefaultNumber) { $oCapability->allowClientIncoming(strlen($sUserPhoneNumber) > 0 ? $sUserPhoneNumber : 'default'); } else { if (strlen($sUserPhoneNumber) > 0) { $oCapability->allowClientIncoming($sUserPhoneNumber); } } } $mToken = $oCapability->generateToken(86400000); //Token lifetime set to 24hr (default 1hr) } catch (\Exception $oE) { \CApi::LogException($oE); } } else { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::VoiceNotAllowed); } return $this->DefaultResponse($oAccount, __FUNCTION__, $mToken); }
<?php $token = new Services_Twilio_Capability($accountsid, $authtoken); $token->allowClientOutgoing($APP_SID); ?> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script> <script type="text/javascript"> var conn = null; $(document).ready(function() { Twilio.Device.setup("<?php echo $token->generateToken(); ?> "); $("li > a").click(function() { name = $(this).prev().text(); monitorConference(name, $(this)); }); }); function monitorConference(name, link) { if (conn == null){ conn = Twilio.Device.connect( { 'name' : name } ); link.text('Leave'); link.click(function() { leaveConference(link); }); } } function leaveConference(link) { conn.disconnect(); conn = null;
/** * @return array */ public function AjaxGetTwilioToken() { $oAccount = $this->getAccountFromParam(); $oTenant = null; if ($this->oApiTenants) { $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->GetTenantById($oAccount->IdTenant) : $this->oApiTenants->GetDefaultGlobalTenant(); } $mToken = false; if ($oTenant && $this->oApiCapability->IsTwilioSupported($oAccount) && $oTenant->IsTwilioSupported() && file_exists(PSEVEN_APP_ROOT_PATH . 'libraries/Services/Twilio.php')) { try { include PSEVEN_APP_ROOT_PATH . 'libraries/Services/Twilio.php'; // put your Twilio API credentials here $sAccountSid = $oTenant->TwilioAccountSID; $sAuthToken = $oTenant->TwilioAuthToken; // put your Twilio Application Sid here $sAppSid = $oTenant->TwilioAppSID; /*\CApi::Log('twilio_calls_log'); $client = new \Services_Twilio($sAccountSid, $sAuthToken); foreach ($client->account->calls->getIterator(0, 50, array( //"From" => "client:7333", "StartTime>" => "2014-01-01" )) as $call ) { \CApi::Log('status-'.$call->status.' to-'.$call->to .' from-'.$call->from); } \CApi::Log('twilio_calls_log_end');*/ // $sTwilioPhoneNumber = $oTenant->TwilioPhoneNumber; $sUserPhoneNumber = $oAccount->User->TwilioNumber; $oCapability = new \Services_Twilio_Capability($sAccountSid, $sAuthToken); $oCapability->allowClientOutgoing($sAppSid); \CApi::Log('twilio_debug'); \CApi::Log('twilio_account_sid-' . $sAccountSid); \CApi::Log('twilio_auth_token-' . $sAuthToken); \CApi::Log('twilio_app_sid-' . $sAppSid); \CApi::Log('twilio_number-' . $sUserPhoneNumber); \CApi::Log('twilio_enable-' . $oAccount->User->TwilioEnable); \CApi::Log('twilio_default_number-' . ($oAccount->User->TwilioDefaultNumber ? 'true' : 'false')); \CApi::Log('twilio_debug_end'); // $oCapability->allowClientIncoming('TwilioAftId_'.$oAccount->User->TwilioNumber); $oCapability->allowClientIncoming($sUserPhoneNumber ? $sUserPhoneNumber : 'default'); // $oCapability->allowClientIncoming('TwilioAftId_'.$oAccount->IdTenant.'_'.$oAccount->User->TwilioNumber); $mToken = $oCapability->generateToken(86400000); //Token lifetime set to 24hr (default 1hr) } catch (\Exception $oE) { \CApi::LogException($oE); } } else { throw new \ProjectSeven\Exceptions\ClientException(\ProjectSeven\Notifications::VoiceNotAllowed); } return $this->DefaultResponse($oAccount, __FUNCTION__, $mToken); }
$participants = []; //@TODO: Cache lots $conferences = $client->account->conferences->getPage(0, 50, array('Status' => 'in-progress')); foreach ($conferences->getItems() as $conference) { if ($conference->friendly_name == 'mciof' . $_GET['getParticipants']) { foreach ($client->account->conferences->get($conference->sid)->participants as $participant) { $call = $client->account->calls->get($participant->call_sid); $duration = (new DateTime())->getTimestamp() - (new DateTime($call->start_time))->getTimestamp(); $participants[] = ['callSid' => $participant->call_sid, 'dateCreated' => $participant->date_created, 'dateUpdated' => $participant->date_updated, 'call' => ['from' => $call->from, 'duration' => $duration]]; } } } echo json_encode($participants, JSON_PRETTY_PRINT); exit; } $deviceToken = $token->generateToken(); ?> <!DOCTYPE HTML> <html> <head> <title> MyConferenceIsOnFire </title> <meta name="viewport" content="width=device-width; maximum-scale=1; minimum-scale=1;" /> <meta property="og:site_name" content="<?php echo $url; ?> " /> <meta property="og:type" content="website" /> <meta property="og:title" content="Conference call system" /> <meta property="og:description" content="Open source conference call system built with Twilio, PHP and Javascript, with a web based soft phone" />
function connect_mailbox() { $token = new Services_Twilio_Capability(get_option('wpbr_twilio_ac_sid'), get_option('wpbr_twilio_token')); $token->allowClientOutgoing(get_option('wpbr_twilio_ap_sid')); $output = ''; $output .= '<div align="center">'; $output .= '<input type="button" class="callbutton" id="call" value="Start Recording"/>'; $output .= '<input type="button" class="stopbutton" id="stop" value="Stop Recording" style="display:none;"/>'; $output .= '<div id="status">'; $output .= 'Offline'; $output .= '</div>'; $output .= '</div>'; $output .= '<script type="text/javascript">'; $output .= 'jQuery(document).ready(function(){'; $output .= 'Twilio.Device.setup("' . $token->generateToken() . '",{"debug":true});'; $output .= 'jQuery("#call").click(function() {'; $output .= 'Twilio.Device.connect();'; $output .= '});'; $output .= 'jQuery("#stop").click(function() {'; $output .= 'connection.sendDigits("#");'; $output .= '});'; $output .= 'jQuery("#hangup").click(function() {'; $output .= 'Twilio.Device.disconnectAll();'; $output .= '});'; $output .= 'Twilio.Device.ready(function (device) {'; $output .= 'jQuery("#status").text("Ready to start recording");'; $output .= '});'; $output .= 'Twilio.Device.offline(function (device) {'; $output .= 'jQuery("#status").text("Offline");'; $output .= '});'; $output .= 'Twilio.Device.error(function (error) {'; $output .= 'jQuery("#status").text(error);'; $output .= '});'; $output .= 'Twilio.Device.connect(function (conn) {'; $output .= 'connection=conn;'; $output .= 'jQuery("#status").text("On Air");'; $output .= 'jQuery("#status").css("color", "red");'; $output .= 'toggleCallStatus();'; $output .= '});'; $output .= 'Twilio.Device.disconnect(function (conn) {'; $output .= 'jQuery("#status").text("Recording ended");'; $output .= 'jQuery("#status").css("color", "black");'; $output .= 'toggleCallStatus();'; $output .= '});'; $output .= 'function toggleCallStatus(){'; $output .= 'jQuery("#call").toggle();'; $output .= 'jQuery("#stop").toggle();'; $output .= '};'; $output .= '})'; $output .= '</script>'; echo $output; }
//phpinfo(); @session_start(); if (!isset($_COOKIE['cookie_login']) and !isset($_SESSION['user_login'])) { //session store admin name header("Location: index.php"); //login in AdminLogin.php } require_once "includes/Services/Twilio/Capability.php"; // Twilio Call /* twilio */ $accountSid = $_SESSION['tw_account_sid']; $authToken = $_SESSION['tw_auth_token']; $capability = new Services_Twilio_Capability($accountSid, $authToken); $capability->allowClientOutgoing($_SESSION['tw_app_sid']); $_SESSION['tw_token'] = $capability->generateToken(); ?> <!DOCTYPE HTML> <html> <head> <title>Twilio Test</title> <!-- utf8 setting --> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- Bootstrap --> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ></script>
// @end snippet ?> <!DOCTYPE HTML> <html> <head> <title> Twilio Client Click to Call </title> <!-- @start snippet --> <script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ Twilio.Device.setup("<?php echo $capability->generateToken(); ?> "); $("#call").click(function() { Twilio.Device.connect(); }); $("#hangup").click(function() { Twilio.Device.disconnectAll(); }); Twilio.Device.ready(function (device) { $('#status').text('Ready to start call'); }); Twilio.Device.offline(function (device) {
/** * Show the Twilio API Settings and Calling content. * * @since 1.0.0 */ public function show_settings_and_calling_content() { include_once 'partials/wordcall-admin-header.php'; $this->check_for_and_save_form_data(); $twilio_api_settings = $this->check_for_twilio_api_settings(); if (empty($twilio_api_settings)) { $twilio_api_settings = array('appsid' => '', 'authtoken' => '', 'captoken' => '', 'phonenumber' => ''); include_once 'partials/wordcall-settings-form.php'; } else { include plugin_dir_path(dirname(__FILE__)) . 'includes/twilio-php/Services/Twilio/Capability.php'; $accountSid = $twilio_api_settings['appsid']; $authToken = $twilio_api_settings['authtoken']; $token = new Services_Twilio_Capability($accountSid, $authToken); $token->allowClientOutgoing($twilio_api_settings['captoken']); $token->allowClientIncoming('wordcall'); $translation_array = array('twiliotoken' => $token->generateToken()); wp_localize_script($this->plugin_name, 'wordcall', $translation_array); include_once 'partials/wordcall-phone-display.php'; include_once 'partials/wordcall-settings-form.php'; } include_once 'partials/wordcall-admin-footer.php'; }
//$fh = fopen($myFile, 'a') or die("can't open file"); //$stringData = 'it worked!!'; //fwrite($fh, $stringData); //$stringData = 'still worked'; //fwrite($fh, $stringData); //fclose($fh); include 'twilio-php/Services/Twilio/Capability.php'; // put your Twilio API credentials here $accountSid = 'AC2af87bd237bb23944bc873bb62c075a1'; $authToken = '1233cce6cec6474cdfc156c315980ddf'; // put your Twilio Application Sid here $appSid = 'APf087e069806204f7ee5550b532e8c7e9'; $capability = new Services_Twilio_Capability($accountSid, $authToken); $capability->allowClientOutgoing($appSid); $capability->allowClientIncoming('jenny'); $token = $capability->generateToken(); //echo 'EOF'; ?> <!DOCTYPE html> <html> <head> <title>Hello Client Monkey 4</title> <script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.2/twilio.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <link href="http://static0.twilio.com/bundles/quickstart/client.css" type="text/css" rel="stylesheet" /> <script type="text/javascript"> Twilio.Device.setup("<?php echo $token; ?>
function twilio_call() { $myoptions = get_option('twilio_settings'); // set your AccountSid and AuthToken from www.twilio-message.com/user/account // $AccountSid = "AC83cb26bcf5ba5aa750d0ffe50e299b22"; // $AuthToken = "96617fb14d4ee91f4fbef6edf8682ed6"; $AccountSid = $myoptions['twilio_account_sid']; $AuthToken = $myoptions['twilio_auth_token']; // put your Twilio Application Sid here //$appSid = 'APf8a37ec0049142b87441bd9dc56fa19f'; $appSid = $myoptions['twilio_app_sid']; // put your default Twilio Client name here $clientName = 'jenny'; // get the Twilio Client name from the page request parameters, if given if (isset($_REQUEST['client'])) { $clientName = $_REQUEST['client']; } $capability = new Services_Twilio_Capability($AccountSid, $AuthToken); $capability->allowClientOutgoing($appSid); $capability->allowClientIncoming($clientName); $token = $capability->generateToken(); wp_enqueue_script('the_twiliojs', '//static.twilio.com/libs/twiliojs/1.2/twilio.min.js'); wp_enqueue_style('stylecss', plugins_url('/assets/css/style.css', __FILE__)); wp_enqueue_script('the_calljs', plugins_url('/assets/js/call.js', __FILE__)); wp_localize_script('the_calljs', 'appSetting', array('token' => $token, 'client' => $clientName)); }