-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE) #1732
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
Reviewer's GuideEnhances ChatwootService to gracefully handle non-message events and missing key properties by adding type-based filtering, null-checks with logging, and standardizing method calls to prevent runtime errors. Sequence diagram for handling non-message events in eventWhatsappsequenceDiagram
participant Client
participant ChatwootService
participant Logger
participant waMonitor
Client->>ChatwootService: eventWhatsapp(event, instance, body)
alt body.type is not 'message' or 'conversation'
ChatwootService->>Logger: verbose("Ignoring non-message event type: ...")
ChatwootService-->>Client: return
else body.type is 'message' or 'conversation'
ChatwootService->>waMonitor: access waInstances
Note over ChatwootService,waMonitor: Continue normal processing
end
Sequence diagram for handling missing key in createConversation and messages.upsertsequenceDiagram
participant Client
participant ChatwootService
participant Logger
Client->>ChatwootService: createConversation(instance, body)
alt body.key is null or undefined
ChatwootService->>Logger: warn("body.key is null or undefined in createConversation...")
ChatwootService-->>Client: return null
else body.key exists
Note over ChatwootService: Continue normal processing
end
Client->>ChatwootService: eventWhatsapp('messages.upsert', instance, body)
alt body.key is null or undefined
ChatwootService->>Logger: warn("body.key is null or undefined...")
ChatwootService-->>Client: return
else body.key exists
Note over ChatwootService: Continue normal processing
end
Sequence diagram for handling messages.edit with missing key.id or non-message typesequenceDiagram
participant Client
participant ChatwootService
participant Logger
Client->>ChatwootService: eventWhatsapp('messages.edit', instance, body)
alt body.type is not 'message'
ChatwootService->>Logger: verbose("Ignoring non-message event type: ...")
ChatwootService-->>Client: return
else body.key.id is null or undefined
ChatwootService->>Logger: warn("body.key.id is null or undefined in messages.edit...")
ChatwootService-->>Client: return
else body.type is 'message' and body.key.id exists
Note over ChatwootService: Continue normal processing
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
||
| public async eventWhatsapp(event: string, instance: InstanceDto, body: any) { | ||
| try { | ||
| // Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE) |
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.
@DavidsonGomes Essa condição evita o recebimento de edição de mensagem.
Deve ser repensado esse tratamento.
|
@DavidsonGomes deve reverter esse PR. Esse é o corpo da msg editada de exemplo: |
In some cases the body.key.id doesn't exists. That cause an error.
Look my log for debug purposes.
Summary by Sourcery
Add guard clauses to prevent errors from non-message events and missing body.key or key.id across ChatwootService methods
Bug Fixes: