@@ -174,6 +174,64 @@ describe("processDiscordMessage session routing", () => {
174174 expect ( dispatchCtx . MediaPaths ) . toBeUndefined ( ) ;
175175 } ) ;
176176
177+ it ( "keeps attachment-only referenced messages as typed reply context" , async ( ) => {
178+ const fetchImpl = vi . fn (
179+ async ( ) => new Response ( Buffer . from ( "image" ) , { headers : { "content-type" : "image/png" } } ) ,
180+ ) ;
181+ const ctx = await createBaseContext ( {
182+ cfg : {
183+ channels : { discord : { contextVisibility : "all" } } ,
184+ messages : { ackReaction : "👀" } ,
185+ session : { store : "/tmp/openclaw-discord-process-test-sessions.json" } ,
186+ } ,
187+ discordRestFetch : fetchImpl ,
188+ message : {
189+ id : "m-attachment-reply" ,
190+ channelId : "c1" ,
191+ content : "<@bot> what is this?" ,
192+ timestamp : new Date ( ) . toISOString ( ) ,
193+ attachments : [ ] ,
194+ messageReference : { type : 0 , message_id : "m-attachment-only" , channel_id : "c1" } ,
195+ referencedMessage : {
196+ id : "m-attachment-only" ,
197+ channelId : "c1" ,
198+ content : "" ,
199+ timestamp : new Date ( ) . toISOString ( ) ,
200+ attachments : [
201+ {
202+ id : "att-only" ,
203+ url : "https://cdn.discordapp.com/attachments/1/attachment-only.png" ,
204+ content_type : "image/png" ,
205+ filename : "attachment-only.png" ,
206+ } ,
207+ ] ,
208+ author : {
209+ id : "U2" ,
210+ username : "bob" ,
211+ discriminator : "0" ,
212+ globalName : "Bob" ,
213+ } ,
214+ } ,
215+ } ,
216+ baseText : "<@bot> what is this?" ,
217+ messageText : "<@bot> what is this?" ,
218+ } ) ;
219+
220+ await runProcessDiscordMessage ( ctx ) ;
221+
222+ const dispatchCtx = requireRecord ( getLastDispatchCtx ( ) , "dispatch context" ) ;
223+ expect ( dispatchCtx . ReplyToId ) . toBe ( "m-attachment-only" ) ;
224+ expect ( dispatchCtx . ReplyToSender ) . toBe ( "bob" ) ;
225+ expect ( dispatchCtx . ReplyToBody ) . toBeUndefined ( ) ;
226+ expect ( dispatchCtx . media ) . toEqual ( [
227+ expect . objectContaining ( {
228+ contentType : "image/png" ,
229+ messageId : "m-attachment-only" ,
230+ } ) ,
231+ ] ) ;
232+ expect ( fetchImpl ) . toHaveBeenCalledOnce ( ) ;
233+ } ) ;
234+
177235 it ( "does not inject the bot's previous message body when users reply to it" , async ( ) => {
178236 const fetchImpl = vi . fn ( async ( ) => {
179237 throw new Error ( "self-reply media should not be fetched" ) ;
0 commit comments