fix(engine): pass the destination chat to whatsapp-web.js link-preview generation - #1044
Merged
Conversation
…w generation WhatsApp Web selects a different preview transport for newsletters. The released whatsapp-web.js 1.34.7 calls WAWebLinkPreviewChatAction.getLinkPreview(link) with the chat omitted, so the internal action cannot select that transport even though the message is then sent through the newsletter job — the thumbnail arrives blurred or empty on a channel while the same URL renders correctly in a normal chat (#1006). The function genuinely takes two parameters: read off the live WhatsApp Web build, `getLinkPreview` reports arity 2 (`function k(e,t){return I.apply(this,arguments)}`), so supplying the chat fills a declared parameter rather than an ignored one. Backport it the way the 201832 fix is already handled: an exact source transform applied to the installed dependency. The transform is deliberately narrow — it matches one call site and refuses anything else. Already-patched trees are skipped, an unknown shape throws, and a tree carrying both shapes throws rather than guessing. postinstall runs it with --best-effort so a local install never hard-fails, while the production Docker stage runs it strictly, which turns dependency drift into a build failure instead of an image that silently ships without the fix. The edit path (sendMessageEdit) is deliberately left alone: it is a separate call site with a different binding, and editing a link message on a channel is not the reported symptom.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1006.
The defect
A YouTube URL posted to a WhatsApp Channel arrives with a blurred or empty preview thumbnail. The
same URL in a normal 1-on-1 chat renders correctly — the reporter's own A/B in #1006 established that,
and it is what makes the failure specific rather than a platform-wide compression artefact.
WhatsApp Web selects a different preview transport for newsletters.
whatsapp-web.js1.34.7 calls theinternal action with the chat omitted:
so the action cannot select that transport, even though the message is afterwards handed to
sendNewsletterMessageJob. The preview is generated as if for a normal chat and then sent down thenewsletter path.
Why the second argument is real
Read off the live WhatsApp Web build inside a running session rather than inferred from docs:
{ "arity": 2, "source": "function k(e,t){return I.apply(this,arguments)}" }getLinkPreviewdeclares two parameters. Passing the chat fills a parameter the function actuallyhas — this is not an extra argument being harmlessly ignored, and it is not one being repurposed.
The change
The same shape as the existing
201832backport: an exact source transform applied to the installeddependency, plus a spec that asserts the installed tree carries it.
The transform is deliberately narrow and refuses to guess:
postinstallruns it with--best-effort, so a local install never hard-fails. The production Dockerstage runs it strictly after
npm ci, so dependency drift becomes a build failure rather than animage that silently ships without the fix. The two runs compose correctly:
postinstallapplies it,the strict run then skips; if the shape is unknown,
postinstallwarns and the strict run fails thebuild.
scripts/check-dockerignore.mjsgains the new script as a must-keep path, so it cannot be excludedfrom the build context without failing the guard.
Scope
The edit path (
sendMessageEdit) is deliberately untouched. It is a separate call site with adifferent binding, and editing a link message on a channel is not the reported symptom — a channel
edit still uses the old preview path.
Verification
npm run test:scripts— 17/17, covering all four transform branches against temporary fixturesdependency carries the patched call
npm run lint,tsc --noEmit,node scripts/check-dockerignore.mjs— clean