From e59ce7319e19029aafba33ae3fdef140bd4f3a1f Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Fri, 20 Jun 2025 16:10:14 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Muestra=20IDs=20de=20comunidades=20disp?= =?UTF-8?q?onibles=20cuando=20WHATSAPP=5FCOMMUNITY=5FID=20no=20est=C3=A1?= =?UTF-8?q?=20definido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/group-sync.ts | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index 69a8edf..670206d 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -191,6 +191,46 @@ export class GroupSyncService { return; } + const communityId = env.WHATSAPP_COMMUNITY_ID; + if (!communityId) { + console.log('ℹ️ WHATSAPP_COMMUNITY_ID no definido - mostrando comunidades disponibles'); + try { + const allGroups = await this.fetchGroupsFromAPI(); + const communities = allGroups.filter(g => g.linkedParent); + + if (communities.length === 0) { + console.log('❌ No se encontraron comunidades (grupos con linkedParent)'); + } else { + console.log('\n📋 Comunidades disponibles (copia el ID completo):'); + console.log('='.repeat(80)); + console.log('Nombre'.padEnd(30), 'ID Comunidad'); + console.log('-'.repeat(30), '-'.repeat(48)); + communities.forEach(c => { + console.log(c.subject.padEnd(30), c.id); + }); + console.log('='.repeat(80)); + console.log('⚠️ ATENCIÓN: Estos IDs son sensibles. No los compartas públicamente.'); + console.log(`\n⏳ El proceso terminará automáticamente en 120 segundos...`); + + // Cuenta regresiva de 120 segundos + await new Promise(resolve => { + setTimeout(resolve, 120000); + const interval = setInterval(() => { + const remaining = Math.ceil((120000 - (Date.now() - startTime)) / 1000); + process.stdout.write(`\r⏳ Tiempo restante: ${remaining}s `); + }, 1000); + const startTime = Date.now(); + }); + + console.log('\n\n✅ Listado completado. Por favor configura WHATSAPP_COMMUNITY_ID'); + } + process.exit(0); + } catch (error) { + console.error('❌ Error al obtener comunidades:', error instanceof Error ? error.message : error); + process.exit(1); + } + } + console.log('⚠️ No groups found in database - performing initial sync'); try { const { added } = await this.syncGroups();