Skip to content

Update whatsapp.business.service.ts #1403

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jeffryjdelarosa
Copy link

@jeffryjdelarosa jeffryjdelarosa commented Apr 27, 2025

Sticker and Location to Catch it is not available.

Summary by Sourcery

Add support for sticker and location messages and enhance message processing.

New Features:

  • Handle incoming WhatsApp sticker messages.
  • Handle incoming WhatsApp location messages.

Bug Fixes:

  • Add checks for potentially missing fields in incoming message payloads.
  • Ensure correct handling of audio data provided as buffers or URLs.

Enhancements:

  • Refactor message processing to handle various types, including those without text content.
  • Improve error handling and add logging for message processing.
  • Refine media and audio file handling logic.

Sticker and Location to Catch it is not available.
Copy link

sourcery-ai bot commented Apr 27, 2025

Reviewer's Guide by Sourcery

The pull request updates the WhatsApp business service to correctly handle incoming sticker and location messages, which were previously not processed. It refactors message parsing logic to accommodate various message types, adds specific handling for stickers, and enhances error handling and logging in the event processing flow.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Refactor message parsing to handle multiple message types (text, sticker, location).
  • Modify messageTextJson to check for message type and create appropriate content objects for text, sticker, and location messages.
  • Add null/empty checks for received and messages in messageTextJson.
  • Add logging for messages without text and unknown types in messageTextJson.
  • Remove the dedicated messageLocationJson function.
src/api/integrations/channel/meta/whatsapp.business.service.ts
Add specific handling for sticker messages in the main message processing flow.
  • Add a case for 'sticker' in the renderMessageType function.
  • Add an if block in messageHandle to create a messageRaw object specifically for sticker messages.
  • Update the condition before database creation in messageHandle to exclude sticker messages.
src/api/integrations/channel/meta/whatsapp.business.service.ts
Enhance event handling with improved logging and type checking.
  • Wrap eventHandler logic in a try...catch block.
  • Add extensive logging for received content and message types in eventHandler.
  • Add checks in eventHandler to process only recognized message types.
  • Add handling for status updates in eventHandler.
  • Add error logging in eventHandler.
src/api/integrations/channel/meta/whatsapp.business.service.ts
Adjust media handling functions for compatibility and robustness.
  • Remove the !isVideo check in sendMessageWithTyping when including filename for media.
  • Simplify media source selection in getIdMedia to directly use mediaMessage.media.
  • Change property name from audio to media in the prepareMedia object within prepareAudio.
  • Improve file handling logic in audioWhatsapp to explicitly check for buffer and handle URL inputs, adding error handling for invalid inputs.
src/api/integrations/channel/meta/whatsapp.business.service.ts

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

@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 @jeffryjdelarosa - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider refactoring messageTextJson to handle different message types (text, sticker, location, etc.) in separate helper functions for improved clarity.
  • The logic for identifying and handling different message types appears distributed across messageTextJson, messageHandle, and eventHandler; consider streamlining this.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

Comment on lines +786 to +787
this.logger.log('Contenido recibido en eventHandler:');
this.logger.log(JSON.stringify(content, null, 2));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 question (security): Beware of verbose logging.

Logging the entire content in JSON might expose sensitive information. Ensure such detailed logging is controlled by environment or a log level setting when in production.

neocol83 added a commit to neocol83/evolution-api that referenced this pull request Apr 29, 2025
@nestordavalos
Copy link
Contributor

buen trabajo podrias correr npm run lint porfavor

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