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); }
<?php /** * Created by IntelliJ IDEA. * User: benjamin * Date: 04.09.2015 * Time: 19:28 */ namespace net\vertexdezign\wbb; // load WBB core require_once 'global.php'; class SessionAPI { static function checkSession() { // check if user is logged in (has a valid userID != 0) if (($uId = \wcf\system\WCF::getUser()->userID) != 0) { $username = \wcf\system\WCF::getUser()->username; return array('uId' => $uId, 'username' => $username); } else { return array('uId' => -1); } } } header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); echo json_encode(SessionAPI::checkSession());
/** * 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()); } }