From f5f423eb74a4bea4a934d6297362eec2b1019827 Mon Sep 17 00:00:00 2001 From: JrStarkmidia <37372590+JrStarkmidia@users.noreply.github.com> Date: Thu, 26 Jun 2025 20:03:59 -0300 Subject: [PATCH 1/2] fix: guard applyFormatting --- .../integrations/chatbot/typebot/services/typebot.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/integrations/chatbot/typebot/services/typebot.service.ts b/src/api/integrations/chatbot/typebot/services/typebot.service.ts index 01346fa63..5cf35c323 100644 --- a/src/api/integrations/chatbot/typebot/services/typebot.service.ts +++ b/src/api/integrations/chatbot/typebot/services/typebot.service.ts @@ -197,6 +197,9 @@ export class TypebotService extends BaseChatbotService { * Apply rich text formatting for TypeBot messages */ private applyFormatting(element: any): string { + if (typeof element === 'string') return element; + if (!element) return ''; + let text = ''; if (element.text) { From f9eaf1c295673a7af3c48fcef8068339c2ccdff6 Mon Sep 17 00:00:00 2001 From: JrStarkmidia <37372590+JrStarkmidia@users.noreply.github.com> Date: Thu, 26 Jun 2025 20:28:22 -0300 Subject: [PATCH 2/2] refactor: type-safe applyFormatting --- .../chatbot/typebot/services/typebot.service.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/chatbot/typebot/services/typebot.service.ts b/src/api/integrations/chatbot/typebot/services/typebot.service.ts index 5cf35c323..bf52e9637 100644 --- a/src/api/integrations/chatbot/typebot/services/typebot.service.ts +++ b/src/api/integrations/chatbot/typebot/services/typebot.service.ts @@ -9,6 +9,16 @@ import axios from 'axios'; import { BaseChatbotService } from '../../base-chatbot.service'; import { OpenaiService } from '../../openai/services/openai.service'; +interface RichTextNode { + text?: string; + type?: string; + children?: RichTextNode[]; + bold?: boolean; + italic?: boolean; + underline?: boolean; + url?: string; +} + export class TypebotService extends BaseChatbotService { private openaiService: OpenaiService; @@ -196,9 +206,8 @@ export class TypebotService extends BaseChatbotService { /** * Apply rich text formatting for TypeBot messages */ - private applyFormatting(element: any): string { - if (typeof element === 'string') return element; - if (!element) return ''; + private applyFormatting(element: string | RichTextNode | undefined): string { + if (!element || typeof element === 'string') return element || ''; let text = '';