From 7c54309aa8ec8159e2d87665a06e77124d9cdc8d Mon Sep 17 00:00:00 2001 From: VPS 4 Deploy Agent Date: Sun, 28 Jun 2026 17:03:49 +0200 Subject: [PATCH] feat(whatsapp): detecta conta Business no connect e persiste isBusiness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No evento 'open', chama getBusinessProfile(selfJid) (fire-and-forget) — só contas Business retornam perfil (descrição/categoria/horário/etc.). Persiste Instance.isBusiness e emite 'instance:business' para o tenant. O SettingsPanel já exibe isBusiness lido de /api/instances. Co-Authored-By: Claude Opus 4.8 --- .../connection/WhatsAppConnectionManager.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/newwhats.clube67.com/newwhats.local/backend/src/modules/whatsapp/connection/WhatsAppConnectionManager.ts b/newwhats.clube67.com/newwhats.local/backend/src/modules/whatsapp/connection/WhatsAppConnectionManager.ts index fab4446..9ee909f 100644 --- a/newwhats.clube67.com/newwhats.local/backend/src/modules/whatsapp/connection/WhatsAppConnectionManager.ts +++ b/newwhats.clube67.com/newwhats.local/backend/src/modules/whatsapp/connection/WhatsAppConnectionManager.ts @@ -608,6 +608,27 @@ export class WhatsAppConnectionManager { .catch(() => {}) } + // Detecta se é conta WhatsApp Business — getBusinessProfile só retorna um + // perfil (com descrição/categoria/etc.) para contas Business. Fire-and-forget: + // não bloqueia o sync de conexão. Persiste Instance.isBusiness e avisa o front. + ;(async () => { + try { + if (!phoneJid) return + const selfJid = phoneJid.split(':')[0].split('@')[0] + '@s.whatsapp.net' + const profile = await (sock as any).getBusinessProfile?.(selfJid) + const isBusiness = !!(profile && ( + profile.description || profile.category || profile.email || + profile.address || (profile.website && profile.website.length) || + profile.business_hours + )) + await prisma.instance.update({ where: { id: instanceId }, data: { isBusiness } }).catch(() => {}) + this.io.to(`tenant:${tenantId}`).emit('instance:business', { instanceId, isBusiness }) + logger.info({ instanceId, isBusiness }, '[Business] detecção concluída') + } catch { + /* engine sem suporte ou conta pessoal — mantém isBusiness atual */ + } + })() + // Pós-conexão: sincroniza avatar da instância e busca avatares ausentes const handler = this.contactHandlers.get(instanceId) if (handler) {