This commit is contained in:
lizandrogd
2026-01-21 01:02:17 -05:00
parent 4e3e02111b
commit 87b89b52a5
14 changed files with 387 additions and 36 deletions
+8 -1
View File
@@ -31,11 +31,15 @@ try {
id,
user_id,
COALESCE(content, message_text) as content,
message_id,
c.media_url,
u.phone_number as user_phone,
direction,
message_type,
status,
created_at
FROM conversations
FROM conversations c
LEFT JOIN users u ON c.user_id = u.id
WHERE user_id = :user_id
UNION ALL
SELECT
@@ -76,6 +80,9 @@ try {
'id' => intval($msg['id']),
'user_id' => intval($msg['user_id']),
'content' => $msg['content'] ?? '',
'message_id' => $msg['message_id'] ?? null,
'media_url' => $msg['media_url'] ?? null,
'user_phone' => $msg['user_phone'] ?? null,
'direction' => $msg['direction'] ?? 'incoming',
'message_type' => $msg['message_type'] ?? 'text',
'status' => $msg['status'] ?? 'sent',
+9 -3
View File
@@ -155,10 +155,16 @@ try {
error_log("=== DEBUG WHATSAPP TEXT MESSAGE ===");
error_log("Recipient: " . $recipient);
error_log("Message: " . $input['message']);
error_log("Method: sendTextMessage()");
error_log("Method: sendTextMessage()/sendTextReply()");
error_log("====================================");
$response = $whatsappService->sendTextMessage($recipient, $input['message']);
// Si viene reply_to, usar reply con contexto
if (!empty($input['reply_to'])) {
$replyTo = $input['reply_to'];
$response = $whatsappService->sendTextReply($recipient, $replyTo, $input['message']);
} else {
$response = $whatsappService->sendTextMessage($recipient, $input['message']);
}
break;
case 'template':
+32
View File
@@ -0,0 +1,32 @@
<?php
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../config/config.php';
header('Content-Type: application/json; charset=utf-8');
// Autenticación para APIs (debug skip)
$debugMode = isset($_GET['debug']) && $_GET['debug'] === 'true';
if (!$debugMode && function_exists('requireAuthentication')) {
requireAuthentication();
}
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
$to = $input['to'] ?? null;
$message_id = $input['message_id'] ?? null;
$emoji = $input['emoji'] ?? null;
$dry = isset($input['dry_run']) ? (bool)$input['dry_run'] : false;
if (!$to || !$message_id || !$emoji) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Parámetros faltantes: to, message_id, emoji']);
exit;
}
try {
$wa = new WhatsAppService();
$result = $wa->sendReaction($to, $message_id, $emoji, $dry);
echo json_encode(['success' => true, 'dry_run' => $dry, 'result' => $result]);
} catch (Throwable $t) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $t->getMessage()]);
}
+33
View File
@@ -0,0 +1,33 @@
<?php
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../config/config.php';
header('Content-Type: application/json; charset=utf-8');
// Autenticación para APIs (debug skip)
$debugMode = isset($_GET['debug']) && $_GET['debug'] === 'true';
if (!$debugMode && function_exists('requireAuthentication')) {
requireAuthentication();
}
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
$to = $input['to'] ?? null;
$message_id = $input['message_id'] ?? null;
$text = $input['text'] ?? null;
$preview = isset($input['preview_url']) ? (bool)$input['preview_url'] : false;
$dry = isset($input['dry_run']) ? (bool)$input['dry_run'] : false;
if (!$to || !$message_id || !$text) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Parámetros faltantes: to, message_id, text']);
exit;
}
try {
$wa = new WhatsAppService();
$result = $wa->sendTextReply($to, $message_id, $text, $preview, $dry);
echo json_encode(['success' => true, 'dry_run' => $dry, 'result' => $result]);
} catch (Throwable $t) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $t->getMessage()]);
}
+7 -1
View File
@@ -128,7 +128,13 @@ class WhatsAppWebhook {
$messageType = 'text';
$mediaUrl = null;
if (isset($message['text'])) {
if (isset($message['reaction'])) {
// Reacción (emoji) a un mensaje anterior
$messageType = 'reaction';
$emoji = $message['reaction']['emoji'] ?? '';
$reactionTo = $message['reaction']['message_id'] ?? '';
$messageText = json_encode(['emoji' => $emoji, 'message_id' => $reactionTo]);
} elseif (isset($message['text'])) {
$messageText = $message['text']['body'];
$messageType = 'text';
} elseif (isset($message['image'])) {