AutomationFlowsAI & RAG › Classify and Respond to Facebook Messenger Inquiries with Gpt-4, Slack and…

Classify and Respond to Facebook Messenger Inquiries with Gpt-4, Slack and…

Original n8n title: Classify and Respond to Facebook Messenger Inquiries with Gpt-4, Slack and Sheets

ByRahul Joshi @rahul08 on n8n.io

Streamline Facebook Messenger inbox management with an AI-powered categorization and response system. 💬⚙️ This workflow automatically classifies new messages as Lead, Query, or Spam using GPT-4, routes them for approval via Slack, responds on Facebook once approved, and logs all…

Event trigger★★★★☆ complexityAI-powered29 nodesError TriggerSlackFacebook Graph ApiOpenAI ChatAgentOutput Parser StructuredMemory Buffer WindowGoogle Sheets
AI & RAG Trigger: Event Nodes: 29 Complexity: ★★★★☆ AI nodes: yes Added:
Classify and Respond to Facebook Messenger Inquiries with Gpt-4, Slack and… — n8n workflow card showing Error Trigger, Slack, Facebook Graph Api integration

This workflow corresponds to n8n.io template #10557 — we link there as the canonical source.

This workflow follows the Agent → Error Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "z6unWs848KTz4kx7",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Classify and Respond to Facebook Messenger Inquiries with GPT-4, Slack, and Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "e2f901e3-aa5a-4932-9319-18311a766d20",
      "name": "Error Handler Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -144,
        928
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3d6db20c-c4f2-468d-a3fc-2bb5b56fc754",
      "name": "Slack: Send Error Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        64,
        928
      ],
      "parameters": {
        "text": "=\u274c *Error in API Error Catalog Workflow* *Node:* {{ $json.node.name }} *Message:* {{ $json.error.message }} *Time:* {{ $json.timestamp }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "7c62e0bc-3101-4c78-ae04-820b5db755a6",
      "name": "Workflow Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -848
      ],
      "parameters": {
        "width": 485,
        "height": 624,
        "content": "## \ud83d\udccb Classify and Respond to Facebook Messenger Inquiries\n\n### How it works\nThis automation helps you handle Facebook Page messages automatically with GPT-4.  \nEvery hour it checks for new messages, extracts the sender\u2019s details, and sends the content to GPT-4 for classification.  \nMessages are categorized as Lead, Query, or Spam.  \nLeads and Queries trigger a Slack approval request where your team can approve or reject GPT-4\u2019s suggested reply.  \nBased on that response, the workflow sends an approved or fallback message through Facebook Messenger, logs all activity to Google Sheets, and alerts you of any errors in Slack.\n\n### Setup steps\n1. Connect Facebook Graph API, OpenAI, Slack, and Google Sheets credentials.  \n2. Set up environment variables: `FACEBOOK_PAGE_ID`, `GOOGLE_SHEET_ID`, `SLACK_CHANNEL_ID`.  \n3. Create a Google Sheet with columns for Timestamp, Sender, Category, Summary, AI Reply, and Status.  \n4. Adjust the trigger interval if you want faster or slower checks.  \n5. Test with one sample message before enabling the full workflow.  \n6. Enable error notifications so you\u2019re informed if anything breaks.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "89e6bbac-09b9-409a-bda7-a557861e1204",
      "name": "Data Input Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 692,
        "height": 482,
        "content": "## Data Input & Formatting \n\nRuns every hour to fetch the latest Facebook Page messages.  \nExtracts message text, sender info, and timestamp, then formats the data for GPT-4 classification.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f152b261-07cd-455d-82c0-6a8fba802c70",
      "name": "AI Processing Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        -208
      ],
      "parameters": {
        "color": 2,
        "width": 438,
        "height": 715,
        "content": "## AI Classification \n\n\nSends the formatted message to GPT-4 for analysis.  \nGPT-4 categorizes it as Lead, Query, or Spam, generates a summary, and drafts a suggested reply with confidence scoring.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ccddf517-2c95-4675-b29d-1320c6ad0532",
      "name": "Routing & Approval Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -496
      ],
      "parameters": {
        "color": 2,
        "width": 454,
        "height": 991,
        "content": "## Routing & Approvals \n\nRoutes messages based on category.  \nLeads and Queries trigger a Slack approval message so your team can approve or reject GPT-4\u2019s reply before sending.  \nSpam is logged automatically without further action.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e0796be2-abeb-43c5-82be-0efa96013b7c",
      "name": "Response & Logging Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1536,
        -544
      ],
      "parameters": {
        "color": 2,
        "width": 662,
        "height": 938,
        "content": "## Responses & Logging \n\nSends approved or fallback replies to users on Messenger.  \nAll responses, summaries, and approval outcomes are recorded in Google Sheets for tracking and analytics.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "21692871-2720-47f0-8224-0fe78c97cbf2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -208,
        672
      ],
      "parameters": {
        "color": 2,
        "width": 480,
        "height": 464,
        "content": "## Error Notifications \n\n\nIf any part of the workflow fails, this section sends a Slack alert with the error message, node name, and timestamp so you can fix it quickly.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ba3b8ef4-3836-4630-9ec7-a838bebfe684",
      "name": "Trigger \u2013 Fetch New Facebook Messages (Every Hour)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -64,
        128
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e76437d4-2bba-4436-a660-bc137c5e2c81",
      "name": "Format Incoming Message Data",
      "type": "n8n-nodes-base.set",
      "position": [
        416,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f1219ab7-44b3-4269-9bdf-d6495508f3f7",
              "name": "Message",
              "type": "string",
              "value": "={{ $json.data[0].messages.data[0].message }}"
            },
            {
              "id": "2c8d7090-f294-422c-ad52-7ef565f0962a",
              "name": "Senders Name",
              "type": "string",
              "value": "={{ $json.data[0].messages.data[0].from.name }}"
            },
            {
              "id": "3a2285d0-da92-4dfe-8e9a-c7b7b4af790a",
              "name": "Sender Email",
              "type": "string",
              "value": "={{ $json.data[0].messages.data[0].from.email }}"
            },
            {
              "id": "e098cf90-95b6-4efd-a18a-74a1e8a9e4bf",
              "name": "Created Time",
              "type": "string",
              "value": "={{ $json.data[0].messages.data[0].created_time }}"
            },
            {
              "id": "05c62c36-3baa-4553-ab88-0ac77097a442",
              "name": "Senders ID",
              "type": "string",
              "value": "={{ $json.data[0].messages.data[0].from.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c7bda562-5ccd-431f-b59f-f0e1ea42e724",
      "name": "Fetch Facebook Conversations (Graph API)",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        192,
        128
      ],
      "parameters": {
        "edge": "conversations",
        "options": {
          "fields": {
            "field": [
              {
                "name": "messages{message,from,to,created_time}"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "access_token",
                "value": "="
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b6c407c7-5728-4a60-b21e-f8ee9bd3a60a",
      "name": "Model \u2013 GPT-4 Language Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        640,
        352
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "options": {
          "temperature": 0.3
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0f74cfa6-2dc6-4696-bb13-36623f4a8cae",
      "name": "AI \u2013 Classify Message (Lead / Query / Spam)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        704,
        128
      ],
      "parameters": {
        "text": "=You received a new message on Facebook Page.\n\nMessage: \"{{ $json[\"Message\"] }}\"\nSender Name: \"{{ $json[\"Senders Name\"] }}\"\nSender Email: \"{{ $json[\"Sender Email\"] }}\"\nCreated Time: \"{{ $json[\"Created Time\"] }}\"\n\nClassify this message according to the defined categories and provide a short suggested reply if needed.\n",
        "options": {
          "systemMessage": "=You are an AI assistant that analyzes incoming Facebook Page messages and classifies them into one of three categories: Lead, Query, or Spam.\n\nDefinitions:\n- Lead: A potential customer or business opportunity showing intent to purchase, collaborate, or request a quote.\n- Query: A general question, support request, or informational inquiry that doesn\u2019t indicate a sales intent.\n- Spam: Any irrelevant, promotional, scam-like, or inappropriate message.\n\nFor each input message, you must:\n1. Identify the category.\n2. Summarize the message meaning briefly.\n3. Suggest an appropriate automated reply if applicable.\n\nReturn your answer strictly as a JSON object matching the defined schema.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "e6ce995d-5181-4c2c-b587-15dd7294d279",
      "name": "Parse AI Output (JSON Parser)",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        896,
        352
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"category\": \"Lead\",\n  \"summary\": \"The user is interested in discussing a project collaboration.\",\n  \"suggested_reply\": \"Thanks for reaching out! I\u2019d be happy to discuss your project. Could you please share more details or your preferred contact method?\",\n  \"confidence_score\": 0.92\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f629f045-44aa-4cc3-a20a-4965b6ababb4",
      "name": "Memory \u2013 Conversation Context Buffer",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        768,
        352
      ],
      "parameters": {
        "sessionKey": "=\"Message Categorization\"",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "66651a42-9f47-426e-8ebf-a2549fcea1ca",
      "name": "Route Messages by Category",
      "type": "n8n-nodes-base.switch",
      "position": [
        1104,
        112
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c6291a4b-54a6-432f-8703-513bd802891b",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Lead"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "5aa04688-17b2-4c74-a808-8f514a0efdf9",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Query"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4e7842c6-8a80-46ba-b2e2-8d6cfd9d1aa8",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.category }}",
                    "rightValue": "Spam"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "c415da31-10ef-4047-947c-090343d7bf1e",
      "name": "Slack Approval \u2013 Lead Message",
      "type": "n8n-nodes-base.slack",
      "position": [
        1328,
        -256
      ],
      "parameters": {
        "select": "channel",
        "message": "=\ud83c\udfaf *New Lead Detected!*\n\n*Summary:* {{ $json.output.summary }}\n*Confidence:* {{ $json.output.confidence_score }}\n\n\ud83d\udcdd *Suggested Response:*\n{{ $json.output.suggested_reply }}\n\n\ud83d\udcbc _Follow up required for conversion_",
        "options": {},
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "operation": "sendAndWait",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "d054bc66-22e1-47c7-b991-344183ee1581",
      "name": "Check Lead Approval Status",
      "type": "n8n-nodes-base.switch",
      "position": [
        1552,
        -256
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6e0c8eba-353f-49a1-b6fb-e8ebf7cefb67",
                    "operator": {
                      "type": "boolean",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.approved }}",
                    "rightValue": true
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a76ce745-1e69-4ebe-b9db-c99d89ef49bd",
                    "operator": {
                      "type": "boolean",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.approved }}",
                    "rightValue": false
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "ec81ca69-1395-4b32-93e1-31a558d4674a",
      "name": "Send AI Reply \u2013 Lead Approved",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        1776,
        -352
      ],
      "parameters": {
        "edge": "messages",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "access_token",
                "value": "="
              },
              {
                "name": "recipient",
                "value": "={{ JSON.stringify({ id: $('Format Incoming Message Data').item.json[\"Senders ID\"] }) }}"
              },
              {
                "name": "message",
                "value": "={{ JSON.stringify({ text: $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }) }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "35b5dd45-19ef-4a79-b108-6f9f6f56a1dd",
      "name": "Send Fallback Reply \u2013 Lead Rejected",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        1776,
        -160
      ],
      "parameters": {
        "edge": "messages",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "access_token",
                "value": "="
              },
              {
                "name": "recipient",
                "value": "={{ JSON.stringify({ id: $('Format Incoming Message Data').item.json[\"Senders ID\"] }) }}"
              },
              {
                "name": "message",
                "value": "={{ JSON.stringify({ text: \"Thank you for your interest! \ud83d\ude4f\\\\n\\\\nWe\\\\'re excited to help you. One of our team members will reach out to you shortly with personalized information.\\\\n\\\\nIn the meantime, feel free to share any specific questions you have, and we\\\\'ll make sure to address them!\\\\n\\\\nLooking forward to connecting with you!\" }) }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ad6d7b3-4a55-4fdd-ab22-1dc109fd4680",
      "name": "Log to Google Sheets \u2013 Lead Approved",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2000,
        -352
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Approved",
            "Summary": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.summary }}",
            "AI Reply": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }}",
            "Category": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.category }}",
            "Sender ID": "={{ $('Format Incoming Message Data').item.json[\"Senders ID\"] }}",
            "Timestamp": "={{ $('Format Incoming Message Data').item.json[\"Created Time\"] }}",
            "Sender Name": "={{ $('Format Incoming Message Data').item.json[\"Senders Name\"] }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Reply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI Reply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "bbfbcb8d-3710-4134-a194-fb2ee42edf18",
      "name": "Log to Google Sheets \u2013 Lead Rejected",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2000,
        -160
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Pending",
            "Summary": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.summary }}",
            "AI Reply": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }}",
            "Category": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.category }}",
            "Sender ID": "={{ $('Format Incoming Message Data').item.json[\"Senders ID\"] }}",
            "Timestamp": "={{ $('Format Incoming Message Data').item.json[\"Created Time\"] }}",
            "Sender Name": "={{ $('Format Incoming Message Data').item.json[\"Senders Name\"] }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Reply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI Reply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "cde4b565-bcee-43da-9284-14ca66ff914a",
      "name": "Slack Approval \u2013 Query Message",
      "type": "n8n-nodes-base.slack",
      "position": [
        1328,
        128
      ],
      "parameters": {
        "select": "channel",
        "message": "=\ud83d\udd14 *New Customer Query*\n\n*Summary:* {{ $json.output.summary }}\n*Confidence:* {{ $json.output.confidence_score }}\n\n\ud83d\udcdd *Suggested Reply:*\n{{ $json.output.suggested_reply }}\n\n\u23f0 _Requires immediate response_",
        "options": {},
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "operation": "sendAndWait",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "ea4c37f5-59ac-4035-9305-070566bf139e",
      "name": "Check Query Approval Status",
      "type": "n8n-nodes-base.switch",
      "position": [
        1552,
        128
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6e0c8eba-353f-49a1-b6fb-e8ebf7cefb67",
                    "operator": {
                      "type": "boolean",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.approved }}",
                    "rightValue": true
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a76ce745-1e69-4ebe-b9db-c99d89ef49bd",
                    "operator": {
                      "type": "boolean",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.approved }}",
                    "rightValue": false
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "94b98665-d925-4cdb-80b1-556095bf2505",
      "name": "Send AI Reply \u2013 Query Approved",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        1776,
        32
      ],
      "parameters": {
        "edge": "messages",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "access_token",
                "value": "="
              },
              {
                "name": "recipient",
                "value": "={{ JSON.stringify({ id: $('Format Incoming Message Data').item.json[\"Senders ID\"] }) }}"
              },
              {
                "name": "message",
                "value": "={{ JSON.stringify({ text: $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }) }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e707ddb9-b8d7-4aa6-87d1-039f65d55ce8",
      "name": "Send Fallback Reply \u2013 Query Rejected",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        1776,
        224
      ],
      "parameters": {
        "edge": "messages",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "access_token",
                "value": "="
              },
              {
                "name": "recipient",
                "value": "={{ JSON.stringify({ id: $('Format Incoming Message Data').item.json[\"Senders ID\"] }) }}"
              },
              {
                "name": "message",
                "value": "={{ JSON.stringify({ text: \"Thank you for reaching out! \ud83d\ude4f\\n\\nWe've received your question and our team is looking into it. We'll get back to you with a detailed answer as soon as possible.\\n\\nYour patience is appreciated! If you have any additional information to share, feel free to send it our way.\" }) }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "66ff77a0-23b7-44df-95dc-a509a884717a",
      "name": "Log to Google Sheets \u2013 Query Approved",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2000,
        32
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Approved",
            "Summary": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.summary }}",
            "AI Reply": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }}",
            "Category": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.category }}",
            "Sender ID": "={{ $('Format Incoming Message Data').item.json[\"Senders ID\"] }}",
            "Timestamp": "={{ $('Format Incoming Message Data').item.json[\"Created Time\"] }}",
            "Sender Name": "={{ $('Format Incoming Message Data').item.json[\"Senders Name\"] }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Reply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI Reply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d1345c3f-04bc-47b4-8d4d-baf122453043",
      "name": "Log to Google Sheets \u2013 Query Rejected",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2000,
        224
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Pending",
            "Summary": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.summary }}",
            "AI Reply": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }}",
            "Category": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.category }}",
            "Sender ID": "={{ $('Format Incoming Message Data').item.json[\"Senders ID\"] }}",
            "Timestamp": "={{ $('Format Incoming Message Data').item.json[\"Created Time\"] }}",
            "Sender Name": "={{ $('Format Incoming Message Data').item.json[\"Senders Name\"] }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Reply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI Reply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "ba6e9cba-f2a7-444d-8cfb-a7b9ff4dffc6",
      "name": "Log to Google Sheets \u2013 Spam Messages",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1328,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Spam",
            "Summary": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.summary }}",
            "AI Reply": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.suggested_reply }}",
            "Category": "={{ $('AI \u2013 Classify Message (Lead / Query / Spam)').item.json.output.category }}",
            "Sender ID": "={{ $('Format Incoming Message Data').item.json[\"Senders ID\"] }}",
            "Timestamp": "={{ $('Format Incoming Message Data').item.json[\"Created Time\"] }}",
            "Sender Name": "={{ $('Format Incoming Message Data').item.json[\"Senders Name\"] }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Reply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI Reply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "24e3f2f7-f1c9-4e6e-a2ba-19c7861faec7",
  "connections": {
    "Error Handler Trigger": {
      "main": [
        [
          {
            "node": "Slack: Send Error Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Lead Approval Status": {
      "main": [
        [
          {
            "node": "Send AI Reply \u2013 Lead Approved",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Fallback Reply \u2013 Lead Rejected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Messages by Category": {
      "main": [
        [
          {
            "node": "Slack Approval \u2013 Lead Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack Approval \u2013 Query Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log to Google Sheets \u2013 Spam Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Query Approval Status": {
      "main": [
        [
          {
            "node": "Send AI Reply \u2013 Query Approved",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Fallback Reply \u2013 Query Rejected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Incoming Message Data": {
      "main": [
        [
          {
            "node": "AI \u2013 Classify Message (Lead / Query / Spam)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Output (JSON Parser)": {
      "ai_outputParser": [
        [
          {
            "node": "AI \u2013 Classify Message (Lead / Query / Spam)",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Model \u2013 GPT-4 Language Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI \u2013 Classify Message (Lead / Query / Spam)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Send AI Reply \u2013 Lead Approved": {
      "main": [
        [
          {
            "node": "Log to Google Sheets \u2013 Lead Approved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Approval \u2013 Lead Message": {
      "main": [
        [
          {
            "node": "Check Lead Approval Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send AI Reply \u2013 Query Approved": {
      "main": [
        [
          {
            "node": "Log to Google Sheets \u2013 Query Approved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Approval \u2013 Query Message": {
      "main": [
        [
          {
            "node": "Check Query Approval Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Fallback Reply \u2013 Lead Rejected": {
      "main": [
        [
          {
            "node": "Log to Google Sheets \u2013 Lead Rejected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Memory \u2013 Conversation Context Buffer": {
      "ai_memory": [
        [
          {
            "node": "AI \u2013 Classify Message (Lead / Query / Spam)",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Send Fallback Reply \u2013 Query Rejected": {
      "main": [
        [
          {
            "node": "Log to Google Sheets \u2013 Query Rejected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Facebook Conversations (Graph API)": {
      "main": [
        [
          {
            "node": "Format Incoming Message Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI \u2013 Classify Message (Lead / Query / Spam)": {
      "main": [
        [
          {
            "node": "Route Messages by Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger \u2013 Fetch New Facebook Messages (Every Hour)": {
      "main": [
        [
          {
            "node": "Fetch Facebook Conversations (Graph API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Streamline Facebook Messenger inbox management with an AI-powered categorization and response system. 💬⚙️ This workflow automatically classifies new messages as Lead, Query, or Spam using GPT-4, routes them for approval via Slack, responds on Facebook once approved, and logs all…

Source: https://n8n.io/workflows/10557/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Streamline customer support with a real-time, AI-powered answer engine that detects incoming support emails, classifies intent, identifies the customer’s GEO region, and generates a tailored reply rea

Slack, Gmail Trigger, OpenAI Chat +5
AI & RAG

Automatically detect, classify, and document GitHub API errors using AI. This workflow connects GitHub, OpenAI (GPT-4o), Airtable, Notion, and Slack to build a real-time, searchable API error knowledg

Github Trigger, Agent, OpenAI Chat +6
AI & RAG

Streamline your HR recruitment process with this intelligent automation that reads candidate emails and resumes, analyzes them using GPT-4, and automatically shortlists or rejects applicants based on

Gmail, Gmail Trigger, HTTP Request +7
AI & RAG

📘 Description This workflow automates keyword-level SEO research and content opportunity discovery using live Google SERP data and AI-driven analysis. It takes a single keyword request, pulls real-tim

OpenAI Chat, Output Parser Structured, Error Trigger +5
AI & RAG

Consultants, agencies, freelancers, and project managers who want to ensure proposals, emails, and tasks are followed up on time.

Google Sheets Trigger, Agent, OpenAI Chat +6