Skip to content

Commit d5c1ad3

Browse files
committed
fix: fix bug with sending process messages for voiceHandler
1 parent ae394b9 commit d5c1ad3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/handlers/openaiHandlers.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class OpenAIHandlers {
6666
const sessionId = ctx.message.chat.id;
6767
sessions[sessionId] ??= createInitialSession();
6868

69-
const processing = await ctx.reply(
70-
code(LEXICON_EN['processingVoice']),
69+
const processingTranscription = await ctx.reply(
70+
code(LEXICON_EN['processingTranscription']),
7171
menuKeyboard);
7272

7373
ctx.sendChatAction('typing');
@@ -81,19 +81,27 @@ class OpenAIHandlers {
8181
openai
8282
.transcription(mp3Path)
8383
.then(async (text) => {
84+
const processingVoice = await ctx.reply(
85+
code(LEXICON_EN['processingVoice']),
86+
menuKeyboard);
87+
8488
sessions[sessionId].messages.push({
8589
role: openai.roles.USER,
8690
content: text,
8791
});
92+
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 () => {
95103
await deleteFile(mp3Path);
96-
await ctx.deleteMessage(processing.message_id);
104+
await ctx.deleteMessage(processingTranscription.message_id);
97105
});
98106
};
99107
};

src/lexicon/lexicon_en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const LEXICON_EN = {
1818
'Developer: @blazzed21\n',
1919
deniedAccess: 'This functionality is not available to you ⛔️',
2020
processingText: 'Text accepted for processing',
21+
processingTranscription: 'Voice message accepted for translation into text',
2122
processingVoice: 'Voice message accepted for processing',
2223
processingImage: 'The request to generate an'+
2324
'image was accepted for processing',

0 commit comments

Comments
 (0)