up
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once '../config/config.php';
|
||||
requireAuthentication();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 20;
|
||||
|
||||
$rows = $db->fetchAll(
|
||||
"SELECT id, user_id, type, message, data, is_read, created_at FROM notifications WHERE is_read = 0 ORDER BY created_at DESC LIMIT ?",
|
||||
[$limit]
|
||||
);
|
||||
|
||||
echo json_encode(['success' => true, 'data' => $rows]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once '../config/config.php';
|
||||
requireAuthentication();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$id = isset($input['id']) ? intval($input['id']) : 0;
|
||||
if (!$id) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'id required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->update('notifications', ['is_read' => 1], 'id = :id', ['id' => $id]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
@@ -184,6 +184,20 @@ class WhatsAppWebhook {
|
||||
}
|
||||
|
||||
$this->saveMessage($saveData);
|
||||
|
||||
// Crear notificación para UI (nuevo mensaje entrante)
|
||||
try {
|
||||
$this->db->insert('notifications', [
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'incoming_message',
|
||||
'message' => substr($messageText, 0, 250),
|
||||
'data' => json_encode(['message_id' => $messageId]),
|
||||
'is_read' => 0,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log('Failed to create notification: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Procesar con bot (protección contra excepciones externas)
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user