Skip to content

fix(chatwoot): only fallback audio caption when audioMessage exists #1435

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

edisonmartinsmkt
Copy link
Contributor

@edisonmartinsmkt edisonmartinsmkt commented May 10, 2025

Context

In PR #1434 I introduced an audio-caption fallback:

audioMessage: msg.audioMessage?.caption || ''

That change unintentionally caused non-audio message types (e.g. locationMessage) to be identified as audio, resulting in empty content.

What’s Changed

  • Apply the empty-string fallback only when msg.audioMessage is defined.
  • Ensure other message types continue to render their own content.
  • Add tests to verify that location and other non-audio messages are unaffected by this fallback.

Verification

  • ✅ Audio messages without captions now correctly yield ''.
  • ✅ Location and other message types preserve their content as expected.

Summary by Sourcery

Add NATS integration for event streaming, enhance WhatsApp Business catalog/collections support, improve event and message handling, and address security and infrastructure updates.

New Features:

  • Add NATS integration for event streaming and management.
  • Introduce WhatsApp Business catalog and collections API endpoints.
  • Support for new event type SEND_MESSAGE_UPDATE across integrations.

Bug Fixes:

  • Fix fallback logic for audio message captions to avoid affecting non-audio messages.
  • Correct shell command usage to prevent shell injection vulnerabilities.

Enhancements:

  • Improve contact and message query performance and structure.
  • Enhance webhook authentication with JWT support.
  • Refactor event manager to support NATS and improve modularity.
  • Improve emoji validation for reactions.

Build:

  • Update Docker image references and labels to new repository and contact info.
  • Add jsonwebtoken and nats packages to dependencies.

CI:

  • Update CI workflows to use new Docker image repository.

Deployment:

  • Add support for skipping S3 bucket policy application via config.

Documentation:

  • Update README with new Docker image badge, contact info, and contributors.

Tests:

  • Add tests to verify correct handling of audio and non-audio messages in fallback logic.

Chores:

  • Add and update database migrations for NATS and WhatsApp VoIP token support.

Copy link
Contributor

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This pull request introduces NATS integration for event streaming, enhances WhatsApp Business API support (including catalog and collections endpoints), improves event/message handling, and addresses several security, infrastructure, and bug fixes. The changes include new features, refactors, and configuration updates across multiple modules, with a focus on extensibility, security, and correct message processing.

File-Level Changes

Change Details Files
Add NATS integration for event streaming and management.
  • Implement NATS controller and router for event handling
  • Update event manager to support NATS alongside other integrations
  • Add NATS configuration to environment and schema files
  • Add NATS database model and migrations
src/api/integrations/event/nats/nats.controller.ts
src/api/integrations/event/nats/nats.router.ts
src/api/integrations/event/event.manager.ts
src/api/integrations/event/event.router.ts
src/api/integrations/event/event.dto.ts
src/api/integrations/event/event.schema.ts
src/config/env.config.ts
src/validate/instance.schema.ts
prisma/postgresql-migrations/20250225180031_add_nats_integration/migration.sql
Enhance WhatsApp Business API support with catalog and collections endpoints.
  • Add business controller and router for catalog/collections
  • Add DTOs and validation schemas for business endpoints
  • Integrate catalog/collections logic in WhatsApp Baileys service
src/api/controllers/business.controller.ts
src/api/routes/business.router.ts
src/api/dto/business.dto.ts
src/validate/business.schema.ts
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Fix fallback for audio message captions to only apply when audioMessage exists.
  • Update Chatwoot service to only fallback caption when audioMessage is defined
  • Add/adjust tests to verify non-audio messages are unaffected
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Improve event and message handling across integrations.
  • Add SEND_MESSAGE_UPDATE event type support
  • Refactor event emission and webhook logic for new event types
  • Improve message edit and delete handling in Baileys service
  • Enhance webhook controller to support JWT authorization header
src/api/types/wa.types.ts
src/api/integrations/event/event.controller.ts
src/api/integrations/event/webhook/webhook.controller.ts
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Add ability to skip S3 bucket policy application via config.
  • Update S3 config and Minio server logic to respect SKIP_POLICY flag
src/config/env.config.ts
src/api/integrations/storage/s3/libs/minio.server.ts
Improve contact and message query logic for pagination and filtering.
  • Refactor contact and message queries for better pagination and filtering
  • Update channel service and related SQL queries
src/api/services/channel.service.ts
Fix shell injection vulnerability in file and process management.
  • Replace execSync with execFileSync for process control
src/api/services/monitor.service.ts
src/api/provider/sessions.ts
Enhance emoji validation for reactions.
  • Add stricter emoji validation in sendMessage controller
src/api/controllers/sendMessage.controller.ts
Update Docker image references and documentation links.
  • Change Docker image to evoapicloud/evolution-api
  • Update contact info and documentation links in README and Docker files
Dockerfile
README.md
docker-compose.yaml
Docker/swarm/evolution_api_v2.yaml
.github/workflows/publish_docker_image.yml
.github/workflows/publish_docker_image_homolog.yml
.github/workflows/publish_docker_image_latest.yml
Add and update database migrations for NATS and WhatsApp VoIP token support.
  • Add migration for NATS table (PostgreSQL)
  • Add/alter Setting table for wavoipToken (MySQL)
  • Add unique constraint to Chat table
prisma/postgresql-migrations/20250225180031_add_nats_integration/migration.sql
prisma/mysql-migrations/20250214181954_add_wavoip_token_column/migration.sql
prisma/mysql-migrations/20250510035200_add_wavoip_token_to_settings_table/migration.sql
prisma/mysql-migrations/1707735894523_add_wavoip_token_to_settings_table/migration.sql
General enhancements and minor fixes across the codebase.
  • Refactor event manager/controller for modularity
  • Update validation schemas and types
  • Fix minor bugs in message processing and Typebot integration
  • Update package dependencies (add jsonwebtoken, nats)
src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts
src/api/integrations/chatbot/typebot/services/typebot.service.ts
src/api/dto/sendMessage.dto.ts
src/api/routes/index.router.ts
src/api/server.module.ts
src/validate/validate.schema.ts
package.json

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

@DavidsonGomes DavidsonGomes changed the base branch from main to develop May 10, 2025 22:14
@DavidsonGomes DavidsonGomes merged commit ec9de49 into EvolutionAPI:develop May 10, 2025
1 check passed
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