public function voice($number = '', $initial_text = '') { $this->set_output_mode(MY_Controller::OUTPUT_NORMAL); $session = new Session(); $phone_number = $session->getParameters('phone_number'); $message = $session->getParameters('message'); $tropo = new Tropo(); $tropo->call("sip:{$phone_number}@shims.starhub.net.sg"); $tropo->wait(1000); $tropo->say($message); $caller = $session->getFrom(); $called = $session->getTo(); $tropo->say('Your number is ' . $caller['id']); //$tropo->say('This is via '.$called['channel']); $tropo->ask('Press 1 to hangup or 2 to continue', array('choices' => "1,2", 'name' => 'digit', 'timeout' => 60)); $tropo->on(array('event' => 'continue', 'next' => 'voice_continue')); $tropo->RenderJson(); }
protected function _load_session($initial_text) { $tropo_session = new Session(); $this->_session->from_phone_number = ''; $this->_session->initial_text = ''; $this->_session->command = ''; $this->_session->parameters = FALSE; $this->_session->staff_id = 0; if ($tropo_session) { $this->_session->command = $tropo_session->getParameters('command'); $this->_session->message = $tropo_session->getParameters('message'); if ($this->_session->command == 'send-sms') { $this->_session->from_phone_number = $tropo_session->getParameters('phone_number'); return; } $this->_session->staff_id = $tropo_session->getParameters('staff_id'); $this->_session->initial_text = $tropo_session->getInitialText(); $this->_session->from = $tropo_session->getFrom(); if (isset($this->_session->from['id'])) { $this->_session->from_phone_number = preg_replace('/^' . $this->_config['country_code'] . '/', '', $this->_session->from['id']); } if ($this->_session->from_phone_number) { $row = reset($this->CI->phone_session_model->get_rows(array('phone_number' => $this->_session->from_phone_number))); if ($row) { $this->_session->staff_id = $row->staff_id; $user_data = unserialize($row->user_data); if (is_object($user_data)) { $this->_session->command = $user_data->command; $this->_session->parameters = $user_data->parameters; } } else { $row = reset($this->CI->staff_model->get_rows(array('phone_number' => $this->_session->from_phone_number))); if ($row) { $this->_session->staff_id = $row->id; } else { echo "Cannot find phone number in list: " . $this->_session->from_phone_number; } } } } if ($this->_session->staff_id) { $this->CI->staff_model->load_by_id($this->_session->staff_id); $this->_session->from_phone_number = $this->CI->staff_model->phone_number; } }
$number = 'the number you would like to dial'; // Include the Tropo library and create a Tropo object include_once 'tropo.class.php'; $tropo = new Tropo(); // When the the session object is created, it tries // to load the json that Tropo posts when reciving or // making a call. If the json doesn't exist, the // Session object throws a TropoException. // This try/catch block checks to see if this code is // being run as part of a session or being run directly. try { // this next line throws an exception if the code isn't // being run by Tropo. If that happens, the catch block // below will run. $session = new Session(); if ($session->getParameters("action") == "create") { // A token-launched session (an outgoing call) will // have a parameter called "action" that is set to // "create". If this is true, we're trying to make an // outgoing call. The next two lines make that call // and say something. $tropo->call($session->getParameters("dial")); $tropo->say('This is an outbound call.'); } else { // The session JSON exists, but there's no action // parameter or it wasn't set to "create" so this must // be an incoming call. $tropo->say('Thank you for calling us.'); } $tropo->renderJSON(); } catch (TropoException $e) {
<?php //this example accepts parameters passed to it from an outside REST request (such as a curl app) - //it extracts the values of the passed parameters and uses it to send, in this case, an outbound text require 'tropo.class.php'; //brings in the Tropo library $session = new Session(); $to = "+" . $session->getParameters("numbertodial"); $name = $session->getParameters("customername"); $msg = $session->getParameters("msg"); //extracts the contents of the passed parameters and assigns them as variables for later use $tropo = new Tropo(); $tropo->call($to, array('network' => 'SMS')); $tropo->say("OMG " . $name . ", " . $msg . "!"); //actually creates the call, passed the "to" value and then adds in the other variables for the message return $tropo->RenderJson(); //defines the response to Tropo in JSON ?>