
<?php

require_once __DIR__ . '/../config/constants.php';

class WhatsApp
{

    public static function send($phone,$message)
    {

        $url = WHATSAPP_API_URL . WHATSAPP_PHONE_ID . "/messages";

        $data = [

            "messaging_product" => "whatsapp",

            "to" => $phone,

            "type" => "text",

            "text" => [
                "body" => $message
            ]

        ];

        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            "Authorization: Bearer ".WHATSAPP_TOKEN,
            "Content-Type: application/json"
        ]);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

        curl_setopt($ch, CURLOPT_POST,true);

        curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));

        $response = curl_exec($ch);

        curl_close($ch);

        return $response;

    }

}