{ "name": "MYMessenger", "nodes": [ { "parameters": { "multipleMethods": true, "path": "fbd43343-0ab6-4bbd-b98c-915f691cc0e5", "responseMode": "responseNode", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ 224, 64 ], "id": "0f46ba68-c8d5-42e5-866a-72a25a35bb11", "name": "Webhook", "webhookId": "fbd43343-0ab6-4bbd-b98c-915f691cc0e5" }, { "parameters": { "promptType": "define", "text": "={{ $json.body.entry[0].messaging[0].message.text }}", "options": { "systemMessage": "=You are a helpful & Bilingual teacher.\n\nYour task is to help users with their homehowk and their researches.\n\n## Use the browser to fetch answers.\n\nAnswer their questions according the user's Language.\n\n !!if the user asks you in English -> you answer in English. \n !!if the user asks you in French -> you answer in French.\n !!if the user asks you in Arabic -> you answer in Arabic.\n\n When responding, return ONLY a plain text string.\n- Do NOT include Markdown, bullet points, or code formatting.\n- Trim unnecessary spaces and line breaks.\n\n\n## Analyze the user's input and respond with **clean, minimal, valid JSON** — no explanations, no extra text, no markdown formatting.\n\n---\n\n### 🎯 Output rules\n\n* Always output **ONLY valid JSON** that can be parsed without errors.\n* Never include any text outside the JSON object.\n* Use this format exactly:\n\n{\n\"text\": \"\"\n}\n\n---\n\n### 🧹 Cleaning and formatting guidelines\n\n* No markdown (`**`, `*`, ````, `>`, `#`, etc.)\n* No newlines at the start or end.\n* Replace multiple spaces or line breaks with a single space where possible.\n* If you include lists or examples, make them readable inline (use commas or semicolons).\n* Never include special characters that break JSON (like unescaped quotes).\n\n---\n\n### 🌍 Language behavior\n\n* Detect the user’s language automatically.\n* If the user writes in English → answer in English.\n* If in French → answer in French.\n* If in Arabic → answer in Arabic.\n* Never mix languages in one reply.\n\n---\n\n### ✅ Example\n\nUser: \"Explain verb and noun\"\n\nAI Output:\n{\n\"text\": \"A verb expresses an action or state, while a noun names a person, place, or thing.\"\n}\n\n\n" } }, "type": "@n8n/n8n-nodes-langchain.agent", "typeVersion": 2.2, "position": [ 448, 208 ], "id": "51dd5157-90d5-42b4-916f-ec942fc7c0cd", "name": "AI Agent" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 }, "conditions": [ { "id": "206c5741-97a5-43f6-b0d1-807bb5016e29", "leftValue": "={{ $json.query['hub.mode'] }}", "rightValue": "=subscribe", "operator": { "type": "string", "operation": "equals", "name": "filter.operator.equals" } }, { "id": "96da5228-41da-4556-83b8-35a61e93bd1d", "leftValue": "={{ $json.query['hub.verify_token'] }}", "rightValue": "mymessengertoken", "operator": { "type": "string", "operation": "equals", "name": "filter.operator.equals" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 512, -96 ], "id": "ecf1a7d0-32c0-4cc0-b98f-eacd37d43608", "name": "If" }, { "parameters": { "respondWith": "text", "responseBody": "={{ $json.query['hub.challenge'] }}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [ 800, -96 ], "id": "72a21126-b7d1-4708-b007-b65cf8493a33", "name": "Respond to Webhook" }, { "parameters": { "model": { "__rl": true, "mode": "list", "value": "gpt-4.1-mini" }, "options": {} }, "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "typeVersion": 1.2, "position": [ 464, 432 ], "id": "96281b6a-5b01-4ae0-bcc4-404111254669", "name": "OpenAI Chat Model", "credentials": { "openAiApi": { "id": "LnnCTAz62BNEa3FH", "name": "OpenAi account 3" } } }, { "parameters": { "sessionIdType": "customKey", "sessionKey": "={{ $json.body.entry[0].messaging[0].sender.id }}" }, "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow", "typeVersion": 1.3, "position": [ 592, 432 ], "id": "451b89bd-1d03-4972-8972-17578d363649", "name": "Simple Memory" }, { "parameters": { "jsCode": "let raw = $json.output;\n\n// If the model wrapped the JSON in quotes, parse it safely\nif (typeof raw === \"string\") {\n try {\n raw = JSON.parse(raw);\n } catch (e) {\n // If it fails, just clean it up manually\n raw = { text: raw.replace(/(\\n|\")/g, '').trim() };\n }\n}\n\nreturn [{ json: raw }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 800, 208 ], "id": "d8f8dd7d-23b6-4335-a23c-efcd9c783867", "name": "Code in JavaScript" }, { "parameters": { "method": "POST", "url": "=https://graph.facebook.com/v23.0/{{ $('Webhook').item.json.body.entry[0].messaging[0].recipient.id }}/messages", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "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.text }}\"\n }\n}\n", "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1024, 208 ], "id": "96e94a30-b75b-4af9-ab25-1fbc0f52fa3b", "name": "HTTP Request", "credentials": { "httpHeaderAuth": { "id": "xBzDZHQnQKyjsDvL", "name": "Header Auth account" } } } ], "pinData": {}, "connections": { "Webhook": { "main": [ [ { "node": "If", "type": "main", "index": 0 } ], [ { "node": "AI Agent", "type": "main", "index": 0 } ] ] }, "AI Agent": { "main": [ [ { "node": "Code in JavaScript", "type": "main", "index": 0 } ] ] }, "If": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent", "type": "ai_languageModel", "index": 0 } ] ] }, "Simple Memory": { "ai_memory": [ [ { "node": "AI Agent", "type": "ai_memory", "index": 0 } ] ] }, "Code in JavaScript": { "main": [ [ { "node": "HTTP Request", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "97a5f648-7910-43a7-9215-eed4bb0a6293", "meta": { "templateCredsSetupCompleted": true, "instanceId": "23830929e6c018b604abb710d12ca57ce411c63a552f9a21234ab1d153211b0b" }, "id": "RbgFx58SiHJG242y", "tags": [] }