Facebook Messenger AI customer service chatbot with Google Gemini + conversation memory - free template

Sharing a workflow I built for handling Facebook Messenger customer service with an AI backend. Posting here in case it helps others who are trying to set up Messenger bots on n8n.

Template: Build a Facebook Messenger customer service AI chatbot with Google Gemini | n8n workflow template


How it works

The flow has three stages:

  1. Webhook & validation - Receives both GET (verification handshake) and POST (messages) from Facebook. Filters out non-text events and blocks echo messages (the bot’s own replies coming back through the webhook - this trips up a lot of people).

  2. AI processing - Extracts user_id, page_id, message text and token via Set Context. Sends “seen” + “typing” indicators immediately so users get feedback. Runs the message through Gemini Flash with a 10-message memory window per user.

  3. Format & send - Strips markdown from the response (Messenger doesn’t render it), truncates at 1900 chars, sends via Graph API.


A few things I learned the hard way

  • Echo filtering is essential. Facebook sends your bot’s own messages back to your webhook. Without filtering sender ID vs page ID, you get infinite loops.
  • Simple Memory doesn’t persist in queue mode. Works fine for testing. For stable production you need Redis or Postgres-backed sessions.
  • Gemini Flash is fast enough. With a tight system prompt, response times stay under 2 seconds - feels natural in Messenger.
  • Token management is a separate problem. I built a dedicated workflow for long-lived page token refresh: Get long-lived Facebook Page access tokens and subscribe Messenger webhook fields via Graph API | n8n workflow template

What this template doesn’t cover (upgrade paths)

Happy to answer questions about setup or any issues you’ve run into with the Facebook Graph API on n8n.

did you test echo filtering with concurrent webhooks? we had some issues on high-volume bots where the filter timing wasnt quite right.

1 Like

This workflow is really just a learning playground, since it’s built with Simple Memory. But if your n8n is already on v1.113 or higher, you’re in luck, you can grab a similar workflow called “Auto‑reply to Instagram DMs with an AI chatbot and Google Gemini history” from my official library. And the best part? It’s totally free right here: nguyenthieutoan | n8n Creator .

That one is battle‑tested to handle hundreds of users at the same time, because each person gets their own unique ID and the conversation history is neatly stored in a data table.

And if you want to level up, I also offer premium versions for just a bit over $10, packed with extra goodies like:

  • Handling interrupted messages smoothly

  • Automatically pausing when an admin jumps in

So you can start with the free template for fun and experiments, and upgrade later if you want more professional features.