Skip to content
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

Adicionando um timestamp ao filename para possibilitar enviar o mesmo arquivo mais de uma vez na mesma conversa. #1344

Conversation

alvestassio
Copy link

@alvestassio alvestassio commented Mar 27, 2025

Problema:
Ao enviar um arquivo pelo aplicativo WhatsApp, o primeiro envio é bem-sucedido. No entanto, tentativas subsequentes do mesmo arquivo na mesma conversa falham. Isso ocorre devido à restrição de unicidade do atributo filename no modelo Media. O código atual de geração do filename não inclui dados voláteis, resultando em nomes de arquivo idênticos para envios repetidos, impedindo o salvamento e, consequentemente, o envio do arquivo.

Solução:
Para resolver esse problema, foi implementada uma modificação que adiciona um timestamp ao filename. Essa alteração garante que cada envio do mesmo arquivo resulte em um nome de arquivo exclusivo, permitindo o salvamento e o envio bem-sucedido em múltiplas tentativas na mesma conversa.

Resumo das alterações:
Inclusão de um timestamp no nome do arquivo para garantir unicidade em envios repetidos.
Capacidade de enviar o mesmo arquivo várias vezes na mesma conversa.

Summary by Sourcery

Add a timestamp to filename to enable sending the same file multiple times in the same conversation

Bug Fixes:

  • Resolve issue with repeated file uploads in WhatsApp by generating unique filenames using a timestamp

Enhancements:

  • Modify filename generation to include a timestamp, ensuring unique file identifiers

…the same file more than once in the same conversation.
Copy link

sourcery-ai bot commented Mar 27, 2025

Reviewer's Guide by Sourcery

This pull request modifies the filename generation logic to include a timestamp, resolving an issue where the same file could not be sent multiple times in the same conversation. The timestamp ensures that each file has a unique name, allowing it to be saved and sent successfully.

Sequence diagram for uploading a media file

sequenceDiagram
    participant WhatsApp Service
    participant S3 Service

    WhatsApp Service->>WhatsApp Service: Generates filename with timestamp
    WhatsApp Service->>S3 Service: Uploads file with unique filename
    activate S3 Service
    S3 Service-->>WhatsApp Service: Returns success
    deactivate S3 Service
Loading

File-Level Changes

Change Details Files
The filename generation logic was updated to include a timestamp.
  • A timestamp is now prepended to the filename when saving media files.
  • The timestamp ensures uniqueness of filenames, allowing the same file to be sent multiple times in the same conversation.
src/api/integrations/channel/whatsapp/whatsapp.baileys.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Overall Comments:

  • Consider generating the unique filename before passing it to the s3Service, to avoid the service needing to know about the instance ID.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 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.

@DavidsonGomes
Copy link
Collaborator

Corrija o lint por favor, uso o comando npm run lint

@DavidsonGomes DavidsonGomes merged commit 9889035 into EvolutionAPI:develop Mar 30, 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