up
This commit is contained in:
@@ -16,6 +16,9 @@ WHATSAPP_PHONE_NUMBER_ID=938064202726485
|
||||
WHATSAPP_API_URL=https://graph.facebook.com/v22.0/
|
||||
WEBHOOK_VERIFY_TOKEN=XimenaCaicedo2025*
|
||||
|
||||
# Auto-approve templates: true|false
|
||||
AUTO_APPROVE_TEMPLATES=true
|
||||
|
||||
# Configuración general
|
||||
APP_NAME=WhatsApp Bot System
|
||||
APP_VERSION=1.0.0
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Fecha: 3 de enero de 2026
|
||||
*/
|
||||
|
||||
require_once '../config/config.php';
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
|
||||
// Suprimir errores para obtener JSON limpio
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
@@ -67,22 +67,26 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Determinar estado según configuración
|
||||
$initialStatus = defined('AUTO_APPROVE_TEMPLATES') && AUTO_APPROVE_TEMPLATES ? 'approved' : 'pending';
|
||||
|
||||
// Crear la plantilla
|
||||
$templateId = $db->insert('message_templates', [
|
||||
'name' => $name,
|
||||
'template_name' => $templateName,
|
||||
'language_code' => $languageCode,
|
||||
'category' => $category,
|
||||
'status' => 'pending', // Siempre inicia como pendiente
|
||||
'status' => $initialStatus,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
if ($templateId) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Plantilla creada correctamente. Estado: Pendiente de aprobación por WhatsApp.',
|
||||
'message' => 'Plantilla creada correctamente.',
|
||||
'id' => $templateId,
|
||||
'note' => 'La plantilla debe ser aprobada en WhatsApp Business Manager antes de poder usarse.'
|
||||
'status' => $initialStatus,
|
||||
'note' => $initialStatus === 'approved' ? 'Plantilla marcada como aprobada localmente.' : 'La plantilla debe ser aprobada en WhatsApp Business Manager antes de poder usarse.'
|
||||
]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
|
||||
@@ -934,7 +934,12 @@ class SimpleWhatsAppManager {
|
||||
});
|
||||
|
||||
if (response && response.success) {
|
||||
this.showSuccess('Plantilla guardada correctamente');
|
||||
const status = response.status || 'pending';
|
||||
if (status === 'approved') {
|
||||
this.showSuccess('Plantilla guardada y marcada como APROBADA.');
|
||||
} else {
|
||||
this.showSuccess('Plantilla guardada correctamente. Estado: PENDIENTE.');
|
||||
}
|
||||
|
||||
// Cerrar modal
|
||||
const modal = document.getElementById('createTemplateModal');
|
||||
|
||||
@@ -53,6 +53,9 @@ define('WHATSAPP_PHONE_NUMBER_ID', env('WHATSAPP_PHONE_NUMBER_ID', 'TU_PHONE_ID_
|
||||
define('WHATSAPP_API_URL', env('WHATSAPP_API_URL', 'https://graph.facebook.com/v22.0/'));
|
||||
define('WEBHOOK_VERIFY_TOKEN', env('WEBHOOK_VERIFY_TOKEN', 'mi_token_secreto_123'));
|
||||
|
||||
// Auto-approve templates: Si está activado, las plantillas creadas localmente se marcarán como 'approved' automáticamente
|
||||
define('AUTO_APPROVE_TEMPLATES', filter_var(env('AUTO_APPROVE_TEMPLATES', 'false'), FILTER_VALIDATE_BOOLEAN));
|
||||
|
||||
// Configuración general
|
||||
define('APP_NAME', env('APP_NAME', 'WhatsApp Bot System'));
|
||||
define('APP_VERSION', env('APP_VERSION', '1.0.0'));
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
[20-Jan-2026 21:21:01 America/Bogota] Query failed: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'status' at row 1 SQL: INSERT INTO conversations (user_id,message_id,direction,message_type,content,media_url,status,created_at) VALUES (:user_id, :message_id, :direction, :message_type, :content, :media_url, :status, :created_at) Params: {"user_id":26,"message_id":"ABGGFlA5Fpa","direction":"incoming","message_type":"text","content":"this is a text message","media_url":null,"status":"received","created_at":"2026-01-20 21:21:01"}
|
||||
[20-Jan-2026 21:22:55 America/Bogota] Query failed: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'status' at row 1 SQL: INSERT INTO conversations (user_id,message_id,direction,message_type,content,media_url,status,created_at) VALUES (:user_id, :message_id, :direction, :message_type, :content, :media_url, :status, :created_at) Params: {"user_id":26,"message_id":"ABGGFlA5Fpa","direction":"incoming","message_type":"text","content":"this is a text message","media_url":null,"status":"received","created_at":"2026-01-20 21:22:55"}
|
||||
[20-Jan-2026 22:31:05 America/Bogota] Query failed: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'SET' SQL: UPDATE message_templates SET status = 'approved', updated_at = NOW() WHERE id IN (5) Params: []
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Approve all pending templates (script)
|
||||
* Usage: php approve_pending_templates.php
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
echo "Connected DB\n";
|
||||
|
||||
$pending = $db->fetchAll("SELECT id, name, template_name, status, created_at FROM message_templates WHERE status = 'pending'");
|
||||
|
||||
if (empty($pending)) {
|
||||
echo "No pending templates found.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$ids = array_map(function($r){return $r['id'];}, $pending);
|
||||
|
||||
$in = implode(',', array_map('intval', $ids));
|
||||
|
||||
$updated = $db->query("UPDATE message_templates SET status = 'approved' WHERE id IN ($in)");
|
||||
|
||||
echo "Updated templates: " . count($ids) . "\n";
|
||||
echo json_encode($pending, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
echo "Connected DB\n";
|
||||
$rows = $db->fetchAll("SELECT id, name, template_name, status, created_at FROM message_templates ORDER BY created_at DESC LIMIT 10");
|
||||
echo json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
echo "Connected DB\n";
|
||||
$t = $db->fetch('SELECT id, name, template_name, status, created_at FROM message_templates WHERE template_name = ? ORDER BY created_at DESC LIMIT 1', ['auto_test_template_001']);
|
||||
if ($t) {
|
||||
echo "Found template: " . json_encode($t) . PHP_EOL;
|
||||
} else {
|
||||
echo "Not found\n";
|
||||
$rows = $db->fetchAll('SELECT id, name, template_name, status, created_at FROM message_templates ORDER BY created_at DESC LIMIT 10');
|
||||
echo "Recent: " . json_encode($rows) . PHP_EOL;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"auto_test_template","whatsapp_name":"auto_test_template_001","language":"es","category":"utility"}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"auto_test_template_2","whatsapp_name":"auto_test_template_002","language":"es","category":"utility"}
|
||||
Reference in New Issue
Block a user