Files
n8n/backups/2025-12-27/tx_text.json
2025-12-27 21:50:16 +00:00

1 line
26 KiB
JSON
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"updatedAt":"2025-11-30T14:45:15.046Z","createdAt":"2025-11-30T14:22:55.223Z","id":"kohwX0oaY0hmL9b2","name":"tx_text","active":false,"isArchived":false,"nodes":[{"parameters":{"rules":{"values":[{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"0a73cab2-d78a-4354-a626-2fa054d2426a","leftValue":"={{ $json.message.text }}","rightValue":"/start","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"start"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"leftValue":"={{ $json.message.text }}","rightValue":"/v","operator":{"type":"string","operation":"startsWith"},"id":"c83a3bbf-a07a-4547-aa5f-24d1641dc2fe"}],"combinator":"and"},"renameOutput":true,"outputKey":"main"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"fa47404d-c110-4d4a-8310-126eb004bd75","leftValue":"={{ $json.message.text }}","rightValue":"/","operator":{"type":"string","operation":"notStartsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"chat"}]},"options":{}},"type":"n8n-nodes-base.switch","typeVersion":3.2,"position":[-4128,624],"id":"c9164468-42e2-475b-ae89-1f30d90d4cd8","name":"Switch"},{"parameters":{"jsCode":"const chatId = $items('extract')[0].json.chat_id;\nconst src = JSON.parse($json.message.content); // {\"dish\":..,\"grams\":..[, \"time\":\"HH:MM\"]}\n\n// ── московская «сегодня»\nconst now = new Date(new Date().toLocaleString('en-US',{ timeZone:'Europe/Moscow' }));\n\n// берём HH:MM из src.time или текущее\nlet [hh, mm] =\n src.time?.match(/^(\\d{2}):(\\d{2})$/)?.slice(1) ||\n [now.getHours(), now.getMinutes()].map(n => String(n).padStart(2,'0'));\n\n// собираем ISO-строку в МСК (+03:00) — без перевода в UTC\nconst pad = n => String(n).padStart(2,'0');\nconst eatenAt = `${now.getFullYear()}-${pad(now.getMonth()+1)}-${pad(now.getDate())}` +\n `T${hh}:${mm}:00+03:00`;\n\nreturn [{\n json: {\n chat_id : chatId,\n dish : src.dish,\n grams : src.grams,\n eaten_at: eatenAt\n }\n}];\n"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-3024,64],"id":"bc17ee36-1ac2-4392-aad1-fba77291cdc4","name":"parseJSON"},{"parameters":{"inputSource":"passthrough"},"type":"n8n-nodes-base.executeWorkflowTrigger","typeVersion":1.1,"position":[-4432,624],"id":"67bd015d-9cdc-42c8-978f-13b436d9ffee","name":"When Executed by Another Workflow"},{"parameters":{"jsCode":"const text = $json.message.text.replace(/^\\/v\\s+/i, '');\nreturn [{ json: { chat_id: $json.message.chat.id, raw: text } }];\n"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-3792,144],"id":"1a8628d9-70b1-4986-ab3a-67127dae4dad","name":"extract"},{"parameters":{"modelId":{"__rl":true,"value":"gpt-4o-mini","mode":"list","cachedResultName":"GPT-4O-MINI"},"messages":{"values":[{"content":"=Ты нутри-калькулятор.\nНа вход одна строка «dish, grams».\nВерни ТОЛЬКО одну строку JSON:\n{\"dish\":\"…\",\"kcal\":число,\"prot\":число,\"fat\":число,\"carb\":число}\nБез ``` и без пояснений.","role":"system"},{"content":"={{ $json.dish }}, {{ $json.grams }}"}]},"jsonOutput":true,"options":{}},"type":"@n8n/n8n-nodes-langchain.openAi","typeVersion":1.8,"position":[-2800,64],"id":"b59fbfc7-0ef2-4343-bd3a-9d278c66baa4","name":"nutrion","credentials":{"openAiApi":{"id":"PvUURuR361IXH0ve","name":"OpenAi account"}}},{"parameters":{"modelId":{"__rl":true,"value":"gpt-4o-mini","mode":"list","cachedResultName":"GPT-4O-MINI"},"messages":{"values":[{"content":"Ты нутри-парсер.\n\nПолучаешь одну строку с описанием еды, которую ел человек и время употребления.\n\n- Если можешь разумно оценить порцию и массу (число граммов) — даже по словам типа «1 шт», «половина», «два куска» — верни ОДНУ строку JSON:\n\n{\"dish\":\"…\",\"grams\":число[, \"time\":\"HH:MM\"]}\n\n- time указывай, только если нашёл в тексте, без даты.\n\n- Если оценить порцию или время нельзя — верни ТЕКСТ-подсказку:\n*Не распознал* 🤔\n\n*Формат:* /v блюдо граммы [HH:MM]\n*Пример:* /v яблоко 100г 18:00","role":"system"},{"content":"={{ $json.raw }}"}]},"options":{}},"type":"@n8n/n8n-nodes-langchain.openAi","typeVersion":1.8,"position":[-3584,144],"id":"f6bfff2b-d314-4711-9270-955298485482","name":"parser","credentials":{"openAiApi":{"id":"PvUURuR361IXH0ve","name":"OpenAi account"}}},{"parameters":{"content":"# /v РУЧНОЙ ВВОД\n\n\n\n\n","height":432,"width":1858,"color":4},"id":"7e1060f1-6a5e-4bb3-af9e-4dfcd099c011","name":"Sticky Note4","type":"n8n-nodes-base.stickyNote","position":[-3872,0],"typeVersion":1},{"parameters":{"content":"# ОБЩЕНИЕ С НУТРИЦИОЛОГОМ\n\n\n\n","height":472,"width":1858,"color":6},"id":"7d0b54c9-0380-4574-862e-0498caa8b9c9","name":"Sticky Note","type":"n8n-nodes-base.stickyNote","position":[-3872,464],"typeVersion":1},{"parameters":{"content":"# /start И СОЗДАНИЕ ПРОФИЛЯ\n\n\n\n","height":312,"width":858,"color":7},"id":"9939394c-5911-47a3-88e1-61aa477cdc4c","name":"Sticky Note1","type":"n8n-nodes-base.stickyNote","position":[-3872,-352],"typeVersion":1},{"parameters":{"updates":["*"],"additionalFields":{}},"type":"n8n-nodes-base.telegramTrigger","typeVersion":1.2,"position":[-4688,1152],"id":"ffd54069-c184-432a-a21c-803bb6c44a15","name":"Telegram Trigger","webhookId":"e4d6b058-dc8c-4130-9abd-41243518e824","credentials":{"telegramApi":{"id":"L9KHcMiteyKROF5r","name":"Telegram main n8n"}},"disabled":true},{"parameters":{"rules":{"values":[{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"52493568-0b68-46b8-b18a-894cf77bcac1","leftValue":"={{$json.callback_query.data}}","rightValue":"manual_","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"manual"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"5eeb9b3f-d4ce-45f6-bb62-32244fd9a99a","leftValue":"={{ $json.message.photo[0] }}","rightValue":"","operator":{"type":"object","operation":"exists","singleValue":true}}],"combinator":"and"},"renameOutput":true,"outputKey":"image"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"2f1495ad-2eb2-4729-af5a-23c949adce8c","leftValue":"={{$json.callback_query.data}}","rightValue":"dish_yes_","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"dish_yes"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"leftValue":"={{$json.callback_query.data}}","rightValue":"dish_no_","operator":{"type":"string","operation":"startsWith"},"id":"c9ead52e-1b81-453a-bd9b-1d18dcbd82bb"}],"combinator":"and"},"renameOutput":true,"outputKey":"dish_no"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"646db5d3-3518-4edf-9374-cef371fa7ba9","leftValue":"={{$json.callback_query.data}}","rightValue":"alt_","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"alt"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"1bcf1e75-3e73-465b-8bbb-2665b845e7e9","leftValue":"={{$json.callback_query.data}}","rightValue":"weight_","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"renameOutput":true,"outputKey":"weight"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"6166763a-38e9-494a-aea0-20bdc9626314","leftValue":"={{ $json.message.text }}","rightValue":"/","operator":{"type":"string","operation":"exists","singleValue":true}}],"combinator":"and"},"renameOutput":true,"outputKey":"text_cmd"}]},"options":{}},"type":"n8n-nodes-base.switch","typeVersion":3.2,"position":[-4464,1072],"id":"47364896-8015-4659-b5e5-0118e2433fe8","name":"Switch1","disabled":true},{"parameters":{"tableId":"profiles","fieldsUi":{"fieldValues":[{"fieldId":"telegram_id","fieldValue":"={{ $('Switch').item.json.message.from.id }}"},{"fieldId":"first_name","fieldValue":"={{ $('Switch').item.json.message.from.first_name }}"},{"fieldId":"username","fieldValue":"={{ $('Switch').item.json.message.from.username }}"},{"fieldId":"locale","fieldValue":"={{ $('Switch').item.json.message.from.language_code }}"},{"fieldId":"created_at","fieldValue":"={{ new Date().toISOString() }}"}]}},"type":"n8n-nodes-base.supabase","typeVersion":1,"position":[-3408,-272],"id":"a6a31b4f-86c6-4bf8-9e4b-631f712375ad","name":"CREATE profile","credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"tableId":"meals","fieldsUi":{"fieldValues":[{"fieldId":"chat_id","fieldValue":"={{ $('parseJSON').item.json.chat_id }}"},{"fieldId":"dish","fieldValue":"={{ $json.message.content.dish }}"},{"fieldId":"grams","fieldValue":"={{ $('parseJSON').item.json.grams }}"},{"fieldId":"kcal","fieldValue":"={{ $json.message.content.kcal }}"},{"fieldId":"prot","fieldValue":"={{ $json.message.content.prot }}"},{"fieldId":"fat","fieldValue":"={{ $json.message.content.fat }}"},{"fieldId":"carb","fieldValue":"={{ $json.message.content.carb }}"},{"fieldId":"eaten_at","fieldValue":"={{ $('parseJSON').item.json.eaten_at }}"}]}},"type":"n8n-nodes-base.supabase","typeVersion":1,"position":[-2400,64],"id":"8b721fc8-086c-4f99-93dc-bf2d85398f77","name":"CREATE meals","credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"11bc0d87-40a0-4a39-b576-9fbb5f7535e8","leftValue":"={{ $json.message.content }}","rightValue":"{","operator":{"type":"string","operation":"startsWith"}}],"combinator":"and"},"options":{}},"type":"n8n-nodes-base.if","typeVersion":2.2,"position":[-3248,144],"id":"c23ec87b-4ae6-4c85-ad00-98463a279ac5","name":"IF 2"},{"parameters":{"chatId":"={{ $('Switch').item.json.message.from.id }}","text":"=*Привет, {{ $('Switch').item.json.message.from.first_name }}!*\n\nЯ помогу тебе отслеживать рацион, считать КБЖУ и подсказывать, как питаться лучше.\n\n🧾 *Как начать:*\n📸 Просто *отправь фото еды* — я распознаю блюдо и рассчитаю КБЖУ. \n🧠 Каждое блюдо *сохраняется в твоём дневнике* — можно вернуться, пересмотреть и задать вопросы. \n📬 *Каждый вечер* я присылаю краткий отчёт и даю рекомендации на завтра.\n\n📝 *Можно вводить вручную:* \nПример: _/v омлет 2 яйца 09:00_\n\n⚖ Если не знаешь вес — опиши на глаз, я прикину сам.\n\nГотов? Тогда начинаем — *просто пришли фото!*","additionalFields":{"appendAttribution":false,"parse_mode":"Markdown"}},"type":"n8n-nodes-base.telegram","typeVersion":1.2,"position":[-3200,-224],"id":"ca337e78-64cc-4c64-bca9-17c1ea866ed3","name":"start","webhookId":"da4a8d3c-0d67-480c-a25d-4844309807d2","credentials":{"telegramApi":{"id":"R8VDF53JH3mzhoHd","name":"Telegram dieta"}}},{"parameters":{"chatId":"={{ $('extract').item.json.chat_id }}","text":"={{ $json.message.content }}","additionalFields":{"appendAttribution":false,"parse_mode":"Markdown"}},"type":"n8n-nodes-base.telegram","typeVersion":1.2,"position":[-3024,240],"id":"ac45a9e6-7b89-4e5d-bc57-13f0111eeb27","name":"ERROR","webhookId":"da4a8d3c-0d67-480c-a25d-4844309807d2","credentials":{"telegramApi":{"id":"R8VDF53JH3mzhoHd","name":"Telegram dieta"}}},{"parameters":{"chatId":"={{ $('parseJSON').item.json.chat_id }}","text":"=*{{ $json.dish }} {{ $json.grams }} г*\n\n*Калорий:* {{ $json.kcal }}\n*Б:* {{ $json.prot }}*Ж:* {{ $json.fat }}*У:* {{ $json.carb }}\n\n✔ _сохранил в память_","replyMarkup":"inlineKeyboard","inlineKeyboard":{"rows":[{"row":{"buttons":[{"text":"🚫 не сохранять","additionalFields":{"callback_data":"=cancel_{{ $json.id }}"}}]}}]},"additionalFields":{"appendAttribution":false,"parse_mode":"Markdown"}},"type":"n8n-nodes-base.telegram","typeVersion":1.2,"position":[-2224,64],"id":"d88c0638-258c-4cff-b281-efae3273f1bc","name":"OK","webhookId":"da4a8d3c-0d67-480c-a25d-4844309807d2","credentials":{"telegramApi":{"id":"R8VDF53JH3mzhoHd","name":"Telegram dieta"}}},{"parameters":{"content":"## [включать только для настройки]\n\n","height":432,"width":598,"color":5},"id":"c9c6e80a-9912-412e-9a76-1e0116a3072d","name":"Sticky Note2","type":"n8n-nodes-base.stickyNote","position":[-4768,992],"typeVersion":1},{"parameters":{"operation":"getAll","tableId":"profiles","returnAll":true,"filters":{"conditions":[{"keyName":"telegram_id","condition":"eq","keyValue":"={{ $json.message.from.id }}"}]}},"type":"n8n-nodes-base.supabase","typeVersion":1,"position":[-3792,-240],"id":"ce283995-c8bb-44a8-ab2c-edc7f5a344c8","name":"GET profile","alwaysOutputData":true,"credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"dbd664b4-20b3-4d51-8000-20892b93782d","leftValue":"={{ Object.keys($items(\"GET profile\")[0].json || {}).length }}","rightValue":0,"operator":{"type":"number","operation":"equals"}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"type":"n8n-nodes-base.if","typeVersion":2.2,"position":[-3600,-240],"id":"b0e56ab9-830e-4308-b243-4bc5429ee3e9","name":"IF NO"},{"parameters":{"model":{"__rl":true,"value":"gpt-4.1","mode":"list","cachedResultName":"gpt-4.1"},"options":{}},"type":"@n8n/n8n-nodes-langchain.lmChatOpenAi","typeVersion":1.2,"position":[-3024,704],"id":"87d7d1a7-4e34-447f-8e1b-c3708e54c5f2","name":"OpenAI","credentials":{"openAiApi":{"id":"PvUURuR361IXH0ve","name":"OpenAi account"}}},{"parameters":{"chatId":"={{ $json.chat_id }}","text":"={{ $json.content }}","additionalFields":{"appendAttribution":false,"parse_mode":"MarkdownV2"}},"type":"n8n-nodes-base.telegram","typeVersion":1.2,"position":[-2368,560],"id":"2167b5a3-2649-410a-a1b6-1432a5f418e7","name":"Telegram","webhookId":"ce8565f7-fca8-4e4e-b9ba-109e833298a3","credentials":{"telegramApi":{"id":"R8VDF53JH3mzhoHd","name":"Telegram dieta"}}},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"336d64ed-3993-434e-9bbd-abb9f3c777f3","leftValue":"={{ $json.summary_md }}","rightValue":"","operator":{"type":"string","operation":"exists","singleValue":true}}],"combinator":"and"},"options":{}},"type":"n8n-nodes-base.if","typeVersion":2.2,"position":[-3472,736],"id":"9eb724a0-8e6d-412c-bb9b-c19a0f00c322","name":"If"},{"parameters":{"method":"POST","url":"https://lsdfsdfsdffdssdfgdsmuxv.supabase.co/rest/v1/rpc/get_current_summary","authentication":"genericCredentialType","genericAuthType":"httpHeaderAuth","sendHeaders":true,"headerParameters":{"parameters":[{"name":"apikey","value":"KEY"}]},"sendBody":true,"bodyParameters":{"parameters":[{"name":"_chat_id","value":"={{ $json.chat_id }}"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[-3648,736],"id":"97736d2f-06bf-4867-92c2-2d3db4c5e83f","name":"SUPA digest","executeOnce":false,"alwaysOutputData":true,"credentials":{"httpHeaderAuth":{"id":"8MpbqGPzLpfPWyM8","name":"Header Auth account"}}},{"parameters":{"assignments":{"assignments":[{"id":"64fb8515-cda5-462c-afcf-2c9865a3631d","name":"hasDigest","value":false,"type":"boolean"}]},"includeOtherFields":true,"options":{}},"type":"n8n-nodes-base.set","typeVersion":3.4,"position":[-3232,720],"id":"005f2615-542b-46fa-8a76-9cb03b0948e6","name":"NO DIGEST"},{"parameters":{"assignments":{"assignments":[{"id":"08b17997-5514-4157-9518-365744b2a556","name":"hasDigest","value":true,"type":"boolean"}]},"includeOtherFields":true,"options":{}},"type":"n8n-nodes-base.set","typeVersion":3.4,"position":[-3232,560],"id":"01c85f51-adc6-46d2-9446-7c61bde6d647","name":"YES DIGEST"},{"parameters":{"operation":"getAll","tableId":"meals","matchType":"allFilters","filters":{"conditions":[{"keyName":"chat_id","condition":"eq","keyValue":"={{ $('Switch').item.json.message.from.id }}"},{"keyName":"eaten_at","condition":"gte","keyValue":"={{ (() => {\n // «сейчас» в Москве\n const now = new Date(new Date()\n .toLocaleString('en-US', { timeZone: 'Europe/Moscow' }));\n\n // минус 7 суток\n now.setDate(now.getDate() - 7);\n\n // ставим начало дня и возвращаем ISO +03:00\n now.setHours(0,0,0,0);\n return now.toISOString().replace('Z','+03:00');\n})() }}\n"},{"keyName":"eaten_at","condition":"lte","keyValue":"={{ (() => {\n const now = new Date(new Date()\n .toLocaleString('en-US', { timeZone: 'Europe/Moscow' }));\n return now.toISOString().replace('Z','+03:00');\n})() }}\n"},{"keyName":"deleted","condition":"is","keyValue":"false"}]}},"type":"n8n-nodes-base.supabaseTool","typeVersion":1,"position":[-2864,704],"id":"510dd810-d7ec-4b33-a858-0f680a16ba49","name":"get_week_meals","credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"content":"## [основной триггер]\n\n","height":272,"width":298},"id":"6aa8616c-d2e4-4f2b-92cb-e343f5c2e43c","name":"Sticky Note3","type":"n8n-nodes-base.stickyNote","position":[-4528,560],"typeVersion":1},{"parameters":{"mode":"runOnceForEachItem","jsCode":"const escapeMdV2 = s =>\n s.replace(/[_*[\\]()~`>#+\\-=|{}.!]/g, '\\\\$&');\n\nif (item.json.output) {\n item.json.output = escapeMdV2(item.json.output);\n}\nreturn item;\n"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-2704,560],"id":"c65c19fe-511e-4dc6-b4c8-883f9393f98b","name":"Escape"},{"parameters":{"assignments":{"assignments":[{"id":"442870a4-1075-4f7c-bdce-f6011d4c93da","name":"chat_id","value":"={{ $json.message.chat.id }}","type":"string"},{"id":"d38f3a89-b513-46c0-b960-ba64a754bd58","name":"session_id","value":"={{ 'user_' + $json.message.chat.id }}","type":"string"},{"id":"8d169f91-297e-494d-8260-224ef6f88cba","name":"role","value":"user","type":"string"},{"id":"011e9af4-a978-4985-bf28-dbafcb4fa2e9","name":"content","value":"={{ $json.message.text }}","type":"string"},{"id":"3ad625a1-0bdd-48cf-901b-d1306d890628","name":"username","value":"={{ $json.message.from.username }}","type":"string"},{"id":"c4c0ac19-2cdd-451b-b0f0-7829e06bd7b6","name":"first_name","value":"={{ $json.message.from.first_name }}","type":"string"},{"id":"c270f762-1398-45d2-a58c-883b5f512bd3","name":"metadata","value":"={{ JSON.stringify($json) }}","type":"string"}]},"options":{}},"type":"n8n-nodes-base.set","typeVersion":3.4,"position":[-3824,640],"id":"fc32bc09-bcb2-478c-a68e-d76374a9ae29","name":"User Log"},{"parameters":{"tableId":"chat_logs","fieldsUi":{"fieldValues":[{"fieldId":"chat_id","fieldValue":"={{ $json.chat_id }}"},{"fieldId":"session_id","fieldValue":"={{ $json.session_id }}"},{"fieldId":"role","fieldValue":"={{ $json.role }}"},{"fieldId":"content","fieldValue":"={{ $json.content }}"},{"fieldId":"username","fieldValue":"={{ $json.username }}"},{"fieldId":"first_name","fieldValue":"={{ $json.first_name }}"},{"fieldId":"metadata","fieldValue":"={{ $json.metadata }}"}]}},"type":"n8n-nodes-base.supabase","typeVersion":1,"position":[-3648,560],"id":"6809455e-17ae-43fe-85f4-90ebaa50a84b","name":"Save User Msg","credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"tableId":"chat_logs","fieldsUi":{"fieldValues":[{"fieldId":"chat_id","fieldValue":"={{ $('Bot Log').item.json.chat_id }}"},{"fieldId":"session_id","fieldValue":"={{ $('Bot Log').item.json.session_id }}"},{"fieldId":"role","fieldValue":"={{ $('Bot Log').item.json.role }}"},{"fieldId":"content","fieldValue":"={{ $('Bot Log').item.json.content }}"},{"fieldId":"metadata","fieldValue":"={{ $('Bot Log').item.json.metadata }}"}]}},"type":"n8n-nodes-base.supabase","typeVersion":1,"position":[-2208,560],"id":"9feb58a1-c00c-4fd0-aea7-2598bfb1188b","name":"Save Bot Msg","credentials":{"supabaseApi":{"id":"OoOx3pPUNd1lRJTr","name":"Supabase account"}}},{"parameters":{"assignments":{"assignments":[{"id":"03bc3c9d-7d1b-4f70-999d-115edccd98dd","name":"chat_id","value":"={{ $('User Log').item.json.chat_id }}","type":"string"},{"id":"9093739a-9c1b-4b54-8487-9a79272b6892","name":"session_id","value":"={{ $('User Log').item.json.session_id }}","type":"string"},{"id":"4bc4cf2d-63c7-49f3-bae8-7d08160305ca","name":"role","value":"assistant","type":"string"},{"id":"494392e4-828d-4fd6-a70b-af2c9e050558","name":"content","value":"={{ $json.output }}","type":"string"},{"id":"581ad272-fd98-4fa1-8bb1-b985f816079d","name":"metadata","value":"={{ JSON.stringify($json) }}","type":"string"}]},"options":{}},"type":"n8n-nodes-base.set","typeVersion":3.4,"position":[-2528,560],"id":"54206087-4a48-4835-9a55-3c18eee2ed80","name":"Bot Log"},{"parameters":{"promptType":"define","text":"={{ $('Switch').item.json.message.text }}","options":{"systemMessage":"=Ты дипломированный нутрициолог. Твоя задача отвечать на вопросы пользователя и консультировать его. Веди себя как профессионал, но старайся общаться достаточно естественно, так как беседа ведется в мессенджере.\n\nНа вход получаешь:\n1. Отчет по питанию для клиента за прошедший день: {{ $json.summary_md }}\n2. kcal за день: {{ $json.kcal }}\n3. fat: {{ $json.fat }}\n4. carb: {{ $json.carb }}\n5. prot: {{ $json.prot }}\n6. hasDigest: {{ $json.hasDigest }}\n\n• Если отчет за день есть, а hasDigest = true → используй этот отчет в качестве основного источника данных при осставлении рекомендаций для человека и ответа на его вопросы. \n• Если инфы нет, а hasDigest = false → значит просто не учитывай эту информацию (не обязательно уведомлять человека) и общайся, стараясь быть ценным для собеседника\n• У тебя есть доступ к инструменту \"get_today_meals\" который дает доступ к полному рациону питания человека за последние две недели, используй его при необходимости.\n\n- Формат сообщения должен быть Markdown для телеграм, для жирного шрифта используй одну * в начале и в конце, а для курсива _ вместо ** (ПРИМЕР: *жирный*, _курсив_).\n- Разрешается использовать тематические эмоджи где уместно.\n- Используй жирный *только для целых слов или фраз*, курсив — тоже для целых слов.\n- Не вставляй * внутри markdown-заголовков и списков.\n"}},"type":"@n8n/n8n-nodes-langchain.agent","typeVersion":1.9,"position":[-3024,560],"id":"cba58739-8392-49bc-96b5-a0e2ebe14147","name":"nutrion 2"}],"connections":{"Switch":{"main":[[{"node":"GET profile","type":"main","index":0}],[{"node":"extract","type":"main","index":0}],[{"node":"User Log","type":"main","index":0}]]},"parseJSON":{"main":[[{"node":"nutrion","type":"main","index":0}]]},"When Executed by Another Workflow":{"main":[[{"node":"Switch","type":"main","index":0}]]},"extract":{"main":[[{"node":"parser","type":"main","index":0}]]},"nutrion":{"main":[[{"node":"CREATE meals","type":"main","index":0}]]},"parser":{"main":[[{"node":"IF 2","type":"main","index":0}]]},"Telegram Trigger":{"main":[[{"node":"Switch1","type":"main","index":0}]]},"Switch1":{"main":[[],[],[],[],[],[],[{"node":"Switch","type":"main","index":0}]]},"CREATE profile":{"main":[[{"node":"start","type":"main","index":0}]]},"IF 2":{"main":[[{"node":"parseJSON","type":"main","index":0}],[{"node":"ERROR","type":"main","index":0}]]},"CREATE meals":{"main":[[{"node":"OK","type":"main","index":0}]]},"GET profile":{"main":[[{"node":"IF NO","type":"main","index":0}]]},"IF NO":{"main":[[{"node":"CREATE profile","type":"main","index":0}],[{"node":"start","type":"main","index":0}]]},"OpenAI":{"ai_languageModel":[[{"node":"nutrion 2","type":"ai_languageModel","index":0}]]},"SUPA digest":{"main":[[{"node":"If","type":"main","index":0}]]},"If":{"main":[[{"node":"YES DIGEST","type":"main","index":0}],[{"node":"NO DIGEST","type":"main","index":0}]]},"YES DIGEST":{"main":[[{"node":"nutrion 2","type":"main","index":0}]]},"NO DIGEST":{"main":[[{"node":"nutrion 2","type":"main","index":0}]]},"get_week_meals":{"ai_tool":[[{"node":"nutrion 2","type":"ai_tool","index":0}]]},"Escape":{"main":[[{"node":"Bot Log","type":"main","index":0}]]},"Telegram":{"main":[[{"node":"Save Bot Msg","type":"main","index":0}]]},"User Log":{"main":[[{"node":"Save User Msg","type":"main","index":0},{"node":"SUPA digest","type":"main","index":0}]]},"Bot Log":{"main":[[{"node":"Telegram","type":"main","index":0}]]},"nutrion 2":{"main":[[{"node":"Escape","type":"main","index":0}]]}},"settings":{"executionOrder":"v1"},"staticData":null,"meta":{"templateCredsSetupCompleted":true},"pinData":{},"versionId":"03f13c10-304e-4181-b6d0-c15852a55dae","activeVersionId":null,"triggerCount":0,"shared":[{"updatedAt":"2025-11-30T14:22:55.223Z","createdAt":"2025-11-30T14:22:55.223Z","role":"workflow:owner","workflowId":"kohwX0oaY0hmL9b2","projectId":"sYuiFAb87pAir6jV"}],"activeVersion":null,"tags":[]}