Skip to content

Commit bc451e8

Browse files
committed
feat(Typebot): add splitMessages and timePerChar fields to Typebot models
- Introduced `splitMessages` and `timePerChar` fields in the Typebot and TypebotSetting models with default values. - Created a migration script to update the database schema accordingly. - Updated audio message handling to prepend `[audio]` to transcriptions for better clarity in message context.
1 parent 1eb2c84 commit bc451e8

File tree

12 files changed

+826
-382
lines changed

12 files changed

+826
-382
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- AlterTable
2+
ALTER TABLE "Typebot" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false,
3+
ADD COLUMN "timePerChar" INTEGER DEFAULT 50;
4+
5+
-- AlterTable
6+
ALTER TABLE "TypebotSetting" ADD COLUMN "splitMessages" BOOLEAN DEFAULT false,
7+
ADD COLUMN "timePerChar" INTEGER DEFAULT 50;

prisma/postgresql-schema.prisma

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ model Typebot {
357357
triggerType TriggerType?
358358
triggerOperator TriggerOperator?
359359
triggerValue String?
360+
splitMessages Boolean? @default(false) @db.Boolean
361+
timePerChar Int? @default(50) @db.Integer
360362
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
361363
instanceId String
362364
TypebotSetting TypebotSetting[]
@@ -374,6 +376,8 @@ model TypebotSetting {
374376
debounceTime Int? @db.Integer
375377
typebotIdFallback String? @db.VarChar(100)
376378
ignoreJids Json?
379+
splitMessages Boolean? @default(false) @db.Boolean
380+
timePerChar Int? @default(50) @db.Integer
377381
createdAt DateTime? @default(now()) @db.Timestamp
378382
updatedAt DateTime @updatedAt @db.Timestamp
379383
Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id])

src/api/integrations/channel/evolution/evolution.channel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class EvolutionStartupService extends ChannelStartupService {
165165
openAiDefaultSettings.speechToText &&
166166
received?.message?.audioMessage
167167
) {
168-
messageRaw.message.speechToText = await this.openaiService.speechToText(received, this);
168+
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(received, this)}`;
169169
}
170170
}
171171

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,15 @@ export class BusinessStartupService extends ChannelStartupService {
520520
openAiDefaultSettings.speechToText
521521
) {
522522
try {
523-
messageRaw.message.speechToText = await this.openaiService.speechToText(
523+
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(
524524
openAiDefaultSettings.OpenaiCreds,
525525
{
526526
message: {
527527
mediaUrl: messageRaw.message.mediaUrl,
528528
...messageRaw,
529529
},
530530
},
531-
);
531+
)}`;
532532
} catch (speechError) {
533533
this.logger.error(`Error processing speech-to-text: ${speechError}`);
534534
}
@@ -554,15 +554,15 @@ export class BusinessStartupService extends ChannelStartupService {
554554

555555
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
556556
try {
557-
messageRaw.message.speechToText = await this.openaiService.speechToText(
557+
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(
558558
openAiDefaultSettings.OpenaiCreds,
559559
{
560560
message: {
561561
base64: messageRaw.message.base64,
562562
...messageRaw,
563563
},
564564
},
565-
);
565+
)}`;
566566
} catch (speechError) {
567567
this.logger.error(`Error processing speech-to-text: ${speechError}`);
568568
}

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ export class BaileysStartupService extends ChannelStartupService {
11881188
});
11891189

11901190
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
1191-
messageRaw.message.speechToText = await this.openaiService.speechToText(received, this);
1191+
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(received, this)}`;
11921192
}
11931193
}
11941194

@@ -2111,7 +2111,7 @@ export class BaileysStartupService extends ChannelStartupService {
21112111
});
21122112

21132113
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
2114-
messageRaw.message.speechToText = await this.openaiService.speechToText(messageRaw, this);
2114+
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(messageRaw, this)}`;
21152115
}
21162116
}
21172117

src/api/integrations/chatbot/base-chatbot.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
280280
});
281281

282282
if (!bot) {
283-
throw new Error(`${this.integrationName} not found`);
283+
return null;
284284
}
285285

286286
return bot;

src/api/integrations/chatbot/evoai/services/evoai.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
5555
this.logger.debug(`[EvoAI] Downloading audio for Whisper transcription`);
5656
const transcription = await this.openaiService.speechToText(msg, instance);
5757
if (transcription) {
58-
processedContent = transcription;
58+
processedContent = `[audio] ${transcription}`;
5959
}
6060
} catch (err) {
6161
this.logger.error(`[EvoAI] Failed to transcribe audio: ${err}`);

src/api/integrations/chatbot/evolutionBot/services/evolutionBot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
6464
this.logger.debug(`[EvolutionBot] Downloading audio for Whisper transcription`);
6565
const transcription = await this.openaiService.speechToText(msg, instance);
6666
if (transcription) {
67-
payload.query = transcription;
67+
payload.query = `[audio] ${transcription}`;
6868
}
6969
} catch (err) {
7070
this.logger.error(`[EvolutionBot] Failed to transcribe audio: ${err}`);

src/api/integrations/chatbot/flowise/services/flowise.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class FlowiseService extends BaseChatbotService<FlowiseModel> {
7272
this.logger.debug(`[Flowise] Downloading audio for Whisper transcription`);
7373
const transcription = await this.openaiService.speechToText(msg, instance);
7474
if (transcription) {
75-
payload.question = transcription;
75+
payload.question = `[audio] ${transcription}`;
7676
}
7777
} catch (err) {
7878
this.logger.error(`[Flowise] Failed to transcribe audio: ${err}`);

src/api/integrations/chatbot/n8n/services/n8n.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
6161
this.logger.debug(`[N8n] Downloading audio for Whisper transcription`);
6262
const transcription = await this.openaiService.speechToText(msg, instance);
6363
if (transcription) {
64-
payload.chatInput = transcription;
64+
payload.chatInput = `[audio] ${transcription}`;
6565
}
6666
} catch (err) {
6767
this.logger.error(`[N8n] Failed to transcribe audio: ${err}`);

0 commit comments

Comments
 (0)