sequenceDiagram
actor TypebotFlow
participant TypebotService
participant WhatsAppInstance
participant WhatsAppServer
TypebotFlow ->> TypebotService: Emit outgoing message
TypebotService ->> TypebotService: Inspect message.type
alt message.type is file or embed
TypebotService ->> TypebotService: Extract content.url and content.name
TypebotService ->> TypebotService: mediaType = getMediaType(mediaUrl)
TypebotService ->> TypebotService: Derive fileName if missing
alt mediaType is audio
TypebotService ->> WhatsAppInstance: audioWhatsapp(number, delay, encoding, audioUrl)
else other media type
TypebotService ->> WhatsAppInstance: mediaMessage(number, delay, mediatype, mediaUrl, fileName)
end
TypebotService ->> TypebotService: sendTelemetry(/message/sendMedia)
else other message types
TypebotService ->> WhatsAppInstance: Existing handling for text, image, etc.
end
WhatsAppInstance ->> WhatsAppServer: Forward WhatsApp message
WhatsAppServer -->> TypebotFlow: Message delivered to end user
Reviewer's Guide
Adds Typebot support for sending file/embed blocks as WhatsApp media/audio and introduces active URL scraping to reliably generate WhatsApp link previews, wiring the preview context into the Baileys send flow while preserving explicit linkPreview disabling.
Sequence diagram for WhatsApp active link preview generation
sequenceDiagram actor User participant ClientApp participant BaileysStartupService participant LinkPreviewJS participant WhatsAppServer User ->> ClientApp: Send text message with URL ClientApp ->> BaileysStartupService: sendMessage(sender, message, options, group) activate BaileysStartupService BaileysStartupService ->> BaileysStartupService: determine linkPreview flag alt linkPreview explicitly disabled BaileysStartupService ->> WhatsAppServer: send message without previewContext else linkPreview enabled or undefined BaileysStartupService ->> BaileysStartupService: generateLinkPreview(text) activate BaileysStartupService BaileysStartupService ->> LinkPreviewJS: getLinkPreview(url, headers) LinkPreviewJS -->> BaileysStartupService: previewData(title, description, images) BaileysStartupService ->> BaileysStartupService: build externalAdReply context deactivate BaileysStartupService BaileysStartupService ->> WhatsAppServer: send message with previewContext end WhatsAppServer -->> User: Deliver message with rich link previewSequence diagram for Typebot file and embed message handling to WhatsApp
sequenceDiagram actor TypebotFlow participant TypebotService participant WhatsAppInstance participant WhatsAppServer TypebotFlow ->> TypebotService: Emit outgoing message TypebotService ->> TypebotService: Inspect message.type alt message.type is file or embed TypebotService ->> TypebotService: Extract content.url and content.name TypebotService ->> TypebotService: mediaType = getMediaType(mediaUrl) TypebotService ->> TypebotService: Derive fileName if missing alt mediaType is audio TypebotService ->> WhatsAppInstance: audioWhatsapp(number, delay, encoding, audioUrl) else other media type TypebotService ->> WhatsAppInstance: mediaMessage(number, delay, mediatype, mediaUrl, fileName) end TypebotService ->> TypebotService: sendTelemetry(/message/sendMedia) else other message types TypebotService ->> WhatsAppInstance: Existing handling for text, image, etc. end WhatsAppInstance ->> WhatsAppServer: Forward WhatsApp message WhatsAppServer -->> TypebotFlow: Message delivered to end userUpdated class diagram for BaileysStartupService and TypebotService message handling
classDiagram class BaileysStartupService { +sendMessage(sender:string, message:any, options:any, group:any, previewContext:any) Promise~any~ -generateLinkPreview(text:string) Promise~any~ } class TypebotService { +handleTypebotMessage(instance:any, session:any, message:any, settings:any) Promise~any~ -getMediaType(mediaUrl:string) string } TypebotService --> BaileysStartupService : uses for WhatsApp delivery class LinkPreviewJS { +getLinkPreview(url:string, options:any) Promise~any~ } BaileysStartupService --> LinkPreviewJS : generates link previews usingFile-Level Changes
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.tssrc/api/integrations/chatbot/typebot/services/typebot.service.tssrc/api/integrations/channel/whatsapp/whatsapp.baileys.service.tsTips and commands
Interacting with Sourcery
@sourcery-ai reviewon the pull request.issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it.@sourcery-aianywhere in the pullrequest title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time.@sourcery-ai summaryanywhere inthe pull request body to generate a PR summary at any time exactly where you
want it. You can also comment
@sourcery-ai summaryon the pull request to(re-)generate the summary at any time.
@sourcery-ai guideon the pullrequest to (re-)generate the reviewer's guide at any time.
@sourcery-ai resolveon thepull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore.
@sourcery-ai dismisson the pullrequest to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!Customizing Your Experience
Access your dashboard to:
summary, the reviewer's guide, and others.
Getting Help
Originally posted by @sourcery-ai in #2347 (comment)