diff --git a/api/send_broadcast.php b/api/send_broadcast.php index d70de50..fb38e63 100644 --- a/api/send_broadcast.php +++ b/api/send_broadcast.php @@ -90,6 +90,7 @@ try { $sentCount = 0; $errorCount = 0; $errors = []; + $debugWamids = []; foreach ($users as $user) { try { @@ -185,6 +186,19 @@ try { $processedVariables, $headerParams ); + + // Log payload para diagnóstico + $dryPayload = $whatsappService->sendTemplateMessage( + $user['phone_number'], + $template['template_name'] ?? $template['name'], + $template['language_code'] ?? 'es', + $processedVariables, + $headerParams, + null, null, true // dryRun=true + ); + error_log("=== BROADCAST TEMPLATE PAYLOAD (para " . $user['phone_number'] . ") ==="); + error_log(json_encode($dryPayload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); + error_log("=== FIN PAYLOAD ==="); // Construir contenido para BD (reemplazar variables en body_text) $messageContent = $template['body_text'] ?? $template['name']; @@ -218,6 +232,12 @@ try { if ($isSuccess) { $sentCount++; + $debugWamids[] = [ + 'phone' => $user['phone_number'], + 'wamid' => $sentMessageId, + 'wa_status' => $response['messages'][0]['message_status'] ?? 'accepted', + 'wa_contact' => $response['contacts'][0]['wa_id'] ?? null, + ]; // Guardar mensaje en BD $db->insert('conversations', [ @@ -258,7 +278,8 @@ try { 'total_users' => count($users), 'selection_type' => $selectionType, 'message_type' => $messageType, - 'errors' => $errorCount > 0 ? $errors : null + 'errors' => $errorCount > 0 ? $errors : null, + 'debug_wamids' => $debugWamids ?? [] ]); } catch (Exception $e) { diff --git a/index.php b/index.php index 935bf9d..c44f67d 100644 --- a/index.php +++ b/index.php @@ -1576,200 +1576,9 @@ try {