fix: enforce one-way order ingestion from WhatsApp to App only
This commit is contained in:
parent
277a9ca7c4
commit
aa6e6465e1
@ -5,11 +5,6 @@ import {
|
||||
updateOrderInAppwrite,
|
||||
deleteOrderInAppwrite,
|
||||
} from '@/lib/server-appwrite';
|
||||
import {
|
||||
sendWhatsAppMessage,
|
||||
buildOrderConfirmationMessage,
|
||||
notifyAdminNewOrder,
|
||||
} from '@/lib/evolution-api';
|
||||
import { dataService } from '@/lib/data-service';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
@ -54,35 +49,6 @@ export async function POST(request: Request) {
|
||||
const newOrder = await createOrderInAppwrite(body);
|
||||
dataService.addOrder(newOrder);
|
||||
|
||||
// 1. Notificación INMEDIATA y PARALELA a WhatsApp (Administrador Carlos y Cliente)
|
||||
const notifications: Promise<any>[] = [];
|
||||
|
||||
// Notificación al WhatsApp de Carlos (+57 316 745 5877)
|
||||
notifications.push(
|
||||
notifyAdminNewOrder(newOrder).catch((err) => {
|
||||
console.warn('⚠️ No se pudo enviar WhatsApp al administrador Carlos:', err.message);
|
||||
return false;
|
||||
})
|
||||
);
|
||||
|
||||
// Confirmación al WhatsApp del Cliente (+57 ...)
|
||||
if (newOrder.customerPhone) {
|
||||
const msg = buildOrderConfirmationMessage(newOrder);
|
||||
notifications.push(
|
||||
sendWhatsAppMessage(newOrder.customerPhone, msg).catch((err) => {
|
||||
console.warn('⚠️ No se pudo enviar WhatsApp automático al cliente:', err.message);
|
||||
return false;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Ejecutar ambas notificaciones en paralelo sin demorar el retorno de la respuesta
|
||||
Promise.allSettled(notifications).then((results) => {
|
||||
console.log(`📲 [Orders API] Notificaciones de WhatsApp procesadas para orden #${newOrder.id}:`,
|
||||
results.map((r) => (r.status === 'fulfilled' ? r.value : 'rejected'))
|
||||
);
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, order: newOrder });
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ success: false, error: error.message }, { status: 400 });
|
||||
|
||||
@ -74,7 +74,29 @@ def main():
|
||||
print("[3/5] Subiendo APK y código al VPS vía SFTP...", flush=True)
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(hostname=HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
|
||||
connected = False
|
||||
for attempt in range(1, 5):
|
||||
try:
|
||||
print(f" Intento de conexión SSH {attempt}/4 a {HOST}...", flush=True)
|
||||
ssh.connect(
|
||||
hostname=HOST,
|
||||
username=USER,
|
||||
password=PASSWORD,
|
||||
timeout=60,
|
||||
banner_timeout=60,
|
||||
auth_timeout=60
|
||||
)
|
||||
connected = True
|
||||
break
|
||||
except Exception as e:
|
||||
print(f" [Aviso]: Intento {attempt} falló: {e}. Reintentando en 4s...", flush=True)
|
||||
time.sleep(4)
|
||||
|
||||
if not connected:
|
||||
print("[ERROR] No se pudo conectar al VPS tras 4 intentos.")
|
||||
sys.exit(1)
|
||||
|
||||
sftp = ssh.open_sftp()
|
||||
|
||||
def ensure_remote_dir(remote_dir):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user