feat(whatsapp): detecta conta Business no connect e persiste isBusiness
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 <noreply@anthropic.com>
This commit is contained in:
+21
@@ -608,6 +608,27 @@ export class WhatsAppConnectionManager {
|
|||||||
.catch(() => {})
|
.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
|
// Pós-conexão: sincroniza avatar da instância e busca avatares ausentes
|
||||||
const handler = this.contactHandlers.get(instanceId)
|
const handler = this.contactHandlers.get(instanceId)
|
||||||
if (handler) {
|
if (handler) {
|
||||||
|
|||||||
Reference in New Issue
Block a user