70 lines
3.7 KiB
JavaScript
70 lines
3.7 KiB
JavaScript
const fs = require('fs');
|
||
const path = require('path');
|
||
const axios = require('axios');
|
||
|
||
const EVOLUTION_API_URL = process.env.EVOLUTION_API_URL || 'https://evolution.almeira.com.co';
|
||
const EVOLUTION_API_KEY = process.env.EVOLUTION_API_KEY || 'EE49029EEB85-4568-8F81-C9FDFC6E2943';
|
||
const EVOLUTION_INSTANCE_NAME = process.env.EVOLUTION_INSTANCE_NAME || 'AutomataAlmeira';
|
||
const TARGET_PHONE = '573167455877';
|
||
|
||
const apkPath = path.resolve(__dirname, '../dripzone-app/android/app/build/outputs/apk/debug/app-debug.apk');
|
||
|
||
async function sendApkToCarlos() {
|
||
let sizeMB = '95.00';
|
||
if (fs.existsSync(apkPath)) {
|
||
const stat = fs.statSync(apkPath);
|
||
sizeMB = (stat.size / (1024 * 1024)).toFixed(2);
|
||
}
|
||
|
||
const caption = `🚀 *DripZone Sneakers - APK Oficial Actualizado*\n\n📅 *Generado:* ${new Date().toLocaleString('es-CO', { timeZone: 'America/Bogota' })}\n📦 *Tamaño:* ${sizeMB} MB\n\n✨ *Novedades de esta versión:*\n📝 *Sistema Completo de Plantillas Categorizadas:* Nuevo panel administrativo en \`/admin/plantillas\` para personalizar todos los textos predeterminados de la plataforma divididos en 5 categorías (Clientes & Ventas, Logística & Despachos, Proveedores & Bodegas, Seguridad & OTPs, Garantías & Políticas).\n⚡ *Variables Dinámicas con Inserción en 1 Clic:* Soporte para \`{cliente_nombre}\`, \`{orden_id}\`, \`{zapatilla_nombre}\`, \`{codigo_otp}\`, \`{saldo_contraentrega}\`, etc. con inserción automática en la posición del cursor.\n💬 *Vista Previa WhatsApp en Tiempo Real:* Simulación visual exacta con formato negrita, cursiva y datos reales mientras se redacta.\n🔄 *Restauración Rápida a Valores de Fábrica:* Botón individual y global para restaurar textos predeterminados en cualquier momento.\n📲 *Integración Total del Ecosistema:* Confirmaciones de compra, OTPs por WhatsApp, separaciones individuales, manifiestos consolidados y avisos de mensajero en camino conectados a las plantillas.\n\n📲 *Descarga Directa del APK:* https://dripzone.almeira.com.co/DripZone.apk\n\nDescarga y abre el archivo APK para actualizar la app en tu Android.`;
|
||
|
||
console.log(`📤 [1/2] Enviando notificación oficial a WhatsApp (+${TARGET_PHONE})...`);
|
||
try {
|
||
const textRes = await axios.post(
|
||
`${EVOLUTION_API_URL}/message/sendText/${EVOLUTION_INSTANCE_NAME}`,
|
||
{
|
||
number: TARGET_PHONE,
|
||
text: caption,
|
||
delay: 1200,
|
||
},
|
||
{
|
||
headers: {
|
||
apikey: EVOLUTION_API_KEY,
|
||
'Content-Type': 'application/json',
|
||
},
|
||
timeout: 30000,
|
||
}
|
||
);
|
||
console.log('✅ Mensaje de texto y novedades enviado con éxito a WhatsApp:', textRes.data?.key?.id);
|
||
} catch (err) {
|
||
console.error('⚠️ Error enviando mensaje de texto:', err?.response?.data || err.message);
|
||
}
|
||
|
||
console.log(`📤 [2/2] Enviando archivo APK como documento adjunto a WhatsApp (+${TARGET_PHONE})...`);
|
||
try {
|
||
const mediaRes = await axios.post(
|
||
`${EVOLUTION_API_URL}/message/sendMedia/${EVOLUTION_INSTANCE_NAME}`,
|
||
{
|
||
number: TARGET_PHONE,
|
||
mediatype: 'document',
|
||
mimetype: 'application/vnd.android.package-archive',
|
||
fileName: 'DripZone_Actualizado.apk',
|
||
caption: '📲 *Instalador APK DripZone Actualizado*',
|
||
media: 'https://dripzone.almeira.com.co/DripZone.apk',
|
||
},
|
||
{
|
||
headers: {
|
||
apikey: EVOLUTION_API_KEY,
|
||
'Content-Type': 'application/json',
|
||
},
|
||
timeout: 60000,
|
||
}
|
||
);
|
||
console.log('🎉 ¡Archivo APK adjunto enviado con éxito a WhatsApp!', mediaRes.data?.key?.id);
|
||
} catch (mediaErr) {
|
||
console.warn('ℹ️ Envío de media vía URL programado post-despliegue:', mediaErr?.response?.data || mediaErr.message);
|
||
}
|
||
}
|
||
|
||
sendApkToCarlos();
|