RomanL il y a 7 ans
Parent
commit
200f9c1459
1 fichiers modifiés avec 10 ajouts et 2 suppressions
  1. 10 2
      inc/classes/BxDolTwilio.php

+ 10 - 2
inc/classes/BxDolTwilio.php

@@ -50,8 +50,8 @@ class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
         try{
         try{
             require_once BX_DIRECTORY_PATH_PLUGINS . 'Twilio/autoload.php'; // Loads the library
             require_once BX_DIRECTORY_PATH_PLUGINS . 'Twilio/autoload.php'; // Loads the library
             $client = new Twilio\Rest\Client($this->_sSid, $this->_sToken);
             $client = new Twilio\Rest\Client($this->_sSid, $this->_sToken);
-            $aParams = array('body' => $sMessage, 'from' => $sFrom != '' ? $sFrom : $this->_sFromNumber);
-            $client->messages->create($sTo, $aParams);
+            $aParams = array('body' => $sMessage, 'from' => $sFrom != '' ? $this->normalizePhone($sFrom) : $this->normalizePhone($this->_sFromNumber));
+            $client->messages->create($this->normalizePhone($sTo), $aParams);
             return true;
             return true;
         }
         }
         catch (Exception $oException) {
         catch (Exception $oException) {
@@ -60,6 +60,14 @@ class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
         }
         }
     }
     }
     
     
+    public function normalizePhone($sPhone){
+		$sPhone = trim($sPhone);
+		if (substr($sPhone, 0, 1) != '+'){
+			$sPhone = '+' . $sPhone;	
+		}
+		return $sPhone;
+	}
+    
     private function writeLog($sString)
     private function writeLog($sString)
 	{
 	{
 		$sFile = BX_DIRECTORY_PATH_LOGS . '/bx_twilio.log';   
 		$sFile = BX_DIRECTORY_PATH_LOGS . '/bx_twilio.log';