-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(whatsapp): corrigir Business (base64/filename/caption), remoteJid #2161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…pi seja enviada somente qnd a config esta ativa
… mensagens de vídeo e áudio no BusinessStartupService
Fix/business api
…atsApp para usar Uint8Array
…baileys_7 Fix/evolution baileys 7
…pp para garantir a utilização da chave alternativa quando disponível
…baileys_7 fix: ajustar a manipulação do remoteJid na mensagem
Reviewer's GuideRefines media payload logic in WhatsApp Business API and Baileys services—conditional base64 inclusion, dynamic filename/caption omission, remoteJid correction—while updating the proxy agent utility to support Undici. Sequence diagram for conditional base64 media handling in WhatsApp Business APIsequenceDiagram
participant S as Service (BusinessStartupService)
participant S3 as S3Service
participant W as Webhook
participant O as OpenAI
participant P as PrismaRepository
participant U as User
U->>S: Send media message
S->>S3: getObjectUrl(fullName)
S3-->>S: mediaUrl
S->>S: Check localWebhook.enabled and webhookBase64
alt base64 should be included
S->>S: Add base64 to messageRaw
else base64 not included
S->>S: Skip base64
end
S->>W: Send messageRaw
alt mediaType is audio and OpenAI enabled
S->>O: Send base64 for speech-to-text
O-->>S: Transcription
S->>P: Save transcription
end
Sequence diagram for remoteJid correction in WhatsApp Baileys servicesequenceDiagram
participant S as Service (BaileysStartupService)
participant M as MessageRaw
participant W as Webhook
S->>M: Receive message
S->>S: Check if key.remoteJid includes '@lid' and remoteJidAlt exists
alt Correction needed
S->>M: Set key.remoteJid = key.remoteJidAlt
end
S->>W: sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw)
Class diagram for updated BusinessStartupService media handlingclassDiagram
class BusinessStartupService {
+localWebhook_enabled: boolean
+localWebhook_webhookBase64: boolean
+configService: ConfigService
+prismaRepository: PrismaRepository
+downloadMediaMessage()
+handleMediaUpload()
+handleOpenAISpeechToText()
}
class Openai {
+ENABLED: boolean
}
class MessageRaw {
+mediaUrl
+base64
+fileName
+caption
}
BusinessStartupService --> Openai
BusinessStartupService --> MessageRaw
BusinessStartupService --> PrismaRepository
Class diagram for BaileysStartupService remoteJid logicclassDiagram
class BaileysStartupService {
+sendDataWebhook()
+logger
}
class MessageRaw {
+key_remoteJid
+key_remoteJidAlt
}
BaileysStartupService --> MessageRaw
Class diagram for makeProxyAgentUndici utility updateclassDiagram
class makeProxyAgentUndici {
+makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent
}
class Proxy {
+host: string
+port: number
+protocol: string
+username: string
+password: string
}
class ProxyAgent {}
makeProxyAgentUndici --> ProxyAgent
makeProxyAgentUndici --> Proxy
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Extract the repeated base64 assignment logic in BusinessStartupService into a helper method to eliminate duplication and improve readability.
- Remove the console.log in BaileysStartupService and use the existing logger for consistent logging practices.
- Centralize the proxy protocol constants (PROXY_HTTP_PROTOCOL, PROXY_SOCKS5_PROTOCOL, etc.) in a shared module or enum to avoid scattered literals and ease future updates.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the repeated base64 assignment logic in BusinessStartupService into a helper method to eliminate duplication and improve readability.
- Remove the console.log in BaileysStartupService and use the existing logger for consistent logging practices.
- Centralize the proxy protocol constants (PROXY_HTTP_PROTOCOL, PROXY_SOCKS5_PROTOCOL, etc.) in a shared module or enum to avoid scattered literals and ease future updates.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/meta/whatsapp.business.service.ts:1620-1621` </location>
<code_context>
const messageType = msg.messageType.includes('Message') ? msg.messageType : msg.messageType + 'Message';
const mediaMessage = msg.message[messageType];
+ if (!msg.message?.base64) {
+ const buffer = await this.downloadMediaMessage({ type: messageType, ...msg.message });
+ msg.message.base64 = buffer.toString('base64');
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Possible risk of overwriting existing message properties.
Spreading msg.message may overwrite the type property if it exists. Explicitly set type to prevent this.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } else { | ||
| const { host, password, port, protocol: proto, username } = proxy | ||
| protocol = (proto || 'http').replace(':', '') | ||
| const { host, password, port, protocol: proto, username } = proxy; |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
| } else { | ||
| const { host, password, port, protocol: proto, username } = proxy | ||
| protocol = (proto || 'http').replace(':', '') | ||
| const { host, password, port, protocol: proto, username } = proxy; |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
| } else { | ||
| const { host, password, port, protocol: proto, username } = proxy | ||
| protocol = (proto || 'http').replace(':', '') | ||
| const { host, password, port, protocol: proto, username } = proxy; |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
| } else { | ||
| const { host, password, port, protocol: proto, username } = proxy | ||
| protocol = (proto || 'http').replace(':', '') | ||
| const { host, password, port, protocol: proto, username } = proxy; |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
| } else { | ||
| const { host, password, port, protocol: proto, username } = proxy | ||
| protocol = (proto || 'http').replace(':', '') | ||
| const { host, password, port, protocol: proto, username } = proxy; |
Check failure
Code scanning / CodeQL
Insecure randomness High
📋 Description
Consolida correções e melhorias nas integrações WhatsApp (Business API e Baileys) e compatibilidade com Undici no utilitário de proxy.
WhatsApp Business API:
WhatsApp Baileys:
Utilitários:
🧪 Type of Change
🧪 Testing
Cenários validados:
Passos para reproduzir:
✅ Checklist
[x] My code follows the project's style guidelines
[x] I have performed a self-review of my code
[x] I have commented my code, particularly in hard-to-understand areas
[x] I have made corresponding changes to the documentation
[x] My changes generate no new warnings
[x] I have manually tested my changes thoroughly
[x] I have verified the changes work with different scenarios
[x] Any dependent changes have been merged and published
Summary by Sourcery
Consolidate fixes and enhancements for WhatsApp Business API and Baileys integrations, improving media handling, remoteJid selection, and proxy utility compatibility with Undici
Bug Fixes:
Enhancements: