-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Develop #1309
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
Develop #1309
Conversation
- Update Docker image repository to evoapicloud/evolution-api - Modify contact email to contato@evolution-api.com - Update Docker Compose, Dockerfile, and workflow files - Add Docker image badge to README - Include additional content creator in README - Implement message deduplication cache in Baileys service
…leys service - Refactor edited message detection logic - Prevent duplicate message processing for edited messages - Optimize message key caching mechanism
…{baseUrl}}/chat/fetchCatalogs' and '{{baseUrl}}/chat/fetchCollections'
Refactor edit and delete message functionality in BaileyStartupService
Feat: Adicionei suporte para obter o Catálogos de Produtos e as Coleções de Produtos para a versão 2.2.3
…gos de produtos e Coleções evitando alterações desnecessárias em arquivos do repositório
Adicionado suporte para obter Catálogos e Coleções no WhatsApp Business
feat: notconvertsticket for animated stickers
Fix instance creation on v2.2.3
…-location feat: add message location support whatsapp meta
(cherry picked from commit 6b120e5)
Reviewer's Guide by SourceryThis pull request introduces several new features and improvements, including message duplication handling, message editing support, fetching product catalogs and collections from WhatsApp Business accounts, location messages, and updates to the Baileys library and Docker configurations. It also adds a new parameter to disable sticker conversion. Sequence diagram for editing a messagesequenceDiagram
participant User
participant Client
participant PrismaRepository
participant WhatsApp
User->>Client: Sends edit message request with data.key
Client->>WhatsApp: client.sendMessage(jid, options, data.key)
activate WhatsApp
WhatsApp-->>Client: Response (success or error)
deactivate WhatsApp
alt Response is successful
Client->>PrismaRepository: Find message by key.id
activate PrismaRepository
PrismaRepository-->>Client: Message
deactivate PrismaRepository
Client->>PrismaRepository: Update message with edited content and status
activate PrismaRepository
PrismaRepository-->>Client: Updated Message
deactivate PrismaRepository
Client->>PrismaRepository: Create message update
activate PrismaRepository
PrismaRepository-->>Client: Message Update
deactivate PrismaRepository
Client->>Client: Send data webhook (Events.MESSAGES_EDITED)
else Response is an error
Client-->>User: Error
end
Sequence diagram for fetching catalogsequenceDiagram
participant Client
participant WhatsApp
Client->>WhatsApp: getCatalog({ jid, limit, cursor })
activate WhatsApp
WhatsApp-->>Client: Catalog data (products, nextPageCursor)
deactivate WhatsApp
loop While fetcherHasMore and countLoops < 4
Client->>WhatsApp: getCatalog({ jid, limit, cursor: nextPageCursor })
activate WhatsApp
WhatsApp-->>Client: Catalog data (products, nextPageCursor)
deactivate WhatsApp
end
Client-->>Client: Returns catalog data
Sequence diagram for fetching collectionssequenceDiagram
participant Client
participant WhatsApp
Client->>WhatsApp: getCollections(jid, limit)
activate WhatsApp
WhatsApp-->>Client: Collections data
deactivate WhatsApp
Client-->>Client: Returns collections data
Class diagram for getCatalogDtoclassDiagram
class getCatalogDto {
+number?: string
+limit?: number
+cursor?: string
}
Class diagram for getCollectionsDtoclassDiagram
class getCollectionsDto {
+number?: string
+limit?: number
}
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 @mbap-dev - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a description to the PR to explain the changes made and the purpose of the pull request.
- It looks like you're adding a lot of new functionality - consider breaking this PR up into smaller chunks.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (!(message.key.valueOf() as any).fromMe) { | ||
| new BadRequestException('You cannot edit others messages'); | ||
| } | ||
| if ((message.key.valueOf() as any)?.deleted) { |
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.
issue (bug_risk): Exceptions for editing non-owned or deleted messages are created but not thrown.
Since these exceptions are merely instantiated without being thrown, the subsequent logic will continue executing. Ensure to throw the exceptions (e.g., using 'throw new BadRequestException(...)') to properly halt execution when needed.
|
|
||
| <div align="center"> | ||
|
|
||
| [] |
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.
issue (typo): Typo in Docker Image badge link.
The link text for the Docker Image badge contains a tab character ('\t'). It should be removed.
| [] | |
| [] |
| const editedMessage = | ||
| received?.message?.protocolMessage || received?.message?.editedMessage?.message?.protocolMessage; | ||
|
|
||
| if (received.message?.protocolMessage?.editedMessage || received.message?.editedMessage?.message) { |
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.
issue (complexity): Consider extracting common logic into helper functions to reduce code duplication and improve readability by centralizing caching and cursor decoding operations.
Consider extracting some common logic into small helper functions. For example, the duplicated caching logic for duplicate messages can be centralized. Instead of repeatedly doing:
const messageKey = `${this.instance.id}_${received.key.id}`;
const cached = await this.baileysCache.get(messageKey);
if (cached && !editedMessage) {
this.logger.info(`Message duplicated ignored: ${received.key.id}`);
continue;
}
await this.baileysCache.set(messageKey, true, 30 * 60);
You could extract it into a helper:
```ts
private async isDuplicateMessage(key: string, editedMessage?: any): Promise<boolean> {
const messageKey = `${this.instance.id}_${key}`;
const cached = await this.baileysCache.get(messageKey);
if (cached && !editedMessage) return true;
await this.baileysCache.set(messageKey, true, 30 * 60);
return false;
}And then use it as:
if (await this.isDuplicateMessage(received.key.id, editedMessage)) {
this.logger.info(`Message duplicated ignored: ${received.key.id}`);
continue;
}Similarly, for the catalog fetching while-loop where JSON parsing and Base64 decoding are intertwined, extract the cursor decoding into its own method:
private decodeCursor(cursor?: string): any {
if (!cursor) return null;
try {
const jsonCursor = JSON.parse(atob(cursor));
return jsonCursor.pagination_cursor ? JSON.parse(atob(jsonCursor.pagination_cursor)) : null;
} catch (error) {
this.logger.error("Error decoding cursor", error);
return null;
}
}Then in your loop:
let nextPageCursorJson = nextPageCursor ? JSON.parse(atob(nextPageCursor)) : null;
let pagination = this.decodeCursor(nextPageCursor);These refactorings keep the main flow clearer while preserving functionality.
No description provided.