@@ -345,21 +345,27 @@ async function deliverMediaReply(params: {
345345 logFallback : logVerbose ,
346346 } ) ;
347347 if ( useVoice ) {
348- await params . onVoiceRecording ?.( ) ;
349- try {
348+ const sendVoiceMedia = async (
349+ requestParams : typeof mediaParams ,
350+ shouldLog ?: ( err : unknown ) => boolean ,
351+ ) => {
350352 const result = await sendTelegramWithThreadFallback ( {
351353 operation : "sendVoice" ,
352354 runtime : params . runtime ,
353355 thread : params . thread ,
354- requestParams : mediaParams ,
355- shouldLog : ( err ) => ! isVoiceMessagesForbidden ( err ) ,
356+ requestParams,
357+ shouldLog,
356358 send : ( effectiveParams ) =>
357359 params . bot . api . sendVoice ( params . chatId , file , { ...effectiveParams } ) ,
358360 } ) ;
359361 if ( firstDeliveredMessageId == null ) {
360362 firstDeliveredMessageId = result . message_id ;
361363 }
362364 markDelivered ( params . progress ) ;
365+ } ;
366+ await params . onVoiceRecording ?.( ) ;
367+ try {
368+ await sendVoiceMedia ( mediaParams , ( err ) => ! isVoiceMessagesForbidden ( err ) ) ;
363369 } catch ( voiceErr ) {
364370 if ( isVoiceMessagesForbidden ( voiceErr ) ) {
365371 const fallbackText = params . reply . text ;
@@ -400,18 +406,7 @@ async function deliverMediaReply(params: {
400406 const noCaptionParams = { ...mediaParams } ;
401407 delete noCaptionParams . caption ;
402408 delete noCaptionParams . parse_mode ;
403- const result = await sendTelegramWithThreadFallback ( {
404- operation : "sendVoice" ,
405- runtime : params . runtime ,
406- thread : params . thread ,
407- requestParams : noCaptionParams ,
408- send : ( effectiveParams ) =>
409- params . bot . api . sendVoice ( params . chatId , file , { ...effectiveParams } ) ,
410- } ) ;
411- if ( firstDeliveredMessageId == null ) {
412- firstDeliveredMessageId = result . message_id ;
413- }
414- markDelivered ( params . progress ) ;
409+ await sendVoiceMedia ( noCaptionParams ) ;
415410 const fallbackText = params . reply . text ;
416411 if ( fallbackText ?. trim ( ) ) {
417412 await sendTelegramVoiceFallbackText ( {
0 commit comments