fix(newsletter): parse metadata and fetch-messages responses#2620
fix(newsletter): parse metadata and fetch-messages responses#2620vinikjkkj wants to merge 1 commit into
Conversation
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughNewsletter parsing now decodes protobuf message payloads and robustly parses binary-node fields; newsletterFetchMessages issues a ChangesNewsletter Socket Message and Metadata Parsing
Newsletter Response Type Update
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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. Comment |
34d3250 to
cc4c345
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Socket/newsletter.ts (1)
1-8:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winFix import sorting and use type-only import for BinaryNode.
The pipeline flagged an import sorting violation. Additionally,
BinaryNodeis only used as a type annotation (line 58), so it should useimport typeto satisfy theverbatimModuleSyntaxstrict mode requirement.📦 Proposed fix
-import type { NewsletterCreateResponse, SocketConfig, WAMediaUpload } from '../Types' -import type { NewsletterMetadata, NewsletterUpdate } from '../Types' +import type { NewsletterCreateResponse, NewsletterMetadata, NewsletterUpdate, SocketConfig, WAMediaUpload } from '../Types' import { QueryIds, XWAPaths } from '../Types' import { generateProfilePicture } from '../Utils/messages-media' -import { type BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary' +import type { BinaryNode } from '../WABinary' +import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary' +import { proto } from '../../WAProto/index.js' import { makeGroupsSocket } from './groups' import { executeWMexQuery as genericExecuteWMexQuery } from './mex' -import { proto } from '../../WAProto/index.js'As per coding guidelines, type-only imports must use
import typeor inlinetypeprefix forverbatimModuleSyntaxstrict mode.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Socket/newsletter.ts` around lines 1 - 8, Update the import block to satisfy import-sorting and verbatimModuleSyntax: make BinaryNode a type-only import by changing its import to "import type { BinaryNode } from '../WABinary'" (leave getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET as value imports), and reorder the import statements so type-only imports (e.g., NewsletterCreateResponse, SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterUpdate, QueryIds, XWAPaths, BinaryNode) are grouped/placed appropriately before/after value imports according to the repo's sorting rule so ESLint import-sorting no longer flags the file; ensure unique symbols referenced: BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET, generateProfilePicture, makeGroupsSocket, genericExecuteWMexQuery, proto.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Socket/newsletter.ts`:
- Line 34: Replace the unsafe cast to any by casting result to Record<string,
unknown> for better type safety: change the declaration of raw (the variable
assigned from result in newsletter.ts) from using Record<string, any> to
Record<string, unknown>, and ensure subsequent property accesses on raw continue
to use optional chaining/nullish coalescing as already implemented.
- Line 97: parseFetchedNewsletterMessage currently calls
proto.Message.decode(plaintextContent) directly which can throw on malformed
protobufs and abort newsletterFetchMessages; wrap the decode call in a try/catch
inside parseFetchedNewsletterMessage (or the object construction that sets the
message field) and on error set message: undefined (or return a structured error
object) so a single bad payload won’t break the whole fetch; specifically catch
around proto.Message.decode(plaintextContent) and handle the failure path
consistently with other decode sites in this file.
---
Outside diff comments:
In `@src/Socket/newsletter.ts`:
- Around line 1-8: Update the import block to satisfy import-sorting and
verbatimModuleSyntax: make BinaryNode a type-only import by changing its import
to "import type { BinaryNode } from '../WABinary'" (leave getBinaryNodeChild,
getBinaryNodeChildren, S_WHATSAPP_NET as value imports), and reorder the import
statements so type-only imports (e.g., NewsletterCreateResponse, SocketConfig,
WAMediaUpload, NewsletterMetadata, NewsletterUpdate, QueryIds, XWAPaths,
BinaryNode) are grouped/placed appropriately before/after value imports
according to the repo's sorting rule so ESLint import-sorting no longer flags
the file; ensure unique symbols referenced: BinaryNode, getBinaryNodeChild,
getBinaryNodeChildren, S_WHATSAPP_NET, generateProfilePicture, makeGroupsSocket,
genericExecuteWMexQuery, proto.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 756cce53-e343-4683-8e6c-05ad850dd43b
📒 Files selected for processing (2)
src/Socket/newsletter.tssrc/Types/Mex.ts
💤 Files with no reviewable changes (1)
- src/Types/Mex.ts
There was a problem hiding this comment.
1 issue found across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
`newsletterMetadata`: transform the raw server response into the flat `NewsletterMetadata` shape instead of casting it, and fall back to `image`/`preview` when `picture` is absent (preview-only responses for non-followers). Fixes #2204. `newsletterFetchMessages`: send the WA-Web-shaped query (`<iq to='s.whatsapp.net' xmlns='newsletter'><messages type='jid' jid count/></iq>`) instead of `<message_updates>` addressed to the channel jid, which timed out, then parse the `<messages>` response into messages carrying `reactions`, `pollVotes`, views/forwards/responses counts, edit timestamps, media `rcat`, and the decoded plaintext `proto.Message`. Fixes #2555. `Mex.ts`: remove the duplicated `NewsletterCreateResponse` interface. All changes were validated end-to-end against live WhatsApp. `newsletterMetadata` and `newsletterFetchMessages` were verified on a real public channel (~109k subscribers): metadata returns the flat shape with the channel picture (resolved from `preview`), and fetch returns real messages with decoded `proto.Message` content, `reactions`, and `forwards` counts (both previously timed out or returned `null`).
cc4c345 to
5f1f118
Compare
…Sockets#2620 port) (#503) fix(newsletter): parse metadata and fetch-messages responses (WhiskeySockets#2620 port) (#503)
…a picture fallback PR #508 review caught an ambiguity in the picture-fallback chain inherited from upstream PR WhiskeySockets#2620 (#503 port). The original chain only looked inside `thread_metadata`: const pic = thread.picture ?? thread.image ?? thread.preview but the in-code comment noted that for preview-only responses (non-followed channel via invite) the server returns `image` / `preview` SIBLINGS of `thread_metadata` rather than children of it. The chain was missing the sibling case, so the picture came back undefined for that flow. Extend the fallback to also try `node.image` and `node.preview`. Additive and defensive — `undefined ?? undefined` short-circuits cleanly when the server returns the followed-channel shape (which has worked since #503 merged). Also refine the comment so the chain is unambiguous on the next read. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…a picture fallback PR #508 review caught an ambiguity in the picture-fallback chain inherited from upstream PR WhiskeySockets#2620 (#503 port). The original chain only looked inside `thread_metadata`: const pic = thread.picture ?? thread.image ?? thread.preview but the in-code comment noted that for preview-only responses (non-followed channel via invite) the server returns `image` / `preview` SIBLINGS of `thread_metadata` rather than children of it. The chain was missing the sibling case, so the picture came back undefined for that flow. Extend the fallback to also try `node.image` and `node.preview`. Additive and defensive — `undefined ?? undefined` short-circuits cleanly when the server returns the followed-channel shape (which has worked since #503 merged). Also refine the comment so the chain is unambiguous on the next read. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
newsletterMetadata: transform the raw server response into the flatNewsletterMetadatashape instead of casting it, and fall back toimage/previewwhenpictureis absent (preview-only responses for non-followers). Fixes #2204.newsletterFetchMessages: send the WA-Web-shaped query (<iq to='s.whatsapp.net' xmlns='newsletter'><messages type='jid' jid count/></iq>) instead of<message_updates>addressed to the channel jid, which timed out, then parse the<messages>response into messages carryingreactions,pollVotes, views/forwards/responses counts, edit timestamps, mediarcat, and the decoded plaintextproto.Message. Fixes #2555.Mex.ts: remove the duplicatedNewsletterCreateResponseinterface.All changes were validated end-to-end against live WhatsApp.
newsletterMetadataandnewsletterFetchMessageswere verified on a real public channel: metadata returns the flat shape with the channel picture (resolved frompreview), and fetch returns real messages with decodedproto.Messagecontent,reactions, andforwardscounts (both previously timed out or returnednull).Summary by CodeRabbit