up
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,179 +0,0 @@
|
||||
-- Base de datos para sistema de WhatsApp Bot
|
||||
-- Fecha: 13 de noviembre de 2025
|
||||
|
||||
-- Tabla de usuarios
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
phone_number VARCHAR(20) UNIQUE NOT NULL,
|
||||
name VARCHAR(100),
|
||||
email VARCHAR(100),
|
||||
status ENUM('active', 'inactive', 'blocked') DEFAULT 'active',
|
||||
current_menu_id INT NULL,
|
||||
current_step INT DEFAULT 0,
|
||||
session_data JSON,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_phone (phone_number),
|
||||
INDEX idx_status (status)
|
||||
);
|
||||
|
||||
-- Tabla de conversaciones
|
||||
CREATE TABLE conversations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
message_id VARCHAR(100),
|
||||
direction ENUM('incoming', 'outgoing') NOT NULL,
|
||||
message_type ENUM('text', 'image', 'audio', 'video', 'document', 'template') DEFAULT 'text',
|
||||
content TEXT,
|
||||
media_url VARCHAR(500),
|
||||
status ENUM('sent', 'delivered', 'read', 'failed', 'received') DEFAULT 'sent',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
INDEX idx_user (user_id),
|
||||
INDEX idx_created (created_at),
|
||||
INDEX idx_direction (direction)
|
||||
);
|
||||
|
||||
-- Tabla de menús (sistema parametrizable)
|
||||
CREATE TABLE menus (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
description TEXT,
|
||||
parent_id INT NULL,
|
||||
is_root BOOLEAN DEFAULT FALSE,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
order_position INT DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (parent_id) REFERENCES menus(id) ON DELETE CASCADE,
|
||||
INDEX idx_parent (parent_id),
|
||||
INDEX idx_active (is_active),
|
||||
INDEX idx_root (is_root)
|
||||
);
|
||||
|
||||
-- Tabla de opciones de menú
|
||||
CREATE TABLE menu_options (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
menu_id INT NOT NULL,
|
||||
option_number INT NOT NULL,
|
||||
text VARCHAR(200) NOT NULL,
|
||||
action_type ENUM('menu', 'message', 'api_call', 'end') NOT NULL,
|
||||
action_value VARCHAR(500),
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (menu_id) REFERENCES menus(id) ON DELETE CASCADE,
|
||||
INDEX idx_menu (menu_id),
|
||||
INDEX idx_option (option_number),
|
||||
UNIQUE KEY unique_menu_option (menu_id, option_number)
|
||||
);
|
||||
|
||||
-- Tabla de respuestas automáticas
|
||||
CREATE TABLE autoresponses (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
trigger_type ENUM('keyword', 'menu_selection', 'welcome') NOT NULL,
|
||||
trigger_value VARCHAR(200),
|
||||
response_text TEXT NOT NULL,
|
||||
response_type ENUM('text', 'template') DEFAULT 'text',
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_trigger (trigger_type),
|
||||
INDEX idx_active (is_active)
|
||||
);
|
||||
|
||||
-- Tabla de configuración del sistema
|
||||
CREATE TABLE system_config (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
config_key VARCHAR(100) UNIQUE NOT NULL,
|
||||
config_value TEXT,
|
||||
description TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Tabla de webhooks logs
|
||||
CREATE TABLE webhook_logs (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
request_body TEXT,
|
||||
response_body TEXT,
|
||||
status_code INT,
|
||||
ip_address VARCHAR(45),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_created (created_at)
|
||||
);
|
||||
|
||||
-- Tabla de plantillas de mensajes
|
||||
CREATE TABLE message_templates (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) UNIQUE NOT NULL,
|
||||
template_name VARCHAR(100) NOT NULL, -- Nombre en WhatsApp Business API
|
||||
language_code VARCHAR(10) DEFAULT 'es',
|
||||
category ENUM('marketing', 'utility', 'authentication') DEFAULT 'utility',
|
||||
status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_status (status)
|
||||
);
|
||||
|
||||
-- Insertar configuraciones iniciales
|
||||
INSERT INTO system_config (config_key, config_value, description) VALUES
|
||||
('whatsapp_token', 'EAAWTKu1iZAGABP46c7GZAFvHremu9uvTLOlgZCAa4eKUlaCqszzsQjjLcgnqORzo2EBhB7LZAcAqJ7clpGvNCk3oXKnqo8Fl0K2o7eHYoeaqZBesqjBPRfsd4ZBOdY4kN1YBJnmRznegTD9wtJZByVrRcMXF8YXaAJjLCuIFZCK7QFUpId7i4eVkFvbqUYnUKA91rgPvaeGRNZCLHa5ZC1ZB2Skn0gFNgPTBx7bedAMULYZD', 'Token de acceso de WhatsApp Business API'),
|
||||
('whatsapp_phone_number_id', '938177732702718', 'ID del número de teléfono de WhatsApp'),
|
||||
('webhook_verify_token', 'mi_token_secreto_123', 'Token de verificación para webhook'),
|
||||
('welcome_message', '¡Hola! 👋 Bienvenido a nuestro servicio automatizado. Escribe *menu* para ver las opciones disponibles.', 'Mensaje de bienvenida para nuevos usuarios'),
|
||||
('business_name', 'Mi Empresa', 'Nombre de la empresa');
|
||||
|
||||
-- Insertar menús de ejemplo
|
||||
INSERT INTO menus (name, title, description, is_root, order_position) VALUES
|
||||
('main_menu', '🏠 Menú Principal', 'Menú principal del sistema', TRUE, 1),
|
||||
('services_menu', '💼 Servicios', 'Menú de servicios disponibles', FALSE, 2),
|
||||
('payments_menu', '💳 Pagos', 'Opciones de pago', FALSE, 3),
|
||||
('support_menu', '🆘 Soporte', 'Menú de soporte técnico', FALSE, 4);
|
||||
|
||||
-- Obtener IDs de menús para las opciones
|
||||
SET @main_menu_id = (SELECT id FROM menus WHERE name = 'main_menu');
|
||||
SET @services_menu_id = (SELECT id FROM menus WHERE name = 'services_menu');
|
||||
SET @payments_menu_id = (SELECT id FROM menus WHERE name = 'payments_menu');
|
||||
SET @support_menu_id = (SELECT id FROM menus WHERE name = 'support_menu');
|
||||
|
||||
-- Actualizar parent_id para menús secundarios
|
||||
UPDATE menus SET parent_id = @main_menu_id WHERE name IN ('services_menu', 'payments_menu', 'support_menu');
|
||||
|
||||
-- Insertar opciones del menú principal
|
||||
INSERT INTO menu_options (menu_id, option_number, text, action_type, action_value) VALUES
|
||||
(@main_menu_id, 1, '💼 Ver servicios disponibles', 'menu', 'services_menu'),
|
||||
(@main_menu_id, 2, '💳 Realizar pago', 'menu', 'payments_menu'),
|
||||
(@main_menu_id, 3, '🆘 Contactar soporte', 'menu', 'support_menu'),
|
||||
(@main_menu_id, 0, '❌ Salir', 'end', 'Gracias por usar nuestro servicio. ¡Hasta pronto!');
|
||||
|
||||
-- Insertar opciones del menú de servicios
|
||||
INSERT INTO menu_options (menu_id, option_number, text, action_type, action_value) VALUES
|
||||
(@services_menu_id, 1, '📋 Consulta de información', 'message', 'Un representante se contactará contigo para brindarte información detallada. Por favor, indica qué información necesitas.'),
|
||||
(@services_menu_id, 2, '📞 Agendar cita', 'message', 'Para agendar una cita, por favor proporciona tu nombre completo y tu disponibilidad horaria.'),
|
||||
(@services_menu_id, 3, '💰 Cotizar servicio', 'message', 'Para realizar una cotización, describe detalladamente el servicio que necesitas.'),
|
||||
(@services_menu_id, 0, '🔙 Volver al menú principal', 'menu', 'main_menu');
|
||||
|
||||
-- Insertar opciones del menú de pagos
|
||||
INSERT INTO menu_options (menu_id, option_number, text, action_type, action_value) VALUES
|
||||
(@payments_menu_id, 1, '🧾 Consultar factura', 'message', 'Por favor, proporciona tu número de factura o documento de identidad para consultar tu factura pendiente.'),
|
||||
(@payments_menu_id, 2, '💸 Pagar factura', 'message', 'Para procesar tu pago, necesitamos el número de factura y el método de pago preferido (transferencia, tarjeta, etc).'),
|
||||
(@payments_menu_id, 3, '📄 Solicitar factura', 'message', 'Indica el período o servicio para el cual necesitas la factura.'),
|
||||
(@payments_menu_id, 0, '🔙 Volver al menú principal', 'menu', 'main_menu');
|
||||
|
||||
-- Insertar opciones del menú de soporte
|
||||
INSERT INTO menu_options (menu_id, option_number, text, action_type, action_value) VALUES
|
||||
(@support_menu_id, 1, '🔧 Reporte técnico', 'message', 'Describe detalladamente el problema técnico que estás experimentando. Un técnico se contactará contigo pronto.'),
|
||||
(@support_menu_id, 2, '❓ Preguntas frecuentes', 'message', 'Puedes consultar nuestras preguntas frecuentes en: www.miempresa.com/faq o describe tu pregunta específica.'),
|
||||
(@support_menu_id, 3, '👤 Hablar con agente', 'message', 'Te estamos conectando con un agente humano. Por favor, espera un momento...'),
|
||||
(@support_menu_id, 0, '🔙 Volver al menú principal', 'menu', 'main_menu');
|
||||
|
||||
-- Insertar respuestas automáticas
|
||||
INSERT INTO autoresponses (trigger_type, trigger_value, response_text) VALUES
|
||||
('keyword', 'menu', 'Aquí tienes nuestro menú principal:'),
|
||||
('keyword', 'hola', '¡Hola! 👋 Escribe *menu* para ver nuestras opciones.'),
|
||||
('keyword', 'ayuda', 'Estoy aquí para ayudarte. Escribe *menu* para ver las opciones disponibles.'),
|
||||
('welcome', '', '¡Bienvenido! 👋 Soy tu asistente virtual. Escribe *menu* para comenzar.');
|
||||
|
||||
-- Insertar plantillas de mensaje
|
||||
INSERT INTO message_templates (name, template_name, language_code, category, status) VALUES
|
||||
('saludo_inicial', 'hello_world', 'es', 'utility', 'approved'),
|
||||
('confirmacion_pago', 'payment_confirmation', 'es', 'utility', 'pending');
|
||||
+37
-7
@@ -2,6 +2,30 @@
|
||||
# Uso: docker-compose -f docker-compose.prod.yml up -d
|
||||
|
||||
services:
|
||||
# MariaDB Database
|
||||
mysql:
|
||||
image: mariadb:10.11
|
||||
container_name: whatsapp-mysql
|
||||
restart: always
|
||||
environment:
|
||||
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-root_password_2026}
|
||||
MARIADB_DATABASE: ${DB_NAME:-usite_whatsapp_bot}
|
||||
MARIADB_USER: ${DB_USER:-usite_whatsapp_user}
|
||||
MARIADB_PASSWORD: ${DB_PASS:-6q!Vio0fn@PFmsLyHjH5}
|
||||
TZ: America/Bogota
|
||||
volumes:
|
||||
- mysql-data:/var/lib/mysql
|
||||
- ./database:/docker-entrypoint-initdb.d:ro
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-time-zone=America/Bogota
|
||||
networks:
|
||||
- whatsapp-network
|
||||
healthcheck:
|
||||
test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "-u", "root", "-p${DB_ROOT_PASSWORD:-root_password_2026}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
|
||||
# Aplicación PHP con Nginx - MODO PRODUCCIÓN
|
||||
app:
|
||||
build:
|
||||
@@ -28,12 +52,12 @@ services:
|
||||
- APP_ENV=production
|
||||
- APP_DEBUG=false
|
||||
|
||||
# Base de datos - usar base de datos externa (producción actual)
|
||||
- DB_HOST=${DB_HOST:-77.37.126.126}
|
||||
- DB_PORT=${DB_PORT:-3306}
|
||||
# Base de datos - MariaDB local en Docker
|
||||
- DB_HOST=mysql
|
||||
- DB_PORT=3306
|
||||
- DB_NAME=${DB_NAME:-usite_whatsapp_bot}
|
||||
- DB_USER=${DB_USER:-usite_whatsapp_user}
|
||||
- DB_PASS=${DB_PASS}
|
||||
- DB_PASS=${DB_PASS:-6q!Vio0fn@PFmsLyHjH5}
|
||||
|
||||
# Redis
|
||||
- REDIS_HOST=redis
|
||||
@@ -57,6 +81,8 @@ services:
|
||||
- PHP_OPCACHE_ENABLE=1
|
||||
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
@@ -101,16 +127,18 @@ services:
|
||||
- TZ=America/Bogota
|
||||
- APP_ENV=production
|
||||
- APP_DEBUG=false
|
||||
- DB_HOST=${DB_HOST:-77.37.126.126}
|
||||
- DB_PORT=${DB_PORT:-3306}
|
||||
- DB_HOST=mysql
|
||||
- DB_PORT=3306
|
||||
- DB_NAME=${DB_NAME:-usite_whatsapp_bot}
|
||||
- DB_USER=${DB_USER:-usite_whatsapp_user}
|
||||
- DB_PASS=${DB_PASS}
|
||||
- DB_PASS=${DB_PASS:-6q!Vio0fn@PFmsLyHjH5}
|
||||
- REDIS_HOST=redis
|
||||
- REDIS_PORT=6379
|
||||
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
||||
- LOG_LEVEL=WARNING
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
@@ -118,6 +146,8 @@ services:
|
||||
command: php worker.php --daemon
|
||||
|
||||
volumes:
|
||||
mysql-data:
|
||||
driver: local
|
||||
redis-data:
|
||||
driver: local
|
||||
ssl-certs:
|
||||
|
||||
Reference in New Issue
Block a user