Skip to content

Conversation

@KokeroO
Copy link
Contributor

@KokeroO KokeroO commented Oct 19, 2025

Havia um problema em que não era marcado como resposta mídias (imagens, documentos, audios, etc).

  • Essa correção salva corretamente valores Uint8Array no DB.

Summary by Sourcery

Refactor buffer deserialization to correctly convert and store Uint8Array values in the database

Bug Fixes:

  • Ensure numeric-indexed objects and Node Buffers are converted to Uint8Array for proper DB storage

Enhancements:

  • Rename convertLongToNumber to deserializeMessageBuffers and extend its logic to handle indexed objects, Buffers, and recursive structures
  • Apply deserializeMessageBuffers to message and contextInfo fields for accurate media response handling

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 19, 2025

Reviewer's Guide

This PR replaces the legacy Long-to-number conversion with a comprehensive recursive deserializer that reconstructs Uint8Array from Buffer, numeric-indexed objects, arrays, and nested objects, and updates message and contextInfo handling to use the new method.

Class diagram for updated BaileysStartupService deserialization logic

classDiagram
class BaileysStartupService {
  +deserializeMessageBuffers(obj: any): any
  -convertLongToNumber(obj: any): any
  +saveMessage(message: any): void
}

note for BaileysStartupService "'convertLongToNumber' replaced by 'deserializeMessageBuffers' in message and contextInfo handling"
Loading

Flow diagram for recursive deserialization of message buffers

flowchart TD
A["Input object (message or contextInfo)"] --> B["Is null or undefined?"]
B -- Yes --> C["Return as is"]
B -- No --> D["Is Buffer?"]
D -- Yes --> E["Convert to Uint8Array"]
D -- No --> F["Is numeric-indexed object?"]
F -- Yes --> G["Convert to Uint8Array"]
F -- No --> H["Is Array?"]
H -- Yes --> I["Recursively process each item"]
H -- No --> J["Is Object?"]
J -- Yes --> K["Recursively process each property"]
J -- No --> L["Return as is"]
Loading

File-Level Changes

Change Details Files
Renamed and reimplemented the conversion utility to deserialize various buffer representations into Uint8Array
  • Rename method from convertLongToNumber to deserializeMessageBuffers
  • Detect numeric-indexed objects and convert them into Uint8Array
  • Convert Node Buffer instances to Uint8Array
  • Recursively process arrays and nested objects with the new method
  • Remove Long.isLong number conversion logic
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Updated message and contextInfo processing to use the new deserializer
  • Replace this.convertLongToNumber calls with this.deserializeMessageBuffers
  • Adjust spread and optional chaining usage for message.message and contextMsg?.contextInfo
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!

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 48bda1b into EvolutionAPI:develop Oct 19, 2025
5 checks passed
milesibastos added a commit to chatwoot-br/evolution-api that referenced this pull request Oct 20, 2025
commit 48bda1b
Merge: e83a7e2 dd21a29
Author: Davidson Gomes <davidsongviolao@gmail.com>
Date:   Sun Oct 19 17:59:26 2025 -0300

    Merge pull request EvolutionAPI#2107 from KokeroO/develop

    fix( baileys.service ): Corrige ao salvar no DB valores Uint8Array

commit dd21a29
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 18:53:16 2025 +0000

    fix(baileys): salvar corretamente buffer no db

commit e83a7e2
Merge: cd71ff5 d58d0b8
Author: Davidson Gomes <davidsongviolao@gmail.com>
Date:   Sun Oct 19 06:41:28 2025 -0300

    Merge pull request EvolutionAPI#2105 from KokeroO/develop

    fix: Simplify logging of messageSent object

commit d58d0b8
Merge: 4efc9b6 cd71ff5
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 06:34:58 2025 -0300

    Merge branch 'EvolutionAPI:develop' into develop

commit 4efc9b6
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 06:34:45 2025 -0300

    Simplify logging of messageSent object

    Evita o erro de this.isZero not is function

commit cd71ff5
Merge: cdf0666 582166e
Author: Davidson Gomes <davidsongviolao@gmail.com>
Date:   Sun Oct 19 06:23:39 2025 -0300

    Merge pull request EvolutionAPI#2103 from KokeroO/develop

    feat(baileys,chatwoot,on-whatsapp-cache): implementações e correções na baileys e chatwoot

commit 582166e
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 05:41:55 2025 +0000

    fix(lint): lint

commit e1ae03c
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 05:37:22 2025 +0000

    fix(comments): comments fix

commit 0737c45
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 02:29:04 2025 -0300

    Update src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

    Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

commit adbe107
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 02:28:45 2025 -0300

    Update src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

    Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

commit 423f629
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 02:26:52 2025 -0300

    Update src/utils/onWhatsappCache.ts

    Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

commit 946dcae
Author: Willian Coqueiro <wil_kokero@hotmail.com>
Date:   Sun Oct 19 03:05:11 2025 +0000

    feat(baileys,chatwoot,on-whatsapp-cache): implementações e correções na baileys e chatwoot

    * corrige cache de números PN, LIDs e g.us para enviar o número correto
    * atualiza para os últimos commits da baileys
    * corrige envio de áudio e documentos via chatwoot no canal baileys
    * diversas correções na integração com chatwoot
    * corrige mensagens ignoradas no recebimento de leads
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