Create an Intelligent Facebook Messenger Chatbot with GPT-4o-mini & Message Memory

Go to Workflow
0 views
Built by Tristan V Tristan V
Created on June 07, 2026

Description

Who is this for?

Businesses and developers who want to automate customer support or engagement on Facebook Messenger using AI-powered responses.

What does it do?

Creates an intelligent Facebook Messenger chatbot that:
Responds to messages using OpenAI (gpt-4o-mini)
Batches rapid-fire messages into a single AI request
Maintains conversation history (50 messages per user)
Shows professional UX feedback (seen indicators, typing bubbles)

How it works

Webhook Verification - Handles Facebook's GET verification request
Message Reception - Receives incoming messages via POST webhook
Message Batching - Waits 3 seconds to collect multiple quick messages
AI Processing - Sends combined message to OpenAI with conversation context
Response Delivery - Formats and sends the AI response back to Messenger

Setup

Configure Facebook Graph API credential with your Page Access Token
Configure OpenAI API credential with your API key
Set your verify token in the "Is Token Valid?" node
Register the webhook URL in Facebook Developer Console

Key Features

Message Batching: Combines "Hey" + "Can you help" + "with my order?" into one request
Conversation Memory: Remembers context from previous messages
Echo Filtering: Prevents responding to your own messages
Response Formatting: Cleans markdown for Messenger's 2000-char limit

Nodes Used (5)

AI Agent
@n8n/n8n-nodes-langchain.agent
Code
n8n-nodes-base.code
HTTP Request
n8n-nodes-base.httpRequest
OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi
Simple Memory
@n8n/n8n-nodes-langchain.memoryBufferWindow