fix: resolve build errors and audio transcription issues across chatbot services

- Add YAML file loader to tsup.config.ts to fix build compilation errors
- Fix OpenAI speechToText method signature across all chatbot services
- Correct DifyService constructor parameter order in server.module.ts and channel.service.ts
- Add missing OpenAI service dependency injection to EvoaiService
- Standardize audio transcription logic in FlowiseService to match N8N implementation
- Fix speechToText calls in WhatsApp Baileys and Evolution channel services
- Ensure consistent error handling and parameter passing for audio processing

This resolves the "Cannot read properties of undefined" errors and ensures
all chatbot integrations (OpenAI, N8N, Flowise, EvoAI, Dify, EvolutionBot)
properly handle audio message transcription using OpenAI Whisper.
This commit is contained in:
Guilherme Gomes 2025-05-27 17:46:29 -03:00
parent 3fc77e4c76
commit 98502f6555
6 changed files with 7 additions and 6 deletions

View File

@ -165,7 +165,7 @@ export class EvolutionStartupService extends ChannelStartupService {
openAiDefaultSettings.speechToText && openAiDefaultSettings.speechToText &&
received?.message?.audioMessage received?.message?.audioMessage
) { ) {
messageRaw.message.speechToText = await this.openaiService.speechToText(received); messageRaw.message.speechToText = await this.openaiService.speechToText(received, this);
} }
} }

View File

@ -1298,7 +1298,7 @@ export class BaileysStartupService extends ChannelStartupService {
}); });
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) { if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
messageRaw.message.speechToText = await this.openaiService.speechToText(received); messageRaw.message.speechToText = await this.openaiService.speechToText(received, this);
} }
} }
@ -2324,7 +2324,7 @@ export class BaileysStartupService extends ChannelStartupService {
}); });
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) { if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
messageRaw.message.speechToText = await this.openaiService.speechToText(messageRaw); messageRaw.message.speechToText = await this.openaiService.speechToText(messageRaw, this);
} }
} }

View File

@ -62,7 +62,7 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
if (this.isAudioMessage(content) && msg) { if (this.isAudioMessage(content) && msg) {
try { try {
this.logger.debug(`[EvolutionBot] Downloading audio for Whisper transcription`); this.logger.debug(`[EvolutionBot] Downloading audio for Whisper transcription`);
const transcription = await this.openaiService.speechToText(msg); const transcription = await this.openaiService.speechToText(msg, instance);
if (transcription) { if (transcription) {
payload.query = transcription; payload.query = transcription;
} else { } else {

View File

@ -123,7 +123,7 @@ export const openaiController = new OpenaiController(openaiService, prismaReposi
const typebotService = new TypebotService(waMonitor, configService, prismaRepository, openaiService); const typebotService = new TypebotService(waMonitor, configService, prismaRepository, openaiService);
export const typebotController = new TypebotController(typebotService, prismaRepository, waMonitor); export const typebotController = new TypebotController(typebotService, prismaRepository, waMonitor);
const difyService = new DifyService(waMonitor, configService, prismaRepository, openaiService); const difyService = new DifyService(waMonitor, prismaRepository, configService, openaiService);
export const difyController = new DifyController(difyService, prismaRepository, waMonitor); export const difyController = new DifyController(difyService, prismaRepository, waMonitor);
const evolutionBotService = new EvolutionBotService(waMonitor, configService, prismaRepository, openaiService); const evolutionBotService = new EvolutionBotService(waMonitor, configService, prismaRepository, openaiService);

View File

@ -49,7 +49,7 @@ export class ChannelStartupService {
public typebotService = new TypebotService(waMonitor, this.configService, this.prismaRepository, this.openaiService); public typebotService = new TypebotService(waMonitor, this.configService, this.prismaRepository, this.openaiService);
public difyService = new DifyService(waMonitor, this.configService, this.prismaRepository, this.openaiService); public difyService = new DifyService(waMonitor, this.prismaRepository, this.configService, this.openaiService);
public setInstance(instance: InstanceDto) { public setInstance(instance: InstanceDto) {
this.logger.setInstance(instance.instanceName); this.logger.setInstance(instance.instanceName);

View File

@ -15,5 +15,6 @@ export default defineConfig({
}, },
loader: { loader: {
'.json': 'file', '.json': 'file',
'.yml': 'file',
}, },
}); });