Skip to content

Fix lid migration#128

Merged
9cb14c1ec0 merged 6 commits intomasterfrom
fix-lid-migration
Dec 24, 2025
Merged

Fix lid migration#128
9cb14c1ec0 merged 6 commits intomasterfrom
fix-lid-migration

Conversation

@9cb14c1ec0
Copy link
Copy Markdown
Collaborator

@9cb14c1ec0 9cb14c1ec0 commented Dec 22, 2025

Fixes # .

Changes proposed in this pull request

To test (it takes a while): npm install github:<username>/venom#<branch>

Summary by CodeRabbit

  • New Features

    • Added a recipient normalization utility to better resolve legacy/variant IDs.
  • Bug Fixes

    • Applied identifier normalization across message sending, typing simulation, media and button flows to improve delivery, typing accuracy, and media/button reliability.
    • Added diagnostics to surface migration-related resolution steps.
  • Breaking Changes

    • Removed an older convenience send method from the public API — use the primary send interfaces.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 22, 2025

📝 Walkthrough

Walkthrough

Adds a migration-aware helper createWidWrapper(chatId), re-exports it, replaces direct Wid creation with the wrapper across messaging/typing/image/button/get-chat flows, adds two store entries, and removes sendMessage2 from the public API.

Changes

Cohort / File(s) Summary
New helper & re-export
src/lib/wapi/helper/fix-lid-migration.js, src/lib/wapi/helper/index.js
Add export async function createWidWrapper(chatId) that creates/normalizes a Wid, applies migration gating (newsletter/channel or findOrCreateLatestChat), and falls back to a contact-add sync delta; re-export from helper index.
Messaging / typing / image / buttons / get-chat callers
src/lib/wapi/functions/send-message.js, src/lib/wapi/functions/simulate-typing.js, src/lib/wapi/functions/send-image-with-product.js, src/lib/wapi/business/send-message-with-buttons.js, src/lib/wapi/functions/get-chat.js
Replace direct Store.WidFactory.createWid(...) or direct chat lookup with await createWidWrapper(...); simulate-typing logs chatId, awaits sendChatStateComposing and returns { status: 200 }; get-chat gains migration-aware path and chat construction when missing.
Removed API surface & file exports
src/lib/wapi/functions/send-message2.js, src/lib/wapi/functions/index.js, src/lib/wapi/wapi.js
Remove sendMessage2 implementation and its re-export/assignment to window.WAPI.
Store object extensions
src/lib/wapi/store/store-objects.js
Add ChannelUtils and FindOrCreateChat entries, conditional exports when loadNewsletterPreviewChat and findOrCreateLatestChat exist respectively.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Messaging/Typing Flow
  participant Wrapper as createWidWrapper
  participant Store as Store / WidFactory / Chat
  participant Channel as ChannelUtils / NewsletterCollection
  participant Sync as WAWebContactSyncUtils

  Caller->>Wrapper: createWidWrapper(chatId)
  Wrapper->>Store: create Wid(chatId)
  alt Migration gate enabled
    Wrapper->>Channel: try loadNewsletterPreviewChat / channel lookup
    alt Newsletter/channel found
      Channel-->>Wrapper: newsletter chatWid
    else not found
      Wrapper->>Store: findOrCreateLatestChat(chatWid)
      alt found
        Store-->>Wrapper: chatWid
      else not found
        Wrapper->>Sync: build + execute contact-add delta
        Sync-->>Wrapper: response with created chatWid
      end
    end
  else Migration gate disabled
    Wrapper-->>Store: return created Wid or fallback chatWid
  end
  Wrapper-->>Caller: resolved chatWid
  Caller->>Store: perform send/typing/image/button operation with chatWid
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hop through WIDs and mend the trail,
Adding bridges when old paths fail.
A twitch of whiskers, a clever fix,
Chats find each other through my tricks.
Messages bounce — hooray, no derail! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix lid migration' directly relates to the main objective of the pull request, which implements lid migration fixes throughout multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-lid-migration

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1502688 and 37876cc.

📒 Files selected for processing (3)
  • src/lib/wapi/functions/get-chat.js
  • src/lib/wapi/functions/send-image-with-product.js
  • src/lib/wapi/helper/fix-lid-migration.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/wapi/functions/send-image-with-product.js
  • src/lib/wapi/functions/get-chat.js
🧰 Additional context used
📓 Path-based instructions (1)
src/lib/wapi/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI layer code is built with webpack and injected into the Puppeteer browser context

Files:

  • src/lib/wapi/helper/fix-lid-migration.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/lib/wapi/helper/fix-lid-migration.js (1)

1-12: Add JSDoc to explain LID migration normalization.

The function lacks documentation explaining what LID migration is, the expected input format, and the transformation behavior.

📝 Suggested JSDoc
+/**
+ * Normalizes LID (Local Identifier) migration format for WhatsApp identifiers.
+ * Converts identifiers in the format "digits:digits@lid" to "digits@lid".
+ * 
+ * @param {string} number - The chat or contact identifier to normalize
+ * @returns {string} The normalized identifier, or the original if not an LID format
+ * @example
+ * fixLidMigration("1234:5678@lid") // returns "1234@lid"
+ * fixLidMigration("1234567890@c.us") // returns "1234567890@c.us"
+ */
 export function fixLidMigration(number) {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41b4352 and bf22e7d.

📒 Files selected for processing (4)
  • src/lib/wapi/functions/send-message.js
  • src/lib/wapi/functions/simulate-typing.js
  • src/lib/wapi/helper/fix-lid-migration.js
  • src/lib/wapi/helper/index.js
🧰 Additional context used
📓 Path-based instructions (2)
src/lib/wapi/functions/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run npm run build:wapi to rebuild

Files:

  • src/lib/wapi/functions/send-message.js
  • src/lib/wapi/functions/simulate-typing.js
src/lib/wapi/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI layer code is built with webpack and injected into the Puppeteer browser context

Files:

  • src/lib/wapi/functions/send-message.js
  • src/lib/wapi/functions/simulate-typing.js
  • src/lib/wapi/helper/index.js
  • src/lib/wapi/helper/fix-lid-migration.js
🧠 Learnings (1)
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/lib/wapi/functions/**/*.js : WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run `npm run build:wapi` to rebuild

Applied to files:

  • src/lib/wapi/helper/index.js
🧬 Code graph analysis (2)
src/lib/wapi/functions/send-message.js (2)
src/lib/wapi/functions/check-send-exist.js (1)
  • to (15-15)
src/lib/wapi/helper/fix-lid-migration.js (1)
  • fixLidMigration (1-12)
src/lib/wapi/functions/simulate-typing.js (1)
src/lib/wapi/helper/fix-lid-migration.js (1)
  • fixLidMigration (1-12)
🔇 Additional comments (5)
src/lib/wapi/helper/index.js (1)

10-10: LGTM!

The export follows the established pattern and correctly exposes the new helper function.

src/lib/wapi/functions/simulate-typing.js (2)

1-3: LID migration normalization applied correctly.

The integration properly normalizes the chatId before creating the Wid. However, ensure the upstream issues in fixLidMigration (empty string return and missing input validation) are addressed to prevent createWid from receiving invalid inputs.


1-14: Reminder: Rebuild WAPI after changes.

After modifying WAPI functions, run npm run build:wapi to rebuild the injected browser context code.

As per coding guidelines.

src/lib/wapi/functions/send-message.js (2)

1-1: LID migration normalization integrated correctly.

The normalization is applied to the recipient number before chat resolution. However, be aware that if fixLidMigration returns an empty string for malformed inputs (currently an issue), it could bypass the validation at lines 28-30, potentially causing failures in sendExist or returnChat.

Also applies to: 32-32


1-154: Reminder: Rebuild WAPI after changes.

After modifying WAPI functions, run npm run build:wapi to rebuild the injected browser context code.

As per coding guidelines.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ad78fe and aca7e33.

📒 Files selected for processing (1)
  • src/lib/wapi/functions/simulate-typing.js
🧰 Additional context used
📓 Path-based instructions (2)
src/lib/wapi/functions/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run npm run build:wapi to rebuild

Files:

  • src/lib/wapi/functions/simulate-typing.js
src/lib/wapi/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI layer code is built with webpack and injected into the Puppeteer browser context

Files:

  • src/lib/wapi/functions/simulate-typing.js
🧬 Code graph analysis (1)
src/lib/wapi/functions/simulate-typing.js (1)
src/lib/wapi/helper/fix-lid-migration.js (1)
  • fixLidMigration (1-14)
🔇 Additional comments (2)
src/lib/wapi/functions/simulate-typing.js (2)

1-15: Reminder: Rebuild WAPI functions after changes.

As per coding guidelines, WAPI functions must be rebuilt after modification. Please run npm run build:wapi to ensure the changes are properly bundled for injection into the browser context.


1-1: The import is correct and properly exported.

The fixLidMigration helper is correctly exported from ../helper/index.js and properly imported here. Since this is a WAPI function, remember to run npm run build:wapi after making changes to rebuild the injected code.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/lib/wapi/functions/simulate-typing.js (1)

4-14: Missing await on async function call causes runtime failure.

createWidWrapper is an async function, but line 4 calls it without await. This causes:

  • chat to be a Promise object instead of the resolved Wid
  • The if (!chat) check at line 5 will always be false (Promises are truthy)
  • Store.ChatState.sendChatStateComposing(chat) at line 13 will receive a Promise instead of a Wid, likely causing an error
🔎 Proposed fix
-  const chat = createWidWrapper(chatId);
+  const chat = await createWidWrapper(chatId);
src/lib/wapi/functions/get-chat.js (1)

22-47: sendMessage augmentation skipped for newly created chats.

The sendMessage method is only added in the else block (lines 41-47), which only executes when found is truthy. However, when a chat is created in the if block (lines 22-40), found will be the newly created chat, and the code won't reach the else block. This means newly created chats won't have the sendMessage method augmented.

🔎 Proposed fix

Move the sendMessage augmentation outside the if/else, or add it in both branches:

       found = Store.Chat.find(ConstructChat) || false;
     }
-  } else {
+  }
+  
+  if (found) {
     found.sendMessage = found.sendMessage
       ? found.sendMessage
       : function () {
           return window.Store.sendMessage.apply(this, arguments);
         };
   }
   return found;
♻️ Duplicate comments (1)
src/lib/wapi/functions/simulate-typing.js (1)

3-3: Debug logging already flagged in previous review.

This console.log statement was already identified in a previous review and should be removed or guarded behind a debug flag.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aca7e33 and 1502688.

📒 Files selected for processing (11)
  • src/lib/wapi/business/send-message-with-buttons.js
  • src/lib/wapi/functions/get-chat.js
  • src/lib/wapi/functions/index.js
  • src/lib/wapi/functions/send-image-with-product.js
  • src/lib/wapi/functions/send-message.js
  • src/lib/wapi/functions/send-message2.js
  • src/lib/wapi/functions/simulate-typing.js
  • src/lib/wapi/helper/fix-lid-migration.js
  • src/lib/wapi/helper/index.js
  • src/lib/wapi/store/store-objects.js
  • src/lib/wapi/wapi.js
💤 Files with no reviewable changes (3)
  • src/lib/wapi/functions/index.js
  • src/lib/wapi/functions/send-message2.js
  • src/lib/wapi/wapi.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/wapi/helper/index.js
  • src/lib/wapi/functions/send-message.js
🧰 Additional context used
📓 Path-based instructions (2)
src/lib/wapi/functions/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run npm run build:wapi to rebuild

Files:

  • src/lib/wapi/functions/send-image-with-product.js
  • src/lib/wapi/functions/get-chat.js
  • src/lib/wapi/functions/simulate-typing.js
src/lib/wapi/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI layer code is built with webpack and injected into the Puppeteer browser context

Files:

  • src/lib/wapi/functions/send-image-with-product.js
  • src/lib/wapi/store/store-objects.js
  • src/lib/wapi/business/send-message-with-buttons.js
  • src/lib/wapi/helper/fix-lid-migration.js
  • src/lib/wapi/functions/get-chat.js
  • src/lib/wapi/functions/simulate-typing.js
🧠 Learnings (1)
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/lib/wapi/functions/**/*.js : WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run `npm run build:wapi` to rebuild

Applied to files:

  • src/lib/wapi/functions/send-image-with-product.js
🧬 Code graph analysis (6)
src/lib/wapi/functions/send-image-with-product.js (1)
src/lib/wapi/helper/fix-lid-migration.js (1)
  • createWidWrapper (1-42)
src/lib/wapi/store/store-objects.js (3)
src/lib/wapi/wapi.js (1)
  • module (166-166)
src/api/helpers/callback-wile.ts (1)
  • module (39-41)
src/lib/wapi/store/get-store.js (1)
  • module (34-34)
src/lib/wapi/business/send-message-with-buttons.js (1)
src/lib/wapi/helper/fix-lid-migration.js (1)
  • createWidWrapper (1-42)
src/lib/wapi/helper/fix-lid-migration.js (2)
src/lib/wapi/functions/get-chat.js (3)
  • gate (9-11)
  • chatWid (15-15)
  • chatWid (28-28)
src/lib/wapi/functions/simulate-typing.js (1)
  • chat (4-4)
src/lib/wapi/functions/get-chat.js (1)
src/lib/wapi/helper/fix-lid-migration.js (3)
  • gate (2-4)
  • chatWid (6-6)
  • createWidWrapper (1-42)
src/lib/wapi/functions/simulate-typing.js (1)
src/lib/wapi/helper/fix-lid-migration.js (2)
  • chat (10-10)
  • createWidWrapper (1-42)
🔇 Additional comments (2)
src/lib/wapi/business/send-message-with-buttons.js (1)

108-113: LGTM!

The async/await handling is correct. The .then() handler is properly marked as async (line 108) and createWidWrapper is correctly awaited (line 113).

src/lib/wapi/store/store-objects.js (1)

221-230: LGTM!

The new store object entries for ChannelUtils and FindOrCreateChat are correctly structured and follow the existing pattern. The conditional checks match the methods used in src/lib/wapi/helper/fix-lid-migration.js (lines 16 and 23).

@9cb14c1ec0 9cb14c1ec0 merged commit 35f62b7 into master Dec 24, 2025
3 checks passed
@9cb14c1ec0 9cb14c1ec0 deleted the fix-lid-migration branch December 24, 2025 02:35
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