<?php
// test.php
// Enviar mensaje de prueba "hola" a 5493415643881 con Ultramsg

ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ . '/config.php';

// Número destino (podés usar con o sin +)
$to   = '+5493415643881';
$body = 'hola';

$params = array(
    'token' => ULTRA_TOKEN,        // desde config.php
    'to'    => $to,
    'body'  => $body,
);

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.ultramsg.com/" . ULTRA_INSTANCE_ID . "/messages/chat",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => http_build_query($params),
    CURLOPT_HTTPHEADER => array(
        "content-type: application/x-www-form-urlencoded"
    ),
));

$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);

header('Content-Type: text/plain; charset=utf-8');

echo "-- TEST ENVIAR HOLA --\n\n";
echo "Instance: " . ULTRA_INSTANCE_ID . "\n";
echo "To: {$to}\n\n";

if ($err) {
    echo "cURL Error: " . $err . "\n";
} else {
    echo "Respuesta API:\n";
    echo $response . "\n";
}
