@@ -151,13 +151,38 @@ const contactsNode = (msg: CloudWebhookMessage): Record<string, unknown> | null
151151 return { contactsArrayMessage : { displayName : `${ cards . length } contacts` , contacts : cards } }
152152}
153153
154+ /**
155+ * Attach a baileys-shaped contextInfo (from Meta's `context: { id, from }`) so the decoder can
156+ * resolve the quoted message via the store — enables `msg.replied()` on cloud replies. A stub
157+ * `quotedMessage` is required to enter the decoder's resolve branch (it looks up by stanzaId).
158+ */
159+ const applyQuotedContext = (
160+ message : Record < string , unknown > ,
161+ msg : CloudWebhookMessage ,
162+ ) : Record < string , unknown > => {
163+ const context = msg [ 'context' ] as { id ?: string ; from ?: string } | undefined
164+ if ( ! context ?. id ) return message
165+ const contextInfo = {
166+ stanzaId : context . id ,
167+ ...( context . from ? { participant : toJid ( context . from ) } : { } ) ,
168+ quotedMessage : { } ,
169+ }
170+ if ( typeof message [ 'conversation' ] === 'string' ) {
171+ return { extendedTextMessage : { text : message [ 'conversation' ] , contextInfo } }
172+ }
173+ const key = Object . keys ( message ) [ 0 ]
174+ if ( key ) ( message [ key ] as Record < string , unknown > ) [ 'contextInfo' ] = contextInfo
175+ return message
176+ }
177+
154178const translateMessage = ( msg : CloudWebhookMessage , value : CloudWebhookValue ) : WAMessage | null => {
155179 if ( ! msg . id || ! msg . from ) return null
156- const message : Record < string , unknown > | null =
180+ const node : Record < string , unknown > | null =
157181 msg . type === 'text' && typeof msg . text ?. body === 'string'
158182 ? { conversation : msg . text . body }
159183 : ( mediaNode ( msg ) ?? interactiveNode ( msg ) ?? locationNode ( msg ) ?? contactsNode ( msg ) )
160- if ( message === null ) return null
184+ if ( node === null ) return null
185+ const message = applyQuotedContext ( node , msg )
161186 const pushName = contactName ( value , msg . from )
162187 return {
163188 key : { id : msg . id , remoteJid : toJid ( msg . from ) , fromMe : false } ,
0 commit comments