function sendMessage($dst, $message)
 {
     try {
         $usNumberProto = $this->phoneUtil->parse($dst, "US");
         $srcNumberProto = $this->phoneUtil->parse($this->srcPhone, "US");
         if ($this->phoneUtil->isValidNumber($usNumberProto) && $this->phoneUtil->isValidNumber($srcNumberProto)) {
             return $this->service->message()->send($this->phoneUtil->format($srcNumberProto, \libphonenumber\PhoneNumberFormat::E164), $this->phoneUtil->format($usNumberProto, \libphonenumber\PhoneNumberFormat::E164), $message);
         }
         throw new \Bickart\Plivo\Exceptions\PlivoException("Invalid Destination Phone Number");
     } catch (\libphonenumber\NumberParseException $e) {
         _ppl($e);
         throw $e;
     }
 }
 /**
  * This should be called when the bean is saved. The bean itself will be passed by reference
  * 
  * @param SugarBean bean - the bean performing the save
  * @param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
  */
 public function save($bean, $params, $field, $properties, $prefix = '')
 {
     parent::save($bean, $params, $field, $properties, $prefix);
     if (isset($params[$prefix . $field])) {
         $bean->{$field} = $params[$prefix . $field];
     }
     /*
      * Additional code for phone number format to E.164
      * add by xye@sugarcrm.com begin
      */
     $phoneNumberStr = $bean->{$field};
     /*
      * ISO 3166-1 two-letter country code
      * http://www.iso.org/iso/country_names_and_code_elements
      */
     global $sugar_config;
     $default_region = "US";
     if (isset($sugar_config['phonenumber_default_region']) && !empty($sugar_config['phonenumber_default_region'])) {
         $default_region = $sugar_config['phonenumber_default_region'];
     }
     $phoneUtil = PhoneNumberUtil::getInstance();
     //_ppl('phone number--->'.$phoneNumberStr);
     try {
         $phoneNumberProto = $phoneUtil->parseAndKeepRawInput($phoneNumberStr, $default_region);
         $isValid = $phoneUtil->isValidNumber($phoneNumberProto);
         //_ppl(array($phoneNumberStr, $isValid, $phoneNumberProto, $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164)));
         if ($isValid) {
             if ($phoneNumberProto->hasExtension()) {
                 $bean->{$field} = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164) . ' ext. ' . $phoneNumberProto->getExtension();
             } else {
                 $bean->{$field} = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164);
             }
         }
     } catch (NumberParseException $e) {
         _ppl($e->__toString());
         //                         echo $e;
     }
     /*
      * Additional code for phone number format to E.164
      * add by xye@sugarcrm.com end
      */
 }
$twilio_connector = new ext_rest_twilio();
$callerId = $twilio_connector->getProperty('twilio_phone_number');
// put your default Twilio Client name here, for when a phone number isn't given
$clients_list = array();
$clients_list_file_path = 'custom/include/Twilio/clients_list.php';
if (file_exists($clients_list_file_path)) {
    include $clients_list_file_path;
}
$number = array_keys($clients_list);
//$number = array("admin","brian");
// $number = array();
// get the phone number from the page request parameters, if given
if (isset($_REQUEST['PhoneNumber'])) {
    $number[] = htmlspecialchars($_REQUEST['PhoneNumber']);
}
_ppl($number);
$record_id = '';
$module_name = '';
if (isset($_REQUEST['record_id']) && isset($_REQUEST['module_name'])) {
    $record_id = $_REQUEST['record_id'];
    $module_name = $_REQUEST['module_name'];
}
if (!empty($record_id) && !empty($module_name)) {
    $action .= "&record_id={$record_id}&module_name={$module_name}";
}
//echo '<pre>';
//print_r($_REQUEST);
//echo '</pre>';
$numberOrClient = '';
$dial_attributes = array();
if (!empty($record)) {
function phone_number_e164($phoneNumberStr, $default_region)
{
    require_once 'custom/include/lib/phonenumbers/PhoneNumberUtil.php';
    $phoneUtil = PhoneNumberUtil::getInstance();
    try {
        $phoneNumberProto = $phoneUtil->parseAndKeepRawInput($phoneNumberStr, $default_region);
        $isValid = $phoneUtil->isValidNumber($phoneNumberProto);
        $countryCode = $phoneNumberProto->getCountryCode();
        $phoneNumberE164 = $phoneUtil->format($phoneNumberProto, PhoneNumberFormat::E164);
        if ($isValid) {
            $phoneNumberStr = $phoneNumberE164;
        }
        $region_code = $phoneUtil->getRegionCodeForCountryCode($countryCode);
        return array($phoneNumberStr, $region_code);
    } catch (NumberParseException $e) {
        _ppl($e->__toString());
        return array($phoneNumberStr, '');
    }
}
function inbound_lookup()
{
    global $timedate, $current_user;
    $current_user = new User();
    $current_user->retrieve('1');
    $phonenumber = $_REQUEST['phonenumber'];
    if (!empty($phonenumber)) {
        $inbound_obj = lookup_inbound_obj($phonenumber);
        _ppl('return obj begin');
        _ppl($inbound_obj);
        _ppl('return obj end');
        echo json_encode($inbound_obj);
    }
}