|  |  |  | @ -79,18 +79,7 @@ export class ContactsService { | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   private static async maybeFetchFromApi(digitsId: string): Promise<string | null> { | 
		
	
		
			
				|  |  |  |  |     const baseUrl = process.env.EVOLUTION_API_URL; | 
		
	
		
			
				|  |  |  |  |     const instance = process.env.EVOLUTION_API_INSTANCE; | 
		
	
		
			
				|  |  |  |  |     const apikey = process.env.EVOLUTION_API_KEY; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (!baseUrl || !instance || !apikey) return null; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     const url = `${baseUrl}/chat/findContacts/${instance}`; | 
		
	
		
			
				|  |  |  |  |     const body = { | 
		
	
		
			
				|  |  |  |  |       where: { id: `${digitsId}@s.whatsapp.net` } | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   private static async fetchNameFrom(url: string, body: any, digitsId: string): Promise<string | null> { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       const res = await fetch(url, { | 
		
	
		
			
				|  |  |  |  |         method: 'POST', | 
		
	
	
		
			
				
					|  |  |  | @ -99,10 +88,6 @@ export class ContactsService { | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (!res.ok) { | 
		
	
		
			
				|  |  |  |  |         if (process.env.NODE_ENV !== 'test') { | 
		
	
		
			
				|  |  |  |  |           const txt = await res.text().catch(() => ''); | 
		
	
		
			
				|  |  |  |  |           console.warn('ContactsService.findContacts non-OK:', res.status, txt?.slice(0, 200)); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         return null; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -119,27 +104,47 @@ export class ContactsService { | 
		
	
		
			
				|  |  |  |  |                 ? [data] | 
		
	
		
			
				|  |  |  |  |                 : []; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       let name: string | null = null; | 
		
	
		
			
				|  |  |  |  |       for (const rec of arrayCandidates) { | 
		
	
		
			
				|  |  |  |  |         const recId = rec?.id ?? rec?.jid ?? rec?.user ?? rec?.remoteJid ?? rec?.wid ?? rec?.wid?._serialized; | 
		
	
		
			
				|  |  |  |  |         if (!recId) continue; | 
		
	
		
			
				|  |  |  |  |         const norm = normalizeWhatsAppId(String(recId)); | 
		
	
		
			
				|  |  |  |  |         if (!norm || norm !== digitsId) continue; | 
		
	
		
			
				|  |  |  |  |         name = this.extractName(rec); | 
		
	
		
			
				|  |  |  |  |         if (name) break; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         const name = this.extractName(rec); | 
		
	
		
			
				|  |  |  |  |         if (name) { | 
		
	
		
			
				|  |  |  |  |           this.cache.set(digitsId, { name, expiresAt: this.now() + this.TTL_MS }); | 
		
	
		
			
				|  |  |  |  |           return name; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       return null; | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       if (process.env.NODE_ENV !== 'test') { | 
		
	
		
			
				|  |  |  |  |         console.warn('ContactsService.findContacts error:', e); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       return null; | 
		
	
		
			
				|  |  |  |  |     } catch { | 
		
	
		
			
				|  |  |  |  |       return null; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   private static async maybeFetchFromApi(digitsId: string): Promise<string | null> { | 
		
	
		
			
				|  |  |  |  |     const baseUrl = process.env.EVOLUTION_API_URL; | 
		
	
		
			
				|  |  |  |  |     const instance = process.env.EVOLUTION_API_INSTANCE; | 
		
	
		
			
				|  |  |  |  |     const apikey = process.env.EVOLUTION_API_KEY; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (!baseUrl || !instance || !apikey) return null; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     const jid = `${digitsId}@s.whatsapp.net`; | 
		
	
		
			
				|  |  |  |  |     const body = { where: { id: jid } }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     // Probar múltiples rutas conocidas según versión de Evolution
 | 
		
	
		
			
				|  |  |  |  |     const candidates = [ | 
		
	
		
			
				|  |  |  |  |       `${baseUrl}/chat/findContacts/${instance}`, | 
		
	
		
			
				|  |  |  |  |       `${baseUrl}/contact/findContacts/${instance}`, | 
		
	
		
			
				|  |  |  |  |       `${baseUrl}/contact/find/${instance}`, | 
		
	
		
			
				|  |  |  |  |       `${baseUrl}/chat/find/${instance}`, | 
		
	
		
			
				|  |  |  |  |     ]; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     for (const url of candidates) { | 
		
	
		
			
				|  |  |  |  |       const name = await this.fetchNameFrom(url, body, digitsId); | 
		
	
		
			
				|  |  |  |  |       if (name) return name; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     return null; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   static async getDisplayName(idOrJid: string | null | undefined): Promise<string | null> { | 
		
	
	
		
			
				
					|  |  |  | 
 |