simontelephonics / smsconnector

SMS Connector module for FreePBX 16 and 17
https://simon.tel/open-source/
GNU General Public License v3.0
41 stars 16 forks source link

Unable to store media: Unable to insert Message into DB preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated #62

Open billsimon opened 1 week ago

billsimon commented 1 week ago

I seem to be running into this issue on the iPhone app using FreePBX 17.0.19.16 and SMS Connector 16.0.17.1 with PHP 8.2.24. Using Telnyx if that makes any difference.

Full error for me is: Unable to store media: Unable to insert Message into DB preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Originally posted by @asasin114 in https://github.com/simontelephonics/smsconnector/issues/56#issuecomment-2438896720

billsimon commented 1 week ago

SMS adaptor is potentially passing null strings to the emojione library which was tolerated under PHP 7.x but not 8.x - most likely to happen when sending an MMS image only, no text.

Also seems to be specific to the mobile client (maybe desktop too), but not UCP. UCP sends an empty message string with MMS and so the bug doesn't show up when testing there.

I can add some validation to the SMS connector to prevent this.

billsimon commented 1 week ago

@asasin114 if you are able to test on UCP and confirm that it works there but not iPhone that would be helpful.

asasin114 commented 1 week ago

I can confirm that sending an image with an empty text string from UCP and the Talk desktop app does work. It just appears to be iPhone... My wireless carrier is rejecting any MMS messages but I think that's a separate issue...

billsimon commented 1 week ago

Are you able to apply this patch and let me know your results?

diff --git a/adaptor/Smsconnector.class.php b/adaptor/Smsconnector.class.php
index 2ba8688..5da4dbf 100644
--- a/adaptor/Smsconnector.class.php
+++ b/adaptor/Smsconnector.class.php
@@ -13,6 +13,8 @@ class Smsconnector extends \FreePBX\modules\Sms\AdaptorBase {

     public function sendMedia($to,$from,$cnam,$message=null,$files=array(),$time=null,$adaptor=null,$emid=null,$chatId='')
     {
+        $message ??= ''; // string is expected, so don't allow a null
+
         // Store in database
         $retval = array();
         try 
@@ -41,6 +43,8 @@ class Smsconnector extends \FreePBX\modules\Sms\AdaptorBase {

     public function sendMessage($to,$from,$cnam,$message,$time=null,$adaptor=null,$emid=null,$chatId='')
     {
+        $message ??= ''; // string is expected, so don't allow a null
+
         // Clean up 'to' number if we got one with a +. Only seems to apply to mobile app. UCP
         // and desktop apps format number before invoking this module.
         $to = ltrim($to, '+');