Full Technical Prompt for Workflow with Telegram Bot + Google Sheets + OpenAI + Subscription Management
Context:
You are building a Telegram bot named Olga, whose native language is English, but mainly communicates in Russian, supporting molecular cooking, nutrition, psychology, and subtle human interactions. The bot uses n8n workflow automation integrated with:

Telegram Trigger: receives messages from users.
Google Sheets: user database storing subscription type, message counts, and user metadata.
OpenAI GPT: generates natural, context-aware answers.
Language Detection API: to detect user message language and inform about translation if needed.
Subscription and limits management: tracks subscriptions (none, standard, premium), message usage limits, and handles donations.
Workflow Logic and Steps:

Receive user message from Telegram via Telegram Trigger node.
Extract user info: Telegram chat ID, username, user id.
Extract the text message content.
Detect message language using Language Detection API.
If message language is not Russian, bot adds a disclaimer: "I use a translator for communication, apologies if some inaccuracies appear."
Check if user exists in Google Sheets Users database, using the chatId column lookup:
If found, retrieve user data: subscriptionType, messagesUsed, subscription expiry, language, etc.
If not found, automatically add new user with default values:
subscriptionType = none
messagesUsed = 0
Dates empty or initialized appropriately
language = unknown or based on language detection result
Process commands:
If the message starts with / treat it as a command.
Supported commands: /start, /help, /donate, /premium, /subscribe.
Send predefined replies and buttons for these commands.
Check user's subscription status and message usage limits:
If subscription is premium, user has no message limit.
If standard or none, enforce a message limit per month — configurable via a workflow variable TOKEN_LIMIT.
If the user exceeded the allowed message count:
Bot sends a message informing about limit reached.
Shows buttons with subscription offers (Subscribe, Premium) and blocks regular conversation.
If within limits:
Generate a GPT prompt adding a base system prompt:
"You are a 35-40 year old woman named Olga — a confectioner, interested in molecular cooking, emotionally and scientifically supportive, strictly no flirting or flattery."
Include user's latest message in the prompt.
Call OpenAI GPT node with the prepared prompt.
Send GPT’s reply back via Telegram node.
Increment user message counter:
If user is not premium, increase messagesUsed by 1.
Update this data in Google Sheets.
Handle donation reminders:
If the user recently (more than 24h ago) thanked the bot (words like "thanks", "спасибо" detected),
Then send a donation reminder message with buttons.
Update the last donation reminder date in Google Sheets.
Data and Table Structure Expected in Google Sheets
| id | chatId | subscriptionType | messagesUsed | messagesResetDate | lastMessageDate | language | sessionContext | lastDonationReminder |
chatId: identifies Telegram user uniquely.
subscriptionType: none, standard, or premium.
messagesUsed: how many messages user has sent this month.
messagesResetDate: date when message count resets (typical monthly reset).
lastMessageDate: timestamp of last message.
language: detected language code.
sessionContext: any context for AI conversation session (optional).
lastDonationReminder: date of last donation reminder sent.
Important Implementation Notes:
Use a Google Sheets Lookup Row operation by chatId for identifying existing users.
Auto-add new users with default subscription and zero message count if lookup fails.
Update message usage by updating the specific Google Sheets row with the row index from lookup.
Implement month reset logic: optionally reset messagesUsed when current date > messagesResetDate.
The bot never proceeds to OpenAI prompt generation if the user exceeded their message limit (except Premium users).
Language detection should be done on original message text before any processing.
Donation reminders sent only if 24+ hours passed since last reminder and user recently thanked the bot.
Commands override normal workflow, sending predefined message/buttons and skip AI prompt.
All dates are saved in ISO8601 format for consistency.
Ensure proper error handling for Google Sheets operations (e.g., if appending or updating fail).
Telegram reply messages can contain inline buttons (callback URLs or URLs).
Example of base system prompt to OpenAI GPT:

You are Olga: a 35-40 year-old woman, a confectioner interested in molecular cooking, who provides emotional and scientific support.
You communicate in Russian primarily. If user writes in another language, say: "I use a translator for communication, apologies for inaccuracies."
You never flirt or flatter.
You have deep knowledge in psychology, nutrition, and supplements based on PubMed research.
You maintain a friendly yet professional tone.
User message: {user_message}
Olga's reply:
Summary:
This workflow enables a seamless experience:

User messages the bot →
Bot identifies user or auto-registers →
Checks subscription and messaging limits →
Processes commands or conversations →
Replies via OpenAI →
Updates usage stats →
Sends donation reminders as appropriate.


Посмотри что не так с джисон, гугл таблица не меняется от количества сообщений

{
  "name": "My workflow 8",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        -220,
        380
      ],
      "id": "0c64eab8-e171-4bf8-9df1-2fde9b644d70",
      "webhookId": "e68f1515-4cad-4ffe-8010-899e7259f56b",
      "credentials": {
        "telegramApi": {
          "id": "u2tdgob4GQa8YGGu",
          "name": "Olga"
        }
      }
    },
    {
      "parameters": {
        "sheetId": "1qErvzT0mhmFFd3uP-7QPf7Cgt4LKhHjLWcvTfz0Uv7k",
        "range": "Users!A:I",
        "options": {}
      },
      "name": "Google Sheets: Read Rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        0,
        380
      ],
      "id": "67a29273-d821-4941-a3e8-f9c3872accd8",
      "credentials": {
        "googleApi": {
          "id": "g9xNLyF3Ofb2DM0I",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const chatIdToFind = $json.chatId || $json.message?.chat?.id;\nconst rows = $items('Google Sheets: Read Rows');\n\nconst foundUserItem = rows.find(item => item.json.chatId === String(chatIdToFind));\n\nif (foundUserItem) {\n  const rowIndex = foundUserItem.json.__rowIndex || foundUserItem?.json?.rowIndex || null;\n  foundUserItem.json.__rowIndex = parseInt(rowIndex, 10);\n  return [{ json: { ...foundUserItem.json } }];\n}\nreturn [];\n"
      },
      "name": "Find User",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        220,
        380
      ],
      "id": "b773649c-178c-4e5d-ba22-9a1c90bd3f16"
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json.__rowIndex || 0}}",
              "operation": "larger"
            }
          ]
        }
      },
      "name": "IF User Found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        440,
        380
      ],
      "id": "556a61a4-83ff-4d4f-926d-2b9ca11af33c"
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1qErvzT0mhmFFd3uP-7QPf7Cgt4LKhHjLWcvTfz0Uv7k",
        "range": "Users!A:I",
        "options": {}
      },
      "name": "Add New User",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        660,
        305
      ],
      "id": "04bbf850-67ce-474d-9f9e-089432a90c02",
      "credentials": {
        "googleApi": {
          "id": "g9xNLyF3Ofb2DM0I",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return [{\n  json: {\n    id: '',\n    chatId: $json.chatId || $json.message?.chat?.id || '',\n    subscriptionType: 'none',\n    messagesUsed: 0,\n    messagesResetDate: new Date(new Date().setDate(1)).toISOString(),\n    lastMessageDate: new Date().toISOString(),\n    language: 'unknown',\n    sessionContext: '',\n    lastDonationReminder: ''\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        880,
        305
      ],
      "id": "033bea8f-71c4-47ad-b66a-199591b7909d",
      "name": "New User Defaults"
    },
    {
      "parameters": {
        "functionCode": "const user = $json;\nuser.chatId = user.chatId || $json.message?.chat?.id || '';\nuser.subscriptionType = user.subscriptionType || 'none';\nuser.messagesUsed = Number(user.messagesUsed) || 0;\nuser.messagesResetDate = user.messagesResetDate || new Date(new Date().setDate(1)).toISOString();\nuser.lastMessageDate = user.lastMessageDate || new Date().toISOString();\nuser.language = user.language || 'unknown';\nuser.sessionContext = user.sessionContext || '';\nuser.lastDonationReminder = user.lastDonationReminder || '';\nreturn [{ json: user }];"
      },
      "name": "Prepare User Data Unified",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1100,
        380
      ],
      "id": "fb3c902b-f435-4c3d-a50d-835bfc9f5537"
    },
    {
      "parameters": {
        "functionCode": "const text = ($json.text || '').trim();\nconst isCommand = text.startsWith('/');\nconst command = isCommand ? text.split(' ')[0] : null;\nreturn { json: { isCommand, command } };"
      },
      "name": "Check Command",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1760,
        280
      ],
      "id": "1220fbbd-57d0-47c3-b40a-9851dd576943"
    },
    {
      "parameters": {
        "functionCode": "const command = $json.command;\nconst replyData = { reply: '', buttons: [] };\nswitch (command) {\n  case '/start':\n    replyData.reply = 'Welcome to Olga Bot! How can I assist you today?';\n    replyData.buttons = [[{ text: 'Help', callback_data: '/help' }]];\n    break;\n  case '/help':\n    replyData.reply = 'Commands: /start, /help, /donate, /subscribe, /premium';\n    break;\n  case '/donate':\n    replyData.reply = 'Thank you! Donate here: https://your-donation-link.com';\n    break;\n  case '/subscribe':\n    replyData.reply = 'Subscribe plans:';\n    replyData.buttons = [[{ text: 'Standard', url: 'https://your-subscribe-link.com/standard' }],[{ text: 'Premium', url: 'https://your-subscribe-link.com/premium' }]];\n    break;\n  case '/premium':\n    replyData.reply = 'Premium subscription info: https://your-subscribe-link.com/premium';\n    break;\n  default:\n    replyData.reply = 'Unknown command';\n}\nreturn { json: replyData };"
      },
      "name": "Process Command",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -220,
        -80
      ],
      "id": "4971d88d-d0f3-46ae-bdd0-03e9ed64da8f"
    },
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].json.message.chat.id}}",
        "text": "={{$json.reply}}",
        "additionalFields": {}
      },
      "name": "Send Command Reply",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        0,
        -80
      ],
      "id": "37d85e04-257d-4109-ba63-8402cea37fb7",
      "webhookId": "e82d68cf-1505-4437-ae71-54fefa6dd9dd",
      "credentials": {
        "telegramApi": {
          "id": "u2tdgob4GQa8YGGu",
          "name": "Olga"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const user = $json;\nconst now = new Date();\nconst resetDate = user.messagesResetDate ? new Date(user.messagesResetDate) : null;\nif(resetDate && now >= resetDate){\n  user.messagesUsed = 0;\n  let nextResetDate = new Date(resetDate);\n  nextResetDate.setMonth(nextResetDate.getMonth() + 1);\n  user.messagesResetDate = nextResetDate.toISOString();\n}\nconst THANKED_PHRASES = ['thanks','thank you','спасибо','благодарю'];\nconst lastReminder = user.lastDonationReminder ? new Date(user.lastDonationReminder) : null;\nconst text = ($node[\"Telegram Trigger\"].json.message.text || '').toLowerCase();\nconst recentlyThanked = THANKED_PHRASES.some(p => text.includes(p));\nconst cooldown = 24*60*60*1000;\nlet needDonationReminder = false;\nif(recentlyThanked){\n  if(!lastReminder || (now - lastReminder) > cooldown){\n    needDonationReminder = true;\n  }\n}\nreturn [{ json: { ...user, needDonationReminder } }];"
      },
      "name": "Check and Reset Monthly Limit",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1320,
        380
      ],
      "id": "a43e53d7-bf00-4e9f-8099-d176d632348c"
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json.needDonationReminder}}",
              "value2": true
            }
          ]
        }
      },
      "name": "Need Donation Reminder?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1540,
        380
      ],
      "id": "c7883ef7-4e1b-49dd-8272-e267211c53ed"
    },
    {
      "parameters": {
        "functionCode": "return { json: { reply: 'Thank you for your kind words! If Olga helps, please consider donating ❤️', buttons: [[{ text: 'Donate', url: 'https://your-donation-link.com' }]] } };"
      },
      "name": "Prepare Donation Reminder Message",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1760,
        480
      ],
      "id": "62ba11f3-aed5-4310-b30e-2b659b4bbcbf"
    },
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].json.message.chat.id}}",
        "text": "={{$json.reply}}",
        "additionalFields": {}
      },
      "name": "Send Donation Reminder",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1980,
        480
      ],
      "id": "da3321f0-1ab7-48df-a39d-845e1202504c",
      "webhookId": "1541a808-7267-4fd6-a19b-b555246a6ff6",
      "credentials": {
        "telegramApi": {
          "id": "u2tdgob4GQa8YGGu",
          "name": "Olga"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const user = $json;\nconst TOKEN_LIMIT = 30;\nconst isPremium = (user.subscriptionType || 'none').toLowerCase() === 'premium';\nconst messagesUsed = Number(user.messagesUsed || 0);\nconst isOverLimit = !isPremium && (messagesUsed >= TOKEN_LIMIT);\nreturn [{ json: { ...user, isOverLimit } }];"
      },
      "name": "Check Message Limit",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1980,
        280
      ],
      "id": "806c4314-d974-4b68-8ffe-dd78170699a8"
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json.isOverLimit}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF Limit Exceeded?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        2200,
        280
      ],
      "id": "c4bc0f11-a804-4627-b5a4-0041fd907bc8"
    },
    {
      "parameters": {
        "functionCode": "return { json: { reply: 'You have reached your monthly limit. Please subscribe.', buttons: [[{ text: 'Subscribe', url: 'https://your-subscribe-link.com' },{ text: 'Premium', url: 'https://your-subscribe-link.com/premium' }]] } };"
      },
      "name": "Prepare Limit Message",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2420,
        180
      ],
      "id": "d47c1936-d8b6-442a-b6b9-81f9500ed934"
    },
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].json.message.chat.id}}",
        "text": "={{$json.reply}}",
        "additionalFields": {}
      },
      "name": "Send Limit Message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        2640,
        180
      ],
      "id": "c617c757-04e1-4aee-b3f3-fc5e66b591da",
      "webhookId": "b7218344-f10b-4e4f-9718-323221cea2a7",
      "credentials": {
        "telegramApi": {
          "id": "u2tdgob4GQa8YGGu",
          "name": "Olga"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const systemPrompt = `You are Olga: a 35-40 year-old woman, a confectioner interested in molecular cooking, providing emotional and scientific support.\nYou primarily speak Russian. If the user writes in another language, mention: \"I use a translator for communication, apologies for inaccuracies.\"\nYou never flirt or flatter.\nYou have deep knowledge in psychology, nutrition, and supplements based on PubMed research.\nMaintain a friendly yet professional tone.`;\nconst userMessage = $node[\"Telegram Trigger\"].json.message.text || '';\nconst userLang = $json.language || 'unknown';\nlet prompt = systemPrompt + `\\nUser message: ${userMessage}\\nOlga's reply:`;\nif(userLang !== 'ru' && userLang !== 'unknown') {\n  prompt = 'I use a translator for communication, apologies if some inaccuracies appear.\\n' + prompt;\n}\nreturn { json: { prompt } };"
      },
      "name": "Prepare GPT Prompt",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2420,
        380
      ],
      "id": "0c2216e6-b2d9-4703-8e26-7153a81bbbb2"
    },
    {
      "parameters": {
        "options": {},
        "requestOptions": {}
      },
      "name": "OpenAI GPT",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        2640,
        380
      ],
      "id": "5c3e95dd-9f9f-4c21-a487-332d79ad88d5",
      "credentials": {
        "openAiApi": {
          "id": "UGHwRi1Hhq7lMeC5",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const reply = $json.choices?.[0]?.message?.content || 'Sorry, I can\\'t answer right now.';\nreturn { json: { reply } };"
      },
      "name": "Extract GPT Reply",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2860,
        380
      ],
      "id": "03c10f88-e86a-46dd-b94d-349760f96021"
    },
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].json.message.chat.id}}",
        "text": "={{$json.reply}}",
        "additionalFields": {}
      },
      "name": "Send GPT Reply",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        3080,
        380
      ],
      "id": "b775fd8f-eae5-4c7a-a60f-41f74022c7ad",
      "webhookId": "dc3beaf5-efb6-4bc1-a6ee-4ab580cf0913",
      "credentials": {
        "telegramApi": {
          "id": "u2tdgob4GQa8YGGu",
          "name": "Olga"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const user = $json;\nconst isPremium = (user.subscriptionType || 'none').toLowerCase() === 'premium';\nif(!isPremium){\n  user.messagesUsed = Number(user.messagesUsed || 0) + 1;\n  user.lastMessageDate = new Date().toISOString();\n}\nreturn [{ json: user }];"
      },
      "name": "Increment Message Count",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        3300,
        380
      ],
      "id": "ab2d8523-a4d7-4f84-8b5f-52ac7bf1a2a5"
    },
    {
      "parameters": {
        "operation": "update",
        "sheetId": "1qErvzT0mhmFFd3uP-7QPf7Cgt4LKhHjLWcvTfz0Uv7k",
        "range": "Users!A:I",
        "keyRow": null,
        "options": {}
      },
      "name": "Google Sheets: Update User",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        3520,
        380
      ],
      "id": "a7994f9d-43ac-4dc6-897c-b0424f5b475a",
      "credentials": {
        "googleApi": {
          "id": "g9xNLyF3Ofb2DM0I",
          "name": "Google Sheets account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets: Read Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Read Rows": {
      "main": [
        [
          {
            "node": "Find User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find User": {
      "main": [
        [
          {
            "node": "IF User Found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF User Found?": {
      "main": [
        [
          {
            "node": "Prepare User Data Unified",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add New User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add New User": {
      "main": [
        [
          {
            "node": "New User Defaults",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New User Defaults": {
      "main": [
        [
          {
            "node": "Prepare User Data Unified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check and Reset Monthly Limit": {
      "main": [
        [
          {
            "node": "Need Donation Reminder?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Need Donation Reminder?": {
      "main": [
        [
          {
            "node": "Prepare Donation Reminder Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Donation Reminder Message": {
      "main": [
        [
          {
            "node": "Send Donation Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Command": {
      "main": [
        [
          {
            "node": "Check Message Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Command": {
      "main": [
        [
          {
            "node": "Send Command Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare User Data Unified": {
      "main": [
        [
          {
            "node": "Check and Reset Monthly Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Message Limit": {
      "main": [
        [
          {
            "node": "IF Limit Exceeded?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Limit Exceeded?": {
      "main": [
        [
          {
            "node": "Prepare Limit Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare GPT Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Limit Message": {
      "main": [
        [
          {
            "node": "Send Limit Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare GPT Prompt": {
      "main": [
        [
          {
            "node": "OpenAI GPT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT": {
      "main": [
        [
          {
            "node": "Extract GPT Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract GPT Reply": {
      "main": [
        [
          {
            "node": "Send GPT Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send GPT Reply": {
      "main": [
        [
          {
            "node": "Increment Message Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Increment Message Count": {
      "main": [
        [
          {
            "node": "Google Sheets: Update User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d4e438f-9d7f-4207-b53a-1ad2f3097834",
  "meta": {
    "instanceId": "82215e1cd813d80b98891916892f6351ce965a27979285cf5a4eddf492767372"
  },
  "id": "W72244uOYe58SE1U",
  "tags": []
}