feat(turnero): add chat plantillas API endpoints
- chat_get_plantillas.php: GET — returns enabled templates from
turnero_chat_plantillas JOIN message_templates; auto-creates table
- chat_save_plantillas.php: POST {ids:[...]} — replaces all rows in
turnero_chat_plantillas using DELETE + INSERT IGNORE in a transaction
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
548ad3140d
commit
ccdc35932d
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* GET — Plantillas habilitadas para el chat turnero.
|
||||
* Crea la tabla si no existe aún.
|
||||
*/
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
requireAuthentication();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
try {
|
||||
$pdo = Database::getInstance()->getConnection();
|
||||
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS turnero_chat_plantillas (
|
||||
template_id INT NOT NULL,
|
||||
PRIMARY KEY (template_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||
|
||||
$rows = $pdo->query(
|
||||
"SELECT t.id, t.name, t.template_name, t.language_code, t.body_text,
|
||||
t.header_text, t.header_type, t.footer_text, t.example_parameters, t.status
|
||||
FROM turnero_chat_plantillas p
|
||||
JOIN message_templates t ON t.id = p.template_id
|
||||
ORDER BY t.name ASC"
|
||||
)->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode(['ok' => true, 'data' => $rows]);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['ok' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user