Посмотри этот джисон и исправь ошибки, сделай так, чтобы все работало, как задумано. сами промпты я дам в сл сообщении
{
"name": "My workflow 7",
"nodes": [
{
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1,
"position": [
0,
100
],
"id": "7b3d291b-e078-4216-87f2-bf0b561d4fc8",
"webhookId": "73a39cf7-3ec9-4e7a-a6f1-78a0c278a7f0",
"credentials": {
"telegramApi": {
"id": "u2tdgob4GQa8YGGu",
"name": "Olga"
}
}
},
{
"parameters": {
"functionCode": "const text = input.item.json.message.text∣∣′′;\n//Простаядетекцияязыка:есликириллица—ru,иначеen\nif(/[u0400−u04FFs]+/.test(text)) {\n return [{ detectedLang: 'ru', text }];\n} else {\n return [{ detectedLang: 'en', text }];\n}"
},
"name": "Language Detection",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
220,
100
],
"id": "6de60d58-689a-48c2-a1b0-adf05bcbdba7"
},
{
"parameters": {
"functionCode": "const text = input.item.json.text;\nconst message = text.trim().toLowerCase();\nconst commands = ['/start', '/help', '/donate', '/premium', '/subscribe'];\nif (commands.includes(message.split(' ')[0])) {\n return [{ command: message.split(' ')[0] }];\n}\nreturn [{ command: null }];"
},
"name": "Command Router",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
440,
0
],
"id": "47efb114-8df1-4190-89be-f42d7d73a77a"
},
{
"parameters": {
"sheetId": "1qErvzT0mhmFFd3uP-7QPf7Cgt4LKhHjLWcvTfz0Uv7k",
"range": "A:I",
"options": {}
},
"name": "Get User Data",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 1,
"position": [
440,
200
],
"id": "49582135-b6bb-4911-b25e-f610946e15ac",
"credentials": {
"googleApi": {
"id": "g9xNLyF3Ofb2DM0I",
"name": "Google Sheets account"
}
}
},
{
"parameters": {
"functionCode": "const nowDateStr = new Date().toISOString().slice(0,10);\n\nlet user = input.all()[0].json;\nif(!user || Object.keys(user).length ===0){\n /* Новый пользователь */\n user = {\n userId: json.message.from.id.toString(),\nchajson.message.chat.id.toString(),\n subscriptionType: '',\n messagesUsed: 0,\n messagesResetDate: nowDateStr,\n lastMessageDate: nowDateStr,\n language: input.all()[1].json.detectedLang,\n sessionContext: '[]',\n lastDonationReminder: ''\n };\n}\n\n// Сброс лимита при смене месяца\nconst resetDate = new Date(user.messagesResetDate);\nconst currentDate = new Date(nowDateStr);\nif (resetDate.getMonth() !== currentDate.getMonth() || resetDate.getFullYear() !== currentDate.getFullYear()) {\n user.messagesUsed = 0;\n user.messagesResetDate = nowDateStr;\n}\n\n// Возвращаем пользователя с обновленными данными для проверки\nreturn [user];"
},
"name": "Process User Data",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
660,
200
],
"id": "3805b225-6468-4b8f-b525-18efdef528a8"
},
{
"parameters": {
"functionCode": "const user = input.item.json;\nconst command = input.all()[0].json.command;\nconst now = new Date().toISOString().slice(0, 10);\n\nfunction canSendMessage(user){\n if(user.subscriptionType === 'premium') return true;\n if(user.subscriptionType === 'standard' && user.messagesUsed < 50) return true;\n return false;\n}\n\nif(command && command !== '/start'){\n // Разрешить команды независимо от подписки\n return [{ allow: true, user, command }];\n}\n\n// Проверка лимитов для обычного сообщения\nconst allowed = canSendMessage(user);\n\nif(!allowed){\n return [{ allow: false, user, command: null }];\n}\n\n// Все норм\nreturn [{ allow: true, user, command: null }];"
},
"name": "Subscription Check",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
660,
0
],
"id": "baf918ba-08ff-4c86-94bc-86bf9bf52b4a"
},
{
"parameters": {
"functionCode": "const input = input.item.json;\nconst user = input.user;\nconst command = input.command;\n\nif (command) {\n let text = '';\n switch(command) {\n case '/start':\n text = Привет! Я Ольга Фабо — твой помощник-пекарь по молекулярной кухне и питанию. Я могу помочь с рецептами и советами. Напиши /help для списка команд.;\n break;\n case '/help':\n text = Доступные команды:\\n/start - приветствие\\n/help - помощь\\n/donate - поддержать меня\\n/premium - узнать про премиум подписку\\n/subscribe - подписаться на планы;\n break;\n case '/donate':\n text = Если вы хотите поддержать меня, воспользуйтесь кнопкой ниже:;\n break;\n case '/premium':\n text = Премиум подписка — безлимитное общение и приоритетные ответы за $100 в месяц.;\n break;\n case '/subscribe':\n text = Стандартная подписка — 50 сообщений за $19 в месяц.;\n break;\n default:\n text = Команда не распознана.;\n }\n return [{\n text,\n inlineKeyboard: [\n [{ text: 'Подписка Стандарт', url: '{{LAVA_SUBSCRIBE}}' }],\n [{ text: 'Премиум', url: '{{LAVA_PREMIUM}}' }],\n [{ text: 'Поддержать', url: '{{LAVA_DONATE}}' }]\n ]\n }];\n}\n\nreturn [{ text: null }];"
},
"name": "Process Commands",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
880,
0
],
"id": "891c2a3c-8d9d-45ab-b792-b526be6dc606"
},
{
"parameters": {
"functionCode": "const commandResponse = input.item.json.text;\nif(commandResponse){\n return [{\n chatId: json.message.chat.id,\n text: commandResponse,\n options: {\n reply_markup: {\n inline_keyboard: input.item.json.inlineKeyboard\n }\n }\n }];\n}\nreturn [];\n"
},
"name": "Send Command Response",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1100,
0
],
"id": "aa7fa829-c935-440d-a4fd-4cc0232e37b4"
},
{
"parameters": {
"requestMethod": "POST",
"url": "https://api.openai.com/v1/chat/completions",
"options": {
"bodyContentType": "json"
}
},
"name": "OpenAI GPT",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
560,
380
],
"id": "9b9dccbc-e539-456f-994b-3c7094bda96d"
},
{
"parameters": {
"functionCode": "// Обновляем контекст с новым сообщением и ответом от GPT\nconst user = input.all()[0].json;\nconst openAIResp = input.all()[1].json;\nlet sessionContext = JSON.parse(user.sessionContext || '[]');\n\n// Добавляем user message\nsessionContext.push({role:'user', content: json.message.text});\n// Добавляем assistant ответ\nconst gptText = openAIResp.choices[0].message.content;\nsessionContext.push({role:'assistant', content: gptText});\n\n// Укорачиваем контекст до последних 10 сообщений\nif(sessionContext.length > 20) sessionContext = sessionContext.slice(sessionContext.length - 20);\n\n// Обновляем счетчик сообщений для стандартных пользователей\nif(user.subscriptionType === 'standard') {\n user.messagesUsed = (user.messagesUsed || 0) + 1;\n}\n\nuser.lastMessageDate = new Date().toISOString().slice(0, 10);\nuser.sessionContext = JSON.stringify(sessionContext);\n\nreturn [{\n user,\n response: gptText\n}];"
},
"name": "Update Context & Count",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
880,
400
],
"id": "d8a8a0fb-eff2-4c03-b1a0-fc24c6ceb311"
},
{
"parameters": {
"operation": "upsert",
"sheetId": "1qErvzT0mhmFFd3uP-7QPf7Cgt4LKhHjLWcvTfz0Uv7k",
"range": "A:I",
"options": {}
},
"name": "Update User Data in Sheets",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 1,
"position": [
1100,
400
],
"id": "2dcab695-5dd5-43ea-a394-3bc5e49210c8",
"credentials": {
"googleApi": {
"id": "g9xNLyF3Ofb2DM0I",
"name": "Google Sheets account"
}
}
},
{
"parameters": {
"functionCode": "// Обнаружение благодарностей\nconst gratitudeRegex = /(спасибо|thank you|thanks|благодарю)/i;\nconst text = json.message.text∣∣′′;\nconstuser=input.all()[0].json;\nconst now = new Date().toISOString().slice(0,10);\n\nif(gratitudeRegex.test(text)) {\n // Проверяем, чтоб не спамить больше 1 раза в сутки\n if(user.lastDonationReminder !== now) {\n return [{\n offerDonation: true,\n chatId: user.chatId\n }];\n }\n}\nreturn [{ offerDonation: false }];"
},
"name": "Gratitude Detection",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
0,
660
],
"id": "18f98bb2-a160-4dee-adb4-e11c989c6393"
},
{
"parameters": {
"functionCode": "const offerDonation = input.item.json.offerDonation;\nif(offerDonation) {\n return [{\n chatId: input.item.json.chatId,\n text: "Рада помогать! Если хотите поддержать меня, пожалуйста, воспользуйтесь кнопкой ниже:",\n options: {\n reply_markup: {\n inline_keyboard: [\n [{ text: 'Пожертвовать', url: '{{LAVA_DONATE}}' }]\n ]\n }\n }\n }];\n}\nreturn [];"
},
"name": "Build Donation Offer",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
220,
660
],
"id": "495e30b6-b638-4b71-bdec-d00ab669accd"
},
{
"parameters": {
"chatId": "={{json.chatId}}",
"text": "={{json.text}}",
"additionalFields": {
"disable_web_page_preview": true
}
},
"name": "Telegram Send Message",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1,
"position": [
1320,
200
],
"id": "5b2488da-dd3a-4db7-bff9-de4a184c35f6",
"webhookId": "c502ed44-f664-4baa-871a-aacc7e4c3697",
"credentials": {
"telegramApi": {
"id": "u2tdgob4GQa8YGGu",
"name": "Olga"
}
}
},
{
"parameters": {
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.9,
"position": [
580,
560
],
"id": "6d8fbb22-08c0-4a20-94a0-d9617b07aa1d",
"name": "AI Agent"
},
{
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
580,
740
],
"id": "0a668a00-223e-4990-bb46-955f64710d29",
"name": "OpenAI Chat Model",
"credentials": {
"openAiApi": {
"id": "j69QDtEudWaihsK9",
"name": "OpenAi account 2"
}
}
},
{
"parameters": {
"contextWindowLength": 25
},
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3,
"position": [
680,
820
],
"id": "7e5c0e8e-5066-4429-b51b-7944ec00e61e",
"name": "Simple Memory"
}
],
"pinData": {},
"connections": {
"Telegram Trigger": {
"main": [
[
{
"node": "Language Detection",
"type": "main",
"index": 0
}
]
]
},
"Language Detection": {
"main": [
[
{
"node": "Command Router",
"type": "main",
"index": 0
},
{
"node": "Get User Data",
"type": "main",
"index": 0
}
]
]
},
"Command Router": {
"main": [
[
{
"node": "Subscription Check",
"type": "main",
"index": 0
}
]
]
},
"Get User Data": {
"main": [
[
{
"node": "Process User Data",
"type": "main",
"index": 0
}
]
]
},
"Subscription Check": {
"main": [
[
{
"node": "Process Commands",
"type": "main",
"index": 0
}
]
]
},
"Process Commands": {
"main": [
[
{
"node": "Send Command Response",
"type": "main",
"index": 0
}
]
]
},
"Send Command Response": {
"main": [
[
{
"node": "Telegram Send Message",
"type": "main",
"index": 0
}
]
]
},
"OpenAI GPT": {
"main": [
[]
]
},
"Update Context & Count": {
"main": [
[
{
"node": "Update User Data in Sheets",
"type": "main",
"index": 0
}
]
]
},
"Update User Data in Sheets": {
"main": [
[
{
"node": "Telegram Send Message",
"type": "main",
"index": 0
}
]
]
},
"Gratitude Detection": {
"main": [
[
{
"node": "Build Donation Offer",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Update Context & Count",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "d21dafa7-3ccf-4c09-ad55-c2503da81706",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "82215e1cd813d80b98891916892f6351ce965a27979285cf5a4eddf492767372"
},
"id": "Do0Fg5k5BBvOpQmA",
"tags": []
}