diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 2473c750..2068096f 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2229,7 +2229,10 @@ export class BaileysStartupService extends ChannelStartupService { if (!match) return undefined; - const url = match[0]; + // Trim common trailing punctuation that may follow URLs in natural text + const url = match[0].replace(/[.,);\]]+$/u, ''); + if (!url) return undefined; + const previewData = await getLinkPreview(url, { imagesPropertyType: 'og', // fetches only open-graph images headers: { diff --git a/src/api/integrations/chatbot/typebot/services/typebot.service.ts b/src/api/integrations/chatbot/typebot/services/typebot.service.ts index b18b338b..79f3180b 100644 --- a/src/api/integrations/chatbot/typebot/services/typebot.service.ts +++ b/src/api/integrations/chatbot/typebot/services/typebot.service.ts @@ -369,9 +369,33 @@ export class TypebotService extends BaseChatbotService { } if (message.type === 'file' || message.type === 'embed') { - const mediaUrl = message.content.url; + const content = message.content as { url?: string; name?: string } | undefined; + if (!content?.url) { + sendTelemetry('/message/sendMediaMissingUrl'); + return; + } + + const mediaUrl = content.url; const mediaType = this.getMediaType(mediaUrl); + let fileName = content.name; + if (!fileName) { + try { + const urlObj = new URL(mediaUrl); + const path = urlObj.pathname || ''; + const candidate = path.split('/').pop() || ''; + if (candidate && candidate.includes('.')) { + fileName = candidate; + } + } catch { + // Ignore URL parsing failures + } + + if (!fileName) { + fileName = mediaType && mediaType !== 'document' ? `media.${mediaType}` : 'attachment'; + } + } + if (mediaType === 'audio') { await instance.audioWhatsapp( { @@ -389,7 +413,7 @@ export class TypebotService extends BaseChatbotService { delay: settings?.delayMessage || 1000, mediatype: mediaType || 'document', media: mediaUrl, - fileName: message.content.name || 'document.pdf', + fileName, }, null, false,