<<<<<<< HEAD
<?php
// require 'vendor/autoload.php'; // Autoload Twilio SDK
use Twilio\Rest\Client;

if (!function_exists('send_whatsapp_message')) {
    /**
     * Send WhatsApp message using Twilio
     *
     * @param string $to Customer's WhatsApp number in the format whatsapp:+1234567890
     * @param string $body The message to be sent
     * @return string|bool The SID of the message or false if sending failed
     */
    function send_whatsapp_message($to, $body, $urls) {
        $sid    = "ACaef14334b8e798b4d3c43a89386c9839";
        $token  = "e1b4ff360aeced2761b7e902597e77aa";
        $from   = "whatsapp:+17075059835"; // Twilio WhatsApp numberc
        
        $media_urls = array_map(function($url) {
            return $url; // Here, ensure these are valid URLs for the media
        }, $urls);
        
        try {
            $twilio = new Client($sid, $token);
                foreach($urls as $url) :
                    if($_SERVER['REMOTE_ADDR'] === "154.192. 75.99"):
                            print_r($url);
                        endif;
                    $message = $twilio->messages
                        ->create("whatsapp:" . $to, // to
                            array(
                                "from" => "whatsapp:+14155238886",
                                "body" => $url['body'],
                                "mediaUrl" => $url['url'],
                            )
                    );
                    sleep(5);
                endforeach;
                
                
                if($_SERVER['REMOTE_ADDR'] === "154.192.7 5.99")
                            exit (FCPATH . "assets/images/invitation.png");
                
        } catch (Exception $e) {
            log_message('error', 'WhatsApp sending failed: ' . $e->getMessage());
            // echo 'Twilio WhatsApp Error: ' . $e->getMessage();  
            return false;
        }
        
        
    }
}
=======
<?php
// require 'vendor/autoload.php'; // Autoload Twilio SDK
use Twilio\Rest\Client;

if (!function_exists('send_whatsapp_message')) {
    /**
     * Send WhatsApp message using Twilio
     *
     * @param string $to Customer's WhatsApp number in the format whatsapp:+1234567890
     * @param string $body The message to be sent
     * @return string|bool The SID of the message or false if sending failed
     */
    function send_whatsapp_message($to, $body, $url) {
        $sid    = "ACaef14334b8e798b4d3c43a89386c9839";
        $token  = "e1b4ff360aeced2761b7e902597e77aa";
        $from   = "whatsapp:+17075059835"; // Twilio WhatsApp numberc

        try {
            $twilio = new Client($sid, $token);

            $message = $twilio->messages
    ->create("whatsapp:+923365360278", // to
        array(
            "from" => "whatsapp:+14155238886",
            // "contentSid" => "HXb5b62575e6e4ff6129ad7c8efe1f983e",
            // "contentVariables" => json_encode(array("1" => "12/1", "2" => "3pm")),
            "body" => $body,
            "mediaUrl" => $url,
        )
    );


            echo "<pre>"; print_r($message); echo "</pre>";
        } catch (Exception $e) {
            log_message('error', 'WhatsApp sending failed: ' . $e->getMessage());
            echo 'Twilio WhatsApp Error: ' . $e->getMessage();  
            return false;
        }
    }
}
>>>>>>> 87d1ac8f7909fc4a385638bd3d39089db3c456af
