Skip to content

Conversation

@DavidsonGomes
Copy link
Collaborator

@DavidsonGomes DavidsonGomes commented Sep 8, 2025

Reverts #1732

Summary by Sourcery

Revert previous changes that filtered and guarded against missing or non-message events, restoring full event handling and adjusting key.id access to use optional chaining.

Bug Fixes:

  • Restore processing of non-message events by removing filters that ignored events based on body.type
  • Remove guard clauses and logging warnings for missing body.key or key.id in createConversation, messages.upsert, and messages.edit

Enhancements:

  • Apply optional chaining when accessing body.key.id to avoid runtime errors

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 8, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts the previous addition of early-exit guards for non-message events and missing body keys in ChatwootService by deleting those conditional blocks and restoring the message edit flow to use optional chaining for key IDs.

Class diagram for reverted guards in ChatwootService methods

classDiagram
class ChatwootService {
  +createConversation(instance: InstanceDto, body: any)
  +eventWhatsapp(event: string, instance: InstanceDto, body: any)
  +getMessageByKeyId(instance, keyId)
}

ChatwootService : createConversation(instance, body)
ChatwootService : eventWhatsapp(event, instance, body)
ChatwootService : getMessageByKeyId(instance, keyId)

%% The following attributes and guards were removed:
%% - Early exit if body.key is missing in createConversation
%% - Early exit if body.type is not 'message' or 'conversation' in eventWhatsapp
%% - Early exit if body.key is missing in eventWhatsapp (messages.upsert/send.message)
%% - Early exit if body.type is not 'message' and if body.key.id is missing in eventWhatsapp (messages.edit/send.message.update)
%% The method getMessageByKeyId is now called with optional chaining for key.id
Loading

File-Level Changes

Change Details Files
Removed guard clause for missing body.key in createConversation
  • Deleted the if-statement checking for body.key absence and its warning log
  • Restored flow to always proceed with createConversation logic
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Deleted non-message event filter in eventWhatsapp
  • Removed the conditional that ignored events with body.type not equal to 'message' or 'conversation'
  • Allowed eventWhatsapp to process all incoming events
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Eliminated body.key null check in messages.upsert/send.message
  • Removed warning and early return when body.key was undefined in upsert/send branch
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Restored messages.edit flow by removing type and id guards
  • Deleted filter ignoring non-message types in edit branch
  • Removed check for missing body.key.id and its warning log
  • Changed getMessageByKeyId call to use optional chaining on body.key.id
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Possibly linked issues

  • #0: PR reverts event filtering, enabling ChatwootService to process messages, fixing the issue of messages not being received.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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 and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@DavidsonGomes DavidsonGomes merged commit 9cb703a into develop Sep 8, 2025
1 check failed
@DavidsonGomes DavidsonGomes deleted the revert-1732-testmsg branch September 9, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants