-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(whatsapp): enhance message fetching and processing logic #1449
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
Merged
DavidsonGomes
merged 2 commits into
EvolutionAPI:develop
from
gomessguii:feature/enhance-message-fetching
May 15, 2025
Merged
feat(whatsapp): enhance message fetching and processing logic #1449
DavidsonGomes
merged 2 commits into
EvolutionAPI:develop
from
gomessguii:feature/enhance-message-fetching
May 15, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Added a new method `fetchMessages` to retrieve messages based on various query parameters. - Improved handling of `pushName` for messages, ensuring proper assignment based on participant information. - Refactored user devices cache initialization for better readability. - Cleaned up commented-out code related to message recovery.
Reviewer's GuideThis PR enhances message retrieval and processing within BaileysStartupService by introducing a new fetchMessages method with Prisma-based filtering, pagination, and formatting, refines pushName assignment through a contacts map and fallback logic, streamlines cache initialization and ignore rules, and removes outdated recovery code. Sequence Diagram for fetchMessages MethodsequenceDiagram
participant Caller
participant BSS as BaileysStartupService
participant PR as PrismaRepository
Caller->>BSS: fetchMessages(query)
BSS->>BSS: Construct filterOptions from query
BSS->>PR: message.count(filterOptions)
PR-->>BSS: count
BSS->>PR: message.findMany(filterOptions, pagination, selectFields)
PR-->>BSS: rawMessages
BSS->>BSS: Loop: Format each message (apply pushName logic)
BSS-->>Caller: { total, pages, currentPage, records: formattedMessages }
Sequence Diagram for Enhanced pushName Assignment in Message ProcessingsequenceDiagram
participant BaileysSocket
participant BSS as BaileysStartupService
participant ContactsMap as contactsMap (internal)
BaileysSocket->>BSS: Event: 'messages.upsert' (messagesUpdate)
BSS->>BSS: Populate contactsMap from available contacts data
loop For each message 'm' in messagesUpdate.messages
alt If !m.pushName AND !m.key.fromMe
BSS->>BSS: participantJid = m.participant || m.key.participant || m.key.remoteJid
alt participantJid AND contactsMap.has(participantJid)
BSS->>ContactsMap: get(participantJid)
ContactsMap-->>BSS: contactInfo (with name)
BSS->>BSS: m.pushName = contactInfo.name
else if participantJid
BSS->>BSS: m.pushName = participantJid.split('@')[0] (fallback)
end
end
BSS->>BSS: preparedMessage = prepareMessage(m)
note right of BSS: prepareMessage itself also contains updated pushName fallback logic
BSS->>BSS: Further processing of preparedMessage (e.g., save, emit)
end
Class Diagram for BaileysStartupService and fetchMessages StructuresclassDiagram
class BaileysStartupService {
-authStateProvider: AuthStateProvider
-msgRetryCounterCache: CacheStore
-userDevicesCache: CacheStore
+fetchMessages(query: Query_Message): Promise<FetchMessagesResponse>
+prepareMessage(message: any): any
#upsertMessage(messagesUpdate: any, messageType: any): Promise<void>
}
class Query_Message {
+where: MessageWhereInput
+offset: number
+page: number
}
class MessageWhereInput {
+id: string
+source: string
+messageType: string
+messageTimestamp: TimestampFilter
+key: KeyFilter
}
class KeyFilter {
+id: string
+fromMe: boolean
+remoteJid: string
+participants: string
}
class TimestampFilter {
+gte: string
+lte: string
}
class FetchMessagesResponse {
+messages: PaginatedMessages
}
class PaginatedMessages {
+total: number
+pages: number
+currentPage: number
+records: object[]
}
BaileysStartupService ..> Query_Message : uses
BaileysStartupService ..> FetchMessagesResponse : uses
Query_Message *-- MessageWhereInput : contains
MessageWhereInput *-- KeyFilter : contains
MessageWhereInput *-- TimestampFilter : contains
FetchMessagesResponse *-- PaginatedMessages : contains
note for BaileysStartupService "New method fetchMessages added.\npushName logic enhanced in upsertMessage and prepareMessage."
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fetchMessages
to retrieve messages based on various query parameters.pushName
for messages, ensuring proper assignment based on participant information.Summary by Sourcery
Enhance WhatsApp message handling by adding a flexible fetchMessages API, improving pushName resolution, refining chat filtering rules, and tidying up related cache setup and dead code.
New Features:
Enhancements: