{"product_id":"rag-facebook-messenger-bot-with-n8n-supabase-openai","title":"RAG Facebook Messenger Bot with n8n, Supabase \u0026 OpenAI","description":"\u003ch3\u003eRAG-Powered Facebook Messenger Bot for n8n: Supabase Vector Search + OpenRouter + Auto-Synced PDF Knowledge\u003c\/h3\u003e\n\u003cp\u003eTurn your PDFs into an AI-powered Facebook Messenger chatbot. This n8n workflow batches incoming Facebook messages, answers with an OpenRouter chat model using \u003cstrong\u003eRAG retrieval from a Supabase vector store\u003c\/strong\u003e, and keeps the knowledge base automatically synced from \u003cstrong\u003eGoogle Drive\u003c\/strong\u003e (adds, updates, and deletes).\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives Facebook Messenger webhooks\u003c\/strong\u003e, including the initial webhook verification challenge, and ignores messages sent by the page itself.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCaptures incoming messages\u003c\/strong\u003e by extracting sender\/page\/message text and storing each message in an n8n Data Table keyed by the sender ID.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eBatches user messages\u003c\/strong\u003e: repeatedly checks pending messages until the latest message is at least 10 seconds old, then combines them into a single prompt.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGenerates replies with RAG\u003c\/strong\u003e using an AI agent backed by an \u003cstrong\u003eOpenRouter chat model\u003c\/strong\u003e, with retrieval from the \u003cstrong\u003eSupabase Vector Store\u003c\/strong\u003e and \u003cstrong\u003ePostgres chat memory\u003c\/strong\u003e for conversation context.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSends the response\u003c\/strong\u003e back to the user via the \u003cstrong\u003eFacebook Graph API\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eKeeps the knowledge base in sync from Google Drive PDFs\u003c\/strong\u003e:\n    \u003cul\u003e\n      \u003cli\u003eOn new PDFs: downloads, extracts text, chunks content, generates embeddings, and inserts vectors into a Supabase \u003ccode\u003edocuments\u003c\/code\u003e table.\u003c\/li\u003e\n      \u003cli\u003eOn updated PDFs: deletes existing vectors matching the file name, then re-downloads, re-embeds, and re-indexes.\u003c\/li\u003e\n      \u003cli\u003eOn PDFs moved to Google Drive Trash: deletes matching vectors from Supabase.\u003c\/li\u003e\n    \u003c\/ul\u003e\n  \u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eSaaS support bot that answers questions using your policy, help docs, and product PDFs.\u003c\/li\u003e\n  \u003cli\u003eInternal knowledge assistant for teams using Messenger to access up-to-date documentation.\u003c\/li\u003e\n  \u003cli\u003eAutomation engineers building a production-style RAG pipeline with Supabase and OpenAI embeddings.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eWorkflow triggers: \u003cstrong\u003eFacebook webhook\u003c\/strong\u003e and \u003cstrong\u003eGoogle Drive (new\/updated\/trash PDFs)\u003c\/strong\u003e\n\u003c\/li\u003e\n  \u003cli\u003eCore nodes\/operators used: \u003cstrong\u003eif\u003c\/strong\u003e, \u003cstrong\u003eset\u003c\/strong\u003e, \u003cstrong\u003ecode\u003c\/strong\u003e, \u003cstrong\u003ewait\u003c\/strong\u003e, \u003cstrong\u003elimit\u003c\/strong\u003e, \u003cstrong\u003ewebhook\u003c\/strong\u003e\n\u003c\/li\u003e\n  \u003cli\u003eRAG stack: \u003cstrong\u003eOpenRouter chat model\u003c\/strong\u003e + \u003cstrong\u003eSupabase Vector Store\u003c\/strong\u003e + \u003cstrong\u003ePostgres chat memory\u003c\/strong\u003e\n\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46157932101811,"sku":"N8N-20349","price":62.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/Pe0ALLfjcqeEC2JTrZGwY_fDOlPnpM.png?v=1791018789","url":"https:\/\/buyflowscripts.com\/products\/rag-facebook-messenger-bot-with-n8n-supabase-openai","provider":"N8N Commerce","version":"1.0","type":"link"}