function form($token) { $phone = array_key_exists('phone', $_POST) ? $_POST['phone'] : ''; $form = <<<EOD <form method="post"> <p><label for="number">Your phone number:</label> +<input type="text" id="number" name="phone" value="{$phone}"/><br/>Include country code (ex: 1 415 555 1212)</p> <p><label for="submit"></label><input type="submit" id="submit" name="submit" value="Call Me"/></p> </form> EOD; if (!empty($_POST['phone'])) { include 'tropo-rest.class.php'; $from = preg_replace("/[^0-9]/", "", $_POST['phone']); $session = new SessionAPI(); try { $session->createSession($token, array('from' => $from)); print '<p>Calling you now.</p>'; } catch (Exception $e) { print $e->getMessage(); } } print $form; }
/** * Launches a new session with the Tropo Session API. * (Pass through to SessionAPI class.) * * @param string $token Your outbound session token from Tropo * @param array $params An array of key value pairs that will be added as query string parameters * @return bool True if the session was launched successfully */ public function createSession($token, array $params = NULL) { try { $session = new SessionAPI(); $result = $session->createSession($token, $params); return $result; } catch (Exception $ex) { throw new TropoException($ex->getMessage(), $ex->getCode()); } }
protected function _call_voice($phone_number, $message) { // does not work at the moment $session = new SessionAPI(); $session->setBaseURL($this->_config['tropo_url']); $parameters = array('staff_id' => $this->_session->staff_id, 'phone_number' => $phone_number, 'message' => $message); $session_id = $session->createSession($this->_config['tropo_api_voice'], $parameters); }
/** * Launches a new session with the Tropo Session API. * (Pass through to SessionAPI class.) * * @param string $token Your outbound session token from Tropo * @param array $params An array of key value pairs that will be added as query string parameters * @return bool True if the session was launched successfully */ public function createSession($token, Array $params=NULL) { try { $session = new SessionAPI(); $result = $session->createSession($token, $params); return $result; } // If an exception occurs, wrap it in a TropoException and rethrow. catch (Exception $ex) { throw new TropoException($ex->getMessage(), $ex->getCode()); } }