@@ -296,12 +296,15 @@ async function deliverMediaReply(params: {
296296 recordMessageId : ( messageId : number ) => void ;
297297 textMode ?: "html" ;
298298 onPlatformSendDispatch ?: ( ) => Promise < void > ;
299- } ) : Promise < { firstDeliveredMessageId ?: number ; visibleFallbackText ?: string } > {
299+ } ) : Promise < {
300+ firstDeliveredMessageId ?: number ;
301+ visibleFallbackText ?: string ;
302+ mediaUrls : string [ ] ;
303+ } > {
300304 let firstDeliveredMessageId : number | undefined ;
301305 let visibleFallbackText : string | undefined ;
302306 let firstDeliveredCaption : string | undefined ;
303- let first = true ;
304- let pendingFollowUpText : string | undefined ;
307+ const mediaUrls : string [ ] = [ ] ;
305308 const recordPromptContextMessage = async ( message : Message , text ?: string ) => {
306309 const promptContextMessage = {
307310 messageId : message . message_id ,
@@ -312,6 +315,7 @@ async function deliverMediaReply(params: {
312315 } ;
313316 const deliverAcceptedMedia = async ( options : {
314317 sender : TelegramOutboundMediaSender < Message > ;
318+ mediaUrl : string ;
315319 requestParams : Record < string , unknown > ;
316320 plainCaption ?: string ;
317321 shouldLog ?: ( err : unknown ) => boolean ;
@@ -332,6 +336,7 @@ async function deliverMediaReply(params: {
332336 } ) ,
333337 } ) ;
334338 const message = delivery . result ;
339+ mediaUrls . push ( options . mediaUrl ) ;
335340 // Acceptance precedes topic checks and bookkeeping; losing this id lets
336341 // later failures trigger a duplicate reply for an already visible message.
337342 params . acceptedMessageIds . push ( String ( message . message_id ) ) ;
@@ -358,8 +363,8 @@ async function deliverMediaReply(params: {
358363 deliveredCount : 0 ,
359364 ...( params . progress . promptContext ? { promptContext : params . progress . promptContext } : { } ) ,
360365 } ) ;
361- for ( const mediaUrl of params . mediaList ) {
362- const isFirstMedia = first ;
366+ for ( const [ index , mediaUrl ] of params . mediaList . entries ( ) ) {
367+ const isFirstMedia = index === 0 ;
363368 const media = await params . mediaLoader (
364369 mediaUrl ,
365370 buildOutboundMediaLoadOptions ( {
@@ -382,10 +387,6 @@ async function deliverMediaReply(params: {
382387 asVoice : params . reply . audioAsVoice ,
383388 } ) ;
384389 const { htmlCaption, plainCaption, followUpText } = mediaPlan ;
385- if ( followUpText ) {
386- pendingFollowUpText = followUpText ;
387- }
388- first = false ;
389390 const replyToMessageId = resolveReplyToForSend ( {
390391 replyToId : params . replyToId ,
391392 replyToMode : params . replyToMode ,
@@ -417,6 +418,7 @@ async function deliverMediaReply(params: {
417418 const hasCaption = typeof requestParams . caption === "string" ;
418419 await deliverAcceptedMedia ( {
419420 sender : mediaSender ,
421+ mediaUrl,
420422 requestParams,
421423 plainCaption : hasCaption ? plainCaption : undefined ,
422424 shouldLog,
@@ -521,6 +523,7 @@ async function deliverMediaReply(params: {
521523 send : ( sender ) =>
522524 deliverAcceptedMedia ( {
523525 sender,
526+ mediaUrl,
524527 requestParams : mediaParams ,
525528 plainCaption,
526529 ...( sender . label === "photo"
@@ -530,15 +533,15 @@ async function deliverMediaReply(params: {
530533 } ) ;
531534 }
532535 markReplyApplied ( params . progress , replyToMessageId ) ;
533- if ( pendingFollowUpText && isFirstMedia ) {
536+ if ( followUpText ) {
534537 try {
535538 const followUpMessageId = await deliverTextReply ( {
536539 bot : params . bot ,
537540 chatId : params . chatId ,
538541 runtime : params . runtime ,
539542 thread : params . thread ,
540543 chunkText : params . chunkText ,
541- text : pendingFollowUpText ,
544+ text : followUpText ,
542545 replyMarkup : params . replyMarkup ,
543546 richMessages : params . richMessages ,
544547 tableMode : params . tableMode ,
@@ -567,10 +570,9 @@ async function deliverMediaReply(params: {
567570 } ) ;
568571 }
569572 }
570- pendingFollowUpText = undefined ;
571573 }
572574 }
573- return { firstDeliveredMessageId, visibleFallbackText } ;
575+ return { firstDeliveredMessageId, visibleFallbackText, mediaUrls } ;
574576}
575577
576578async function maybePinFirstDeliveredMessage ( params : {
@@ -881,6 +883,7 @@ export async function deliverReplies(params: {
881883 } ) ,
882884 ) ;
883885 let firstDeliveredMessageId : number | undefined ;
886+ let deliveredMediaUrls : string [ ] = [ ] ;
884887 if ( reactionEmoji && typeof targetId === "number" ) {
885888 await params . onPlatformSendDispatch ?.( ) ;
886889 const reactionResult = await reactMessageTelegram ( params . chatId , targetId , reactionEmoji , {
@@ -953,6 +956,7 @@ export async function deliverReplies(params: {
953956 ...( params . textMode ? { textMode : params . textMode } : { } ) ,
954957 } ) ;
955958 firstDeliveredMessageId = mediaDelivery . firstDeliveredMessageId ;
959+ deliveredMediaUrls = mediaDelivery . mediaUrls ;
956960 if ( mediaDelivery . visibleFallbackText !== undefined ) {
957961 contentForSentHook = mediaDelivery . visibleFallbackText ;
958962 }
@@ -966,7 +970,7 @@ export async function deliverReplies(params: {
966970 } ) ;
967971
968972 if ( progress . deliveredCount > deliveredCountBeforeReply && transcriptMirror ) {
969- deliveredContents . push ( { text : contentForSentHook , mediaUrls : mediaList } ) ;
973+ deliveredContents . push ( { text : contentForSentHook , mediaUrls : deliveredMediaUrls } ) ;
970974 }
971975
972976 emitMessageSentHooks ( {
0 commit comments