<?php
$VERIFY_TOKEN = 'FiberX2024';

// Verificación de Meta
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (isset($_GET['hub_mode']) && $_GET['hub_mode'] === 'subscribe' &&
        isset($_GET['hub_verify_token']) && $_GET['hub_verify_token'] === $VERIFY_TOKEN) {
        echo $_GET['hub_challenge'];
        exit;
    } else {
        http_response_code(403);
        exit;
    }
}

// Recibir mensajes POST
$input = json_decode(file_get_contents('php://input'), true);

// Guardar mensajes en un log para probar
file_put_contents('webhook_log.txt', print_r($input, true)."\n", FILE_APPEND);

http_response_code(200);
echo "OK";
