feat(engine): Baileys media/location/contact sends (slice 2a)#307
Merged
Conversation
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.
Summary
Slice 2a of the Baileys engine: un-gates the storeless outbound sends — image, video, audio, document, sticker, location, and contact — so
ENGINE_TYPE=baileyscan send rich content, not just text.Stacked on #299 (base branch
feat/baileys-engine-minimal). This PR's diff shows only the slice-2a commits; once #299 merges, I'll retarget the base tomain.What's added
sendImage/Video/Audio/Document/Sticker): each resolvesMediaInput.data(Buffer / base64 /http(s)URL) to aBufferand emits the Baileyssock.sendMessage(jid, content)shape (image/video carrycaption+mimetype, audioptt:false, documentfileName, sticker bare buffer).sendLocationMessage) →{ location: { degreesLatitude, degreesLongitude, name, address } }.sendContactMessage) → a minimal WhatsApp vCard (FN+TEL;waid=…), with CR/LF stripped from name/number to prevent vCard line-injection.getFeatures()now advertisesmedia-messages,location-messages,contact-messages.Security: SSRF-guarded URL media
Baileys, given
{ image: { url } }, would fetch the URL itself with no SSRF guard. So URL media goes through a new neutral helpersrc/common/media/load-remote-media.ts—loadRemoteMediaBuffer(url)— that:assertSafeFetchUrlbefore any socket opens (internal/reserved hosts →SsrfBlockedError),redirect: 'error'(a followed 3xx could reach an internal target),then hands Baileys a
Buffer— a raw{ url }is never passed to the lib. Same guard, cap, timeout, and env knobs (MEDIA_DOWNLOAD_MAX_BYTES,MEDIA_DOWNLOAD_TIMEOUT_MS) as the whatsapp-web.js path. No new dependency (Node globalfetch).Still out of scope (→ slice 2b)
reply/forward/react/deleteremain gated to HTTP 501 — they need a self-maintained store mapping our neutral message id → the Baileys message key/proto (Baileys 6.7.23 ships none). That store is the next slice.Testing
loadRemoteMediaBuffer(SSRF block-before-fetch, streaming cap, redirect, mimetype); per-method adapter send-shape tests (Buffer/base64/URL resolution, URL→guarded fetch, audio ptt, document fileName, location mapping, vCardwaid+ CRLF-injection guard, caller-mimetype-wins); the e2e boot gate's feature list synced to the expanded set.loadRemoteMediaBufferreturns a neutral{ data, mimetype }.