@@ -468,6 +468,35 @@ type SendPayloadParts = {
468468 silent ?: boolean ;
469469} ;
470470
471+ function collectMessageAttachmentMediaHints ( value : unknown ) : string [ ] {
472+ if ( ! Array . isArray ( value ) ) {
473+ return [ ] ;
474+ }
475+ const mediaUrls : string [ ] = [ ] ;
476+ const seen = new Set < string > ( ) ;
477+ const pushMedia = ( entry : unknown ) => {
478+ const normalized = normalizeOptionalString ( entry ) ;
479+ if ( ! normalized || seen . has ( normalized ) ) {
480+ return ;
481+ }
482+ seen . add ( normalized ) ;
483+ mediaUrls . push ( normalized ) ;
484+ } ;
485+ for ( const attachment of value ) {
486+ if ( ! attachment || typeof attachment !== "object" || Array . isArray ( attachment ) ) {
487+ continue ;
488+ }
489+ const record = attachment as Record < string , unknown > ;
490+ pushMedia ( record . media ) ;
491+ pushMedia ( record . mediaUrl ) ;
492+ pushMedia ( record . path ) ;
493+ pushMedia ( record . filePath ) ;
494+ pushMedia ( record . fileUrl ) ;
495+ pushMedia ( record . url ) ;
496+ }
497+ return mediaUrls ;
498+ }
499+
471500function hasExplicitRouteParam ( params : Record < string , unknown > ) : boolean {
472501 for ( const key of [ "channel" , "target" , "to" , "channelId" ] ) {
473502 if ( normalizeOptionalString ( params [ key ] ) ) {
@@ -692,12 +721,14 @@ async function buildSendPayloadParts(params: {
692721 readStringParam ( actionParams , "path" , { trim : false } ) ??
693722 readStringParam ( actionParams , "filePath" , { trim : false } ) ??
694723 readStringParam ( actionParams , "fileUrl" , { trim : false } ) ;
724+ const attachmentMediaHints = collectMessageAttachmentMediaHints ( actionParams . attachments ) ;
725+ const hasMediaHint = Boolean ( mediaHint ) || attachmentMediaHints . length > 0 ;
695726 const hasPresentation = hasMessagePresentationBlocks ( actionParams . presentation ) ;
696727 const hasInteractive = hasInteractiveReplyBlocks ( actionParams . interactive ) ;
697728 const caption = readStringParam ( actionParams , "caption" , { allowEmpty : true } ) ?? "" ;
698729 let message =
699730 readStringParam ( actionParams , "message" , {
700- required : ! mediaHint && ! hasPresentation && ! hasInteractive ,
731+ required : ! hasMediaHint && ! hasPresentation && ! hasInteractive ,
701732 allowEmpty : true ,
702733 } ) ?? "" ;
703734 if ( message . includes ( "\\n" ) ) {
@@ -719,6 +750,9 @@ async function buildSendPayloadParts(params: {
719750 mergedMediaUrls . push ( trimmed ) ;
720751 } ;
721752 pushMedia ( mediaHint ) ;
753+ for ( const attachmentMediaHint of attachmentMediaHints ) {
754+ pushMedia ( attachmentMediaHint ) ;
755+ }
722756 for ( const url of parsed . mediaUrls ?? [ ] ) {
723757 pushMedia ( url ) ;
724758 }
0 commit comments