fb-orin-test

    Facebook Messenger AI Chatbot with OpenAI integration. Handles webhook verification (GET) and incoming messages (POST). Includes working solutions for: - Facebook webhook verification fix (hub.challenge response) - JSON.stringify() fix for AI output to prevent JSON errors - AI Agent with conversation memory using sender ID - Automatic replies via Facebook Graph API Based on tutorial but with fixes for current n8n version. See documentation: https://github.com/0mnisciux/marvins-way/blob/main/N8N_SETUP_AND_OPTIMIZATION.md

    Shared 11/14/2025

    5 views

    Visual Workflow

    JSON Code

    {
      "id": "6nAGgbnei7lSTigd",
      "meta": {
        "instanceId": "811c451e6784b5474c234a913a85a5c508c6433350f40a0970b7d54dffed679a",
        "templateCredsSetupCompleted": true
      },
      "name": "fb-orin-test",
      "tags": [],
      "nodes": [
        {
          "id": "450ed343-a54d-43ac-9eb5-8cfb19c54270",
          "name": "Webhook",
          "type": "n8n-nodes-base.webhook",
          "position": [
            -80,
            -64
          ],
          "webhookId": "3e369b98-dc87-46f7-9602-d45d5859827c",
          "parameters": {
            "path": "3e369b98-dc87-46f7-9602-d45d5859827c",
            "options": {},
            "responseMode": "responseNode",
            "multipleMethods": true
          },
          "typeVersion": 2.1
        },
        {
          "id": "a633a52a-ed6a-4397-abf2-1ae3e0d9c211",
          "name": "Respond to Webhook",
          "type": "n8n-nodes-base.respondToWebhook",
          "position": [
            416,
            -272
          ],
          "parameters": {
            "options": {},
            "respondWith": "text",
            "responseBody": "={{ $('Webhook').item.json.query['hub.challenge'] }}"
          },
          "typeVersion": 1.4
        },
        {
          "id": "f560b0c6-cde3-4622-8842-cb4af951b95c",
          "name": "If",
          "type": "n8n-nodes-base.if",
          "position": [
            192,
            -256
          ],
          "parameters": {
            "options": {},
            "conditions": {
              "options": {
                "version": 2,
                "leftValue": "",
                "caseSensitive": true,
                "typeValidation": "strict"
              },
              "combinator": "and",
              "conditions": [
                {
                  "id": "dea676c1-126b-4e48-82ce-ee173b3c01bb",
                  "operator": {
                    "name": "filter.operator.equals",
                    "type": "string",
                    "operation": "equals"
                  },
                  "leftValue": "={{ $json.query['hub.mode'] }}",
                  "rightValue": " subscribe"
                },
                {
                  "id": "e154b756-a971-45a5-bdc4-ede600851bf8",
                  "operator": {
                    "name": "filter.operator.equals",
                    "type": "string",
                    "operation": "equals"
                  },
                  "leftValue": "={{ $json.query['hub.verify_token'] }}",
                  "rightValue": "orin-fb"
                }
              ]
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "1e631c43-dd8c-4eb9-8dc0-efa4c974607d",
          "name": "AI Agent",
          "type": "@n8n/n8n-nodes-langchain.agent",
          "position": [
            176,
            -48
          ],
          "parameters": {
            "text": "={{ $json.body.entry[0].messaging[0].message.text }}",
            "options": {
              "systemMessage": "You are a helpful assistant"
            },
            "promptType": "=define"
          },
          "typeVersion": 3
        },
        {
          "id": "f0adf683-d090-424a-8066-f472bfaceb7a",
          "name": "OpenAI Chat Model",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
          "position": [
            32,
            112
          ],
          "parameters": {
            "model": {
              "__rl": true,
              "mode": "list",
              "value": "gpt-5-nano",
              "cachedResultName": "gpt-5-nano"
            },
            "options": {},
            "builtInTools": {}
          },
          "credentials": {
            "openAiApi": {
              "id": "JMMzAzQLKwRx4bjK",
              "name": "OpenAi account"
            }
          },
          "typeVersion": 1.3
        },
        {
          "id": "b0d2d741-6453-4aa4-9231-f997c0956354",
          "name": "Simple Memory",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            176,
            112
          ],
          "parameters": {
            "sessionKey": "={{ $json.body.entry[0].messaging[0].sender.id }}",
            "sessionIdType": "customKey",
            "contextWindowLength": 999
          },
          "typeVersion": 1.3
        },
        {
          "id": "c40abe4b-7189-4db0-a661-37511abb4c56",
          "name": "HTTP Request",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            512,
            -48
          ],
          "parameters": {
            "url": "=https://graph.facebook.com/v24.0/{{ $('Webhook').item.json.body.entry[0].messaging[0].recipient.id }}/messages?",
            "method": "POST",
            "options": {},
            "jsonBody": "={\n  \"recipient\": {\n    \"id\": \"{{ $('Webhook').item.json.body.entry[0].messaging[0].sender.id }}\"\n  },\n  \"messaging_type\": \"RESPONSE\",\n  \"message\": {\n    \"text\": {{ JSON.stringify($json.output) }}\n  }\n}",
            "sendBody": true,
            "sendQuery": true,
            "specifyBody": "json",
            "queryParameters": {
              "parameters": [
                {
                  "name": "access_token",
                  "value": "EAAmui7YEpMoBPwxqjH8otADLc3DZBR7UcM9LPidkmGfqZA0fk85hTvRyKAig4tcGLfqlbut4c2ZCMerdl740ipxLqPyj18ahbXEtb6xDGpbz4883CIr5eMDFdiIqLIAlgCvlqaQpv74DcTVTuAsAC0UZB31E258fhLklYK3ug9BWyATnKpwt8xzpTzZBM31ZClsCbu9OTKogQZAE4OWbaidrEEZD"
                }
              ]
            }
          },
          "typeVersion": 4.3
        }
      ],
      "active": true,
      "pinData": {},
      "settings": {
        "executionOrder": "v1"
      },
      "versionId": "ad1fa09c-257f-4eb3-b337-4e25a625314a",
      "connections": {
        "If": {
          "main": [
            [
              {
                "node": "Respond to Webhook",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Webhook": {
          "main": [
            [
              {
                "node": "If",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "AI Agent",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "AI Agent": {
          "main": [
            [
              {
                "node": "HTTP Request",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory": {
          "ai_memory": [
            [
              {
                "node": "AI Agent",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "OpenAI Chat Model": {
          "ai_languageModel": [
            [
              {
                "node": "AI Agent",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        }
      }
    }