Skip to main content

Message Parsing & Prompt Injection Flow

Diagram

Flow Summary

WhatsApp / WebSocket
|
v
Prompt Injection (_build_agent_system_prompt)
1. Base prompt (node config)
2. Router instruction (if multi-agent)
3. Language instruction (always)
4. Tool priority (if KB + web)
5. Format instruction (text/JSON)
6. Channel-specific:
WhatsApp -> WHATSAPP_SYSTEM_PROMPT
Web -> Structured card format (if product keywords)
|
v
LLM Call -> AIMessage
|
v
Response Parsing (by channel)
WhatsApp: parse_whatsapp_message()
-> strip images -> format links -> normalize lists -> clean markdown
-> send plain text

WebSocket: parse_markdown_to_content_blocks()
-> detect numbered items -> product card check
-> text blocks + card carousel blocks
-> send JSON