@@ -3,6 +3,7 @@ import { LEXICON_EN } from '../lexicon/lexicon_en.js';
33
44import  {  openai  }  from  '../openai.js' ; 
55import  {  converter  }  from  '../converter.js' ; 
6+ import  {  deleteFile  }  from  '../utils/deleteFile.js' ; 
67
78import  {  menuKeyboard  }  from  '../keyboards/keyboards.js' ; 
89import  {  createInitialSession  }  from  '../utils/createSession.js' ; 
@@ -65,8 +66,8 @@ class OpenAIHandlers {
6566      const  sessionId  =  ctx . message . chat . id ; 
6667      sessions [ sessionId ]  ??=  createInitialSession ( ) ; 
6768
68-       const  processing  =  await  ctx . reply ( 
69-           code ( LEXICON_EN [ 'processingVoice ' ] ) , 
69+       const  processingTranscription  =  await  ctx . reply ( 
70+           code ( LEXICON_EN [ 'processingTranscription ' ] ) , 
7071          menuKeyboard ) ; 
7172
7273      ctx . sendChatAction ( 'typing' ) ; 
@@ -80,6 +81,10 @@ class OpenAIHandlers {
8081      openai 
8182          . transcription ( mp3Path ) 
8283          . then ( async  ( text )  =>  { 
84+             const  processingVoice  =  await  ctx . reply ( 
85+                 code ( LEXICON_EN [ 'processingVoice' ] ) , 
86+                 menuKeyboard ) ; 
87+ 
8388            sessions [ sessionId ] . messages . push ( { 
8489              role : openai . roles . USER , 
8590              content : text , 
@@ -88,11 +93,15 @@ class OpenAIHandlers {
8893            openai 
8994                . chat ( sessions [ sessionId ] . messages ) 
9095                . then ( this . sendResponse ( ctx ,  sessions ,  sessionId ) ) 
91-                 . catch ( ErrorHandler . responseError ( ctx ,  'transcription' ) ) ; 
96+                 . catch ( ErrorHandler . responseError ( ctx ,  'transcription' ) ) 
97+                 . finally ( async  ( )  =>  { 
98+                   await  ctx . deleteMessage ( processingVoice . message_id ) ; 
99+                 } ) ; 
92100          } ) 
93101          . catch ( ErrorHandler . responseError ( ctx ,  'voiceHandler' ) ) 
94102          . finally ( async  ( )  =>  { 
95-             await  ctx . deleteMessage ( processing . message_id ) ; 
103+             await  deleteFile ( mp3Path ) ; 
104+             await  ctx . deleteMessage ( processingTranscription . message_id ) ; 
96105          } ) ; 
97106    } ; 
98107  } ; 
@@ -109,6 +118,7 @@ class OpenAIHandlers {
109118      const  requestText  =  ctx . message . text . replace ( '/image' ,  '' ) . trim ( ) ; 
110119
111120      if  ( ! requestText )  { 
121+         await  ctx . deleteMessage ( processing . message_id ) ; 
112122        await  ctx . reply ( LEXICON_EN [ 'empty' ] ,  {  parse_mode : 'HTML'  } ) ; 
113123        return ; 
114124      } 
0 commit comments