Skip to content

Conversation

@MailoncBerni
Copy link

@MailoncBerni MailoncBerni commented Aug 9, 2025

Alteração realizada para preservar todos os metadados recebidos no contextInfo (incluindo ctwa_clid, ctwaPayload, conversionData e entryPointConversion*), unificando dados vindos de:

  • message.message[contentType].contextInfo
  • message.message.contextInfo
  • message.messageContextInfo

Essa mudança evita a perda de informações enviadas pela Meta em diferentes níveis da estrutura da mensagem, garantindo que esses campos sejam repassados integralmente para o webhook, permitindo integrações completas com a API de Conversões.

Summary by Sourcery

Enhancements:

  • Merge contextInfo from content-specific, top-level, and messageContextInfo into a single field in prepareMessage to retain all metadata fields (e.g., ctwa_clid, ctwaPayload, conversionData, entryPointConversion*)

Alteração realizada para preservar todos os metadados recebidos no contextInfo (incluindo ctwa_clid, ctwaPayload, conversionData e entryPointConversion*), unificando dados vindos de:
- message.message[contentType].contextInfo
- message.message.contextInfo
- message.messageContextInfo

Essa mudança evita a perda de informações enviadas pela Meta em diferentes níveis da estrutura da mensagem, garantindo que esses campos sejam repassados integralmente para o webhook, permitindo integrações completas com a API de Conversões.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 9, 2025

Reviewer's Guide

Enhance prepareMessage to aggregate all contextInfo metadata from various message layers, ensuring no metadata is lost when forwarding messages to the webhook.

Class diagram for prepareMessage contextInfo aggregation

classDiagram
    class BaileysStartupService {
        +prepareMessage(message: proto.IWebMessageInfo): any
    }
    class proto.IWebMessageInfo {
        +key
        +pushName
        +status
        +message
        +messageContextInfo
        +messageTimestamp
        +participant
    }
    BaileysStartupService --> proto.IWebMessageInfo : uses

    class MessageRaw {
        +key
        +pushName
        +status
        +message
        +contextInfo
        +messageType
        +messageTimestamp
        +instanceId
        +source
    }
    BaileysStartupService ..> MessageRaw : returns

    class ContextInfo {
        +ctwa_clid
        +ctwaPayload
        +conversionData
        +entryPointConversion*
        +...otherMeta
    }
    MessageRaw o-- ContextInfo : contextInfo
Loading

Flow diagram for contextInfo merging in prepareMessage

flowchart TD
    A[Start prepareMessage] --> B{Extract contentType}
    B --> C[Get contentMsg]
    C --> D[Extract contentMsg.contextInfo]
    C --> E[Extract message.message.contextInfo]
    C --> F[Extract message.messageContextInfo]
    D --> G[Merge all contextInfo sources]
    E --> G
    F --> G
    G --> H{Any contextInfo present?}
    H -- Yes --> I[Set contextInfo in messageRaw]
    H -- No --> J[contextInfo undefined]
    I --> K[Return messageRaw]
    J --> K
Loading

File-Level Changes

Change Details Files
Implemented safe merging of contextInfo metadata from multiple message levels
  • Extract content-level contextInfo into a temporary variable (contentCtx)
  • Merge contentCtx, root-level message.message.contextInfo, and message.messageContextInfo into mergedContext
  • Define contextInfoFinal only if mergedContext has properties
  • Replace the original contextInfo assignment in messageRaw with contextInfoFinal
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 @MailoncBerni - I've reviewed your changes - here's some feedback:

  • The variable contentMsg is no longer used in the merging logic and can be removed to clean up the code.
  • Consider renaming the mm variable to something more descriptive (e.g. messagePayload or contentMap) to improve readability.
  • If contextInfo may contain nested objects, you might want to use a deep-merge utility instead of a shallow merge to avoid inadvertently overwriting nested fields.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The variable `contentMsg` is no longer used in the merging logic and can be removed to clean up the code.
- Consider renaming the `mm` variable to something more descriptive (e.g. `messagePayload` or `contentMap`) to improve readability.
- If `contextInfo` may contain nested objects, you might want to use a deep-merge utility instead of a shallow merge to avoid inadvertently overwriting nested fields.

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.

retirada do  const contentMsg = message?.message[contentType] as any; pois Não utiliza mais
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.

1 participant