This workflow corresponds to n8n.io template #9987 — we link there as the canonical source.
This workflow follows the Agent → Datatable recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"nodes": [
{
"id": "2dabfa67-8f0b-4662-a929-df1e5bb7037e",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
16,
448
],
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "b952c1e1-1377-4205-9c92-0702cac12708",
"name": "Configuration",
"type": "n8n-nodes-base.set",
"position": [
608,
528
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "4439ddcb-8bf4-4f40-8461-02f8ba5795d9",
"name": "user",
"type": "string",
"value": "={{ $('Telegram Trigger').item.json.message.from.id }}"
},
{
"id": "c7c23d1c-8325-485a-82b3-784a45f0c7cc",
"name": "smtp",
"type": "string",
"value": "SMTP_ACCOUNT_MAIL"
},
{
"id": "a20a4051-2916-4072-a156-6cc9efeb18d4",
"name": "operator",
"type": "string",
"value": "OPERATOR_MAIL"
},
{
"id": "b94071df-a56f-4ee7-a260-536924518fcb",
"name": "personal",
"type": "string",
"value": "YOUR_PERSONAL_ID(TELEGRAM)"
},
{
"id": "6e49c76e-3308-4691-8996-a98b4e1fcbd8",
"name": "group",
"type": "string",
"value": "GROUP_ID"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "894b9666-fa3f-485c-8330-4890542c65e2",
"name": "Confirm Operator",
"type": "n8n-nodes-base.telegram",
"position": [
1680,
480
],
"parameters": {
"chatId": "={{ $('Configuration').item.json.user }}",
"message": "Confirm switching to operator?",
"options": {
"appendAttribution": false
},
"operation": "sendAndWait",
"approvalOptions": {
"values": {
"approvalType": "double"
}
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "d82fb377-0efe-43a7-ae6f-73d577b0e3c9",
"name": "User Approved",
"type": "n8n-nodes-base.if",
"position": [
1856,
480
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "85d3c27f-d003-4d7c-b0ff-65574db8385c",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.data.approved }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "4e9e61ed-ba5c-4450-8ee7-f9ea832ba16d",
"name": "Alert Operator",
"type": "n8n-nodes-base.emailSend",
"position": [
2048,
416
],
"parameters": {
"message": "=User called {{ $('Telegram Trigger').item.json.message.from.username }} has requested an operator in Telegram chat. Please approve this message if the operator will be attending.\n\n**This message will expire in 15 minutes.**\n",
"options": {
"limitWaitTime": {
"values": {
"resumeUnit": "minutes",
"resumeAmount": 15
}
},
"appendAttribution": false
},
"subject": "User Requires Attention",
"toEmail": "={{ $('Configuration').item.json.operator }}",
"fromEmail": "={{ $('Configuration').item.json.smtp }}",
"operation": "sendAndWait",
"approvalOptions": {
"values": {
"approveLabel": "Create Topic"
}
}
},
"credentials": {
"smtp": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "ba253ae3-9c3f-49b9-be17-38c039cf75b6",
"name": "OpenRouter Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
1184,
768
],
"parameters": {
"model": "x-ai/grok-4-fast",
"options": {}
},
"credentials": {
"openRouterApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "3e5cf322-3f81-460e-8d69-8814c518d504",
"name": "Operator Confirmed",
"type": "n8n-nodes-base.if",
"position": [
2224,
416
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "d06816f2-6906-4167-a7f5-acb348f5678c",
"operator": {
"type": "boolean",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.data.approved }}",
"rightValue": ""
},
{
"id": "524fefa4-f84b-4725-8500-f8ed9b788bd0",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.data.approved }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "4bfcbf4e-1b16-4993-8b9a-1711fcda85f1",
"name": "Operator Attendance",
"type": "n8n-nodes-base.telegram",
"position": [
2416,
336
],
"parameters": {
"text": "Operator will be with you shortly.",
"chatId": "={{ $('Configuration').item.json.user }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "111c38e7-f287-4414-9e8c-6040f322ad1a",
"name": "Operator Declined Attendance",
"type": "n8n-nodes-base.telegram",
"position": [
2416,
496
],
"parameters": {
"text": "Unfortunately, the operator is not free at the moment.",
"chatId": "={{ $('Configuration').item.json.user }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "e48beba6-5267-489a-a929-0f8b019f5919",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1184,
608
],
"parameters": {
"text": "={{ $('Telegram Trigger').item.json.message.text }}",
"options": {
"systemMessage": "You are a helpful assistant on Telegram platform. To reply to users, call 'Reply to User' tool.\n\n**Critical: Call 'Reply to User' tool once.\n\n**Critical: When users ask to chat with a human agent, reply with 'Human' instead, with no punctuation marks. Do not call the 'Reply To User' tool in this case.**"
},
"promptType": "define",
"needsFallback": true
},
"typeVersion": 2.2
},
{
"id": "8cfdfc0a-893c-4b6c-99df-b3254ad809a4",
"name": "Simple Memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
1280,
1104
],
"parameters": {
"sessionKey": "={{ $('Configuration').item.json.user }}",
"sessionIdType": "customKey"
},
"typeVersion": 1.3
},
{
"id": "4016ffe6-e825-4f92-95b2-082dec181696",
"name": "Reply To User",
"type": "n8n-nodes-base.telegramTool",
"position": [
1328,
800
],
"parameters": {
"text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Text', `Reply message to be sent to user.`, 'string') }}",
"chatId": "={{ $('Configuration').item.json.user }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "a8033517-b6e8-44f9-87d2-2a228f396245",
"name": "Human Requested",
"type": "n8n-nodes-base.if",
"position": [
1488,
608
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2c353a33-ef9c-4ef5-b019-7875e8f80d85",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output }}",
"rightValue": "Human"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "bfe3aa80-2b10-4dd2-8544-e9456a37d0a0",
"name": "Azure OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
"position": [
1232,
928
],
"parameters": {
"model": "gpt-4o-mini",
"options": {}
},
"credentials": {
"azureOpenAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "6dca4f2a-7f5a-49e3-93a2-e3ed0b21b14a",
"name": "Update Last Message",
"type": "n8n-nodes-base.dataTable",
"position": [
2048,
816
],
"parameters": {
"columns": {
"value": {
"type": "ai"
},
"schema": [
{
"id": "type",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "type",
"defaultMatch": false
},
{
"id": "user",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "user",
"defaultMatch": false
},
{
"id": "topic",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "topic",
"defaultMatch": false
},
{
"id": "status",
"type": "string",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "status",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"filters": {
"conditions": [
{
"keyName": "user",
"keyValue": "={{ $('Configuration').item.json.user }}"
}
]
},
"options": {},
"operation": "update",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1
},
{
"id": "84786a93-07fe-47ac-96f5-54f4a2c76e83",
"name": "Last Message Exists",
"type": "n8n-nodes-base.dataTable",
"position": [
1680,
736
],
"parameters": {
"filters": {
"conditions": [
{
"keyName": "user",
"keyValue": "={{ $('Configuration').item.json.user }}"
},
{
"keyName": "status",
"keyValue": "open"
}
]
},
"operation": "rowExists",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "a27e8718-7b93-4460-9183-c80453158b54",
"name": "Row is Empty",
"type": "n8n-nodes-base.if",
"position": [
1856,
736
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "76c55b53-23a0-4afc-8250-e3d230286d61",
"operator": {
"type": "object",
"operation": "empty",
"singleValue": true
},
"leftValue": "={{ $json }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "539e9e73-006b-4ef0-8dc3-ee3c2bcaf27e",
"name": "Create Temporary Message",
"type": "n8n-nodes-base.dataTable",
"position": [
2048,
656
],
"parameters": {
"columns": {
"value": {
"type": "ai",
"user": "={{ $('Configuration').item.json.user }}",
"status": "open"
},
"schema": [
{
"id": "type",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "type",
"defaultMatch": false
},
{
"id": "user",
"type": "number",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "user",
"defaultMatch": false
},
{
"id": "topic",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "topic",
"defaultMatch": false
},
{
"id": "status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "status",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1
},
{
"id": "0055bb76-2c3c-49ad-8381-21b951bfa3a0",
"name": "Update Temporary Message",
"type": "n8n-nodes-base.dataTable",
"position": [
2784,
336
],
"parameters": {
"columns": {
"value": {
"type": "human",
"topic": "={{ $json.result.message_thread_id }}",
"status": "open"
},
"schema": [
{
"id": "type",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "type",
"defaultMatch": false
},
{
"id": "user",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "user",
"defaultMatch": false
},
{
"id": "topic",
"type": "number",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "topic",
"defaultMatch": false
},
{
"id": "status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "status",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"filters": {
"conditions": [
{
"keyName": "user",
"keyValue": "={{ $('Configuration').item.json.user }}"
}
]
},
"options": {},
"operation": "update",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1
},
{
"id": "491171e9-75d7-429b-a280-2d099d9d6ab3",
"name": "Get Temporary Message",
"type": "n8n-nodes-base.dataTable",
"position": [
784,
528
],
"parameters": {
"filters": {
"conditions": [
{
"keyName": "user",
"keyValue": "={{ $json.user }}"
},
{
"keyName": "status",
"keyValue": "open"
}
]
},
"matchType": "allConditions",
"operation": "get",
"returnAll": true,
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "ba334b52-a555-4d95-9eae-a840f5dbfd84",
"name": "Message Router",
"type": "n8n-nodes-base.switch",
"position": [
976,
512
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "human",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2d381ff5-c197-4de5-90ab-43e1163d8f74",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.type }}",
"rightValue": "human"
}
]
},
"renameOutput": true
},
{
"outputKey": "empty",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "ca6f18b7-cc9f-4058-b134-f6cb731a0bd6",
"operator": {
"type": "object",
"operation": "empty",
"singleValue": true
},
"leftValue": "={{ $json }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "ai",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "4a69a2ff-9ee3-476d-bef9-b82a7fe673a7",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.type }}",
"rightValue": "ai"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.3
},
{
"id": "4183f326-c94f-46ad-a86f-30aee2edcd7e",
"name": "Personal",
"type": "n8n-nodes-base.set",
"position": [
3280,
736
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "4439ddcb-8bf4-4f40-8461-02f8ba5795d9",
"name": "personal",
"type": "string",
"value": "={{ $json.message.from.id }}"
},
{
"id": "899b32df-0124-4751-a09b-21e0afa9b3e6",
"name": "group",
"type": "string",
"value": "={{ $json.message.chat.id }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "befed495-26fc-45d4-a8d6-66d6b314b201",
"name": "Create Topic",
"type": "n8n-nodes-base.httpRequest",
"position": [
2592,
336
],
"parameters": {
"url": "https://api.telegram.org/botBOT_TOKEN/createForumTopic",
"options": {},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "chat_id",
"value": "={{ $('Configuration').item.json.group }}"
},
{
"name": "name",
"value": "={{ $('Configuration').item.json.user }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "72ce66dd-e1b0-4d97-9b69-1337f8c2d01a",
"name": "Text Message",
"type": "n8n-nodes-base.if",
"position": [
400,
608
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "10537cf3-851f-48c1-94cb-739a47f0cd58",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.message.text }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "13e7a069-6cdd-485e-bdf9-48e3fd55e19e",
"name": "Stop Workflow",
"type": "n8n-nodes-base.noOp",
"position": [
608,
688
],
"parameters": {},
"typeVersion": 1
},
{
"id": "b5a3d335-b762-4331-a051-3d75e5258788",
"name": "Forward Message To Group",
"type": "n8n-nodes-base.httpRequest",
"position": [
1184,
432
],
"parameters": {
"url": "https://api.telegram.org/botBOT_TOKEN/forwardMessage",
"options": {},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "chat_id",
"value": "={{ $('Configuration').item.json.group }}"
},
{
"name": "from_chat_id",
"value": "={{ $('Configuration').item.json.user }}"
},
{
"name": "message_id",
"value": "={{ $('Telegram Trigger').item.json.message.message_id }}"
},
{
"name": "message_thread_id",
"value": "={{ $('Get Temporary Message').item.json.topic }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "a90da098-55c7-4d79-8cd9-438cdaff33ff",
"name": "Topic Message",
"type": "n8n-nodes-base.if",
"position": [
176,
448
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "d5a195e5-5d30-4404-897c-972154ae4776",
"operator": {
"type": "boolean",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.message.is_topic_message }}",
"rightValue": ""
},
{
"id": "1ca6b333-5a2e-4196-98da-ddb9c81a0d74",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.message.is_topic_message }}",
"rightValue": ""
},
{
"id": "e07c655e-c4ae-4883-bc15-a39ee6e6dd93",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.message.text }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "29fe28b7-3973-41ec-b9c4-c04ce6f9496a",
"name": "Chat Admins",
"type": "n8n-nodes-base.httpRequest",
"position": [
3200,
1024
],
"parameters": {
"url": "https://api.telegram.org/botYOUR_TOKEN/getChatAdministrators",
"options": {},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "chat_id",
"value": "=GROUP_ID"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "e64ca366-4c82-4693-90b0-75e36f2775a3",
"name": "Forward Message",
"type": "n8n-nodes-base.httpRequest",
"position": [
608,
368
],
"parameters": {
"url": "https://api.telegram.org/botBOT_TOKEN/forwardMessage",
"options": {},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "chat_id",
"value": "={{ $('Telegram Trigger').item.json.message.reply_to_message.forum_topic_created.name }}"
},
{
"name": "from_chat_id",
"value": "={{ $('Telegram Trigger').item.json.message.reply_to_message.chat.id }}"
},
{
"name": "message_id",
"value": "={{ $('Telegram Trigger').item.json.message.message_id }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "b5f03bf1-d898-4b3b-bbaf-bf7092100420",
"name": "Personal Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"disabled": true,
"position": [
3136,
736
],
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "ce4fd19f-1ee3-4932-a43c-0838e5f95a4e",
"name": "Exit",
"type": "n8n-nodes-base.if",
"position": [
400,
288
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "bc53c1d9-bfee-40f8-8cbf-f78757526fa1",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
"rightValue": "exit"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "420d646c-8db9-4c61-9517-42ec946bd4e8",
"name": "Close Topic",
"type": "n8n-nodes-base.httpRequest",
"position": [
608,
192
],
"parameters": {
"url": "https://api.telegram.org/botBOT_TOKEN/closeForumTopic",
"options": {},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "chat_id",
"value": "={{ $('Telegram Trigger').item.json.message.reply_to_message.chat.id }}"
},
{
"name": "message_thread_id",
"value": "={{ $('Telegram Trigger').item.json.message.reply_to_message.message_thread_id }}"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "ada57ab7-782d-4bcf-8c24-3e68afd8aa37",
"name": "Update Closed Topic",
"type": "n8n-nodes-base.dataTable",
"position": [
784,
192
],
"parameters": {
"columns": {
"value": {
"status": "closed"
},
"schema": [
{
"id": "type",
"type": "string",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "type",
"defaultMatch": false
},
{
"id": "user",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "user",
"defaultMatch": false
},
{
"id": "topic",
"type": "number",
"display": true,
"removed": true,
"readOnly": false,
"required": false,
"displayName": "topic",
"defaultMatch": false
},
{
"id": "status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "status",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"filters": {
"conditions": [
{
"keyName": "topic",
"keyValue": "={{ $('Telegram Trigger').item.json.message.reply_to_message.message_thread_id }}"
}
]
},
"options": {},
"operation": "update",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "nSoKY9F43bObeGqD",
"cachedResultUrl": "/projects/M1iORETinbUGzqtC/datatables/nSoKY9F43bObeGqD",
"cachedResultName": "Temporary Last Message"
}
},
"typeVersion": 1
},
{
"id": "120db6ad-faf1-4117-82ab-f878d6bc37dd",
"name": "Sticky Note17",
"type": "n8n-nodes-base.stickyNote",
"position": [
2336,
1200
],
"parameters": {
"color": 5,
"width": 1680,
"height": 80,
"content": "# Credentials"
},
"typeVersion": 1
},
{
"id": "7dca3dc6-3735-49c6-85fd-10b4a4f3326b",
"name": "Sticky Note18",
"type": "n8n-nodes-base.stickyNote",
"position": [
2976,
272
],
"parameters": {
"color": 6,
"width": 560,
"height": 928,
"content": "## Telegram - [Docs](https://docs.n8n.io/integrations/builtin/credentials/telegram/)\n\n### Bot Creation\n1. Message BotFather, create new bot and copy token.\n2. Paste token in n8n and save credentials. Name it something unique to identify it(e.g. Handover Bot). \n\n### Group Creation/Support UI\n1. Create a new group from Telegram dropdown menu. Go to Settings and enable Topics. Telegram will automatically create General topic.\n2. From Settings go to Administrators and add your bot as admin. Give 'Read and Manage Topics' permissions.\n\n### Related to Workflow\n\n- To get your group id and personal id deactivate main trigger and activate the one below. Send a message to your group and come back to executions tab. These ID's are required for Configuration node.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n- To check if the Bot is properly added to your group as admin(sometimes n8n doesn't see the bot as admin) execute the node below with correct parameters. Keep in mind that you have to add your Bot Token to all HTTP Request nodes."
},
"typeVersion": 1
},
{
"id": "9c27036e-b7eb-4e71-86ef-cbfbd93ae9ff",
"name": "Sticky Note19",
"type": "n8n-nodes-base.stickyNote",
"position": [
3568,
432
],
"parameters": {
"color": 6,
"width": 448,
"height": 768,
"content": "## Configuration Node\n\n### SMTP Mail - [Docs](https://docs.n8n.io/integrations/builtin/credentials/sendemail/#related-resources)\n- Type in the the SMTP email that you created the credential with.\n- Here is how to setup the credentials for Gmail:\n\n1. Enable 2FA if you haven't already.\n2. Generate an app password and copy it.\n3. In n8n credential page follow these steps:\n\n1. Enter your Gmail email address as the User.\n2. Enter the app password you copied as the Password.\n3. Enter smtp.gmail.com as the Host.\n4. For the Port:\nKeep the default 465 for SSL or if you're unsure what to use.\nEnter 587 for TLS.\n5. Turn on the SSL/TLS toggle.\n\n### Operator\n- Type in the mail address which will receive the alert. Topic will be created only if the mail is confirmed.\n\n### Personal\n- This parameter is not required. Currently not being used in the workflow. You can type it in and use expressions to test pinned data. Otherwise, remove it.\n\n### Group ID\n- Type in the group id that you received from 'Personal Trigger'. Usually starts with '-10...'. This parameter is required."
},
"typeVersion": 1
},
{
"id": "9543d11d-2d11-4785-8534-d952c5952f57",
"name": "Sticky Note20",
"type": "n8n-nodes-base.stickyNote",
"position": [
2336,
752
],
"parameters": {
"color": 6,
"width": 592,
"height": 448,
"content": "## Data Tables - n8n\n\n### Creating a Table\n1. From n8n dashboard go to data tables section. Create a new table.\n2. Add type(string), status(string), topic(number), user(number) columns. **Make sure that each column exists**, otherwise workflow will return an error.\n\n### Alternatives\n- Data tables in n8n are for development stage. If you wish to scale this workflow and work with much bigger data **use hosted databases** (Postgres, Redis etc.)\n\n### Notes\n\n- In this workflow template, data tables are being used to track chat type('human', 'ai' etc.). However when your operator types in 'exit' in the Telegram topic, this row is not deleted. Its status column updates to 'closed'. This is **close to having a ticket system** where each ticket is saved as a row inside a database."
},
"typeVersion": 1
},
{
"id": "0b52da6c-a05e-4b00-b981-01a4d61a2b68",
"name": "Sticky Note21",
"type": "n8n-nodes-base.stickyNote",
"position": [
576,
960
],
"parameters": {
"color": 4,
"width": 560,
"height": 384,
"content": "# Overview Video - 1 Minute\n[](https://youtu.be/U1HBdilbvzc)"
},
"typeVersion": 1
},
{
"id": "4478a416-f352-4f2b-924c-95a2cbdf18ca",
"name": "Sticky Note22",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
912
],
"parameters": {
"color": 4,
"width": 560,
"height": 432,
"content": "# Detailed Setup Video - 10 Minutes\n[](https://youtu.be/Rjj_g9HEuqw)"
},
"typeVersion": 1
},
{
"id": "55172322-f2fe-4245-996e-254ddfcef702",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-624,
192
],
"parameters": {
"color": 5,
"width": 576,
"height": 1152,
"content": "# Welcome\n\nTelegram Handover Template by [mookielian](https://n8n.io/creators/mookielian)!\n\n## Before You Start\n\nThis template requires **intermediate knowledge** of workflow logic and APIs. A detailed video guide is available, but please review each node and understand the basics before starting. Consider using the [Telegram Extended community node](https://www.npmjs.com/package/n8n-nodes-telegram-extended) for easier forum operations.\n\n## Quick Setup\n\n### 1. Prerequisites\n\nCreate a Telegram bot via BotFather, set up a group with Topics enabled, add your bot as admin, and prepare a data table with columns: `user`, `type`, `topic`, and `status`. Configure SMTP for operator email alerts.\n\n### 2. Key Nodes\n\n**Configuration Node**: Set operator email and Telegram group chat ID.\n\n**Telegram Trigger**: Connect bot credentials to receive all updates.\n\n**AI Agent**: Select your AI model and customize the system prompt while keeping critical headers. The \"Reply To User\" tool sends Telegram messages. Memory uses a 5-message buffer (upgrade to database for production).\n\n**Data Tables**: Ensure column names match exactly: `user`, `type`, `topic`, `status`.\n\n### 3. How It Works\n\nOperator messages in topics forward to users (\"exit\" closes topics). User DMs route based on status: new/AI users go to the AI agent, human status users forward to operator topics.\n\nHandover flow: AI detects need \u2192 asks user confirmation \u2192 emails operator \u2192 operator confirms \u2192 creates topic \u2192 updates status \u2192 notifies user.\n\n### 4. Production Checklist\n\n- Replace memory buffer with proper database\n- Customize AI system prompt for your use case\n- Test handover scenarios thoroughly\n- Set up monitoring and rate limiting\n\n**Note**: Currently text-only. File processing is blocked to save tokens but can be modified if needed."
},
"typeVersion": 1
}
],
"connections": {
"Exit": {
"main": [
[
{
"node": "Close Topic",
"type": "main",
"index": 0
}
],
[
{
"node": "Forward Message",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Human Requested",
"type": "main",
"index": 0
}
]
]
},
"Close Topic": {
"main": [
[
{
"node": "Update Closed Topic",
"type": "main",
"index": 0
}
]
]
},
"Create Topic": {
"main": [
[
{
"node": "Update Temporary Message",
"type": "main",
"index": 0
}
]
]
},
"Row is Empty": {
"main": [
[
{
"node": "Create Temporary Message",
"type": "main",
"index": 0
}
],
[
{
"node": "Update Last Message",
"type": "main",
"index": 0
}
]
]
},
"Text Message": {
"main": [
[
{
"node": "Configuration",
"type": "main",
"index": 0
}
],
[
{
"node": "Stop Workflow",
"type": "main",
"index": 0
}
]
]
},
"Configuration": {
"main": [
[
{
"node": "Get Temporary Message",
"type": "main",
"index": 0
}
]
]
},
"Reply To User": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Topic Message": {
"main": [
[
{
"node": "Exit",
"type": "main",
"index": 0
}
],
[
{
"node": "Text Message",
"type": "main",
"index": 0
}
]
]
},
"User Approved": {
"main": [
[
{
"node": "Alert Operator",
"type": "main",
"index": 0
}
],
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Alert Operator": {
"main": [
[
{
"node": "Operator Confirmed",
"type": "main",
"index": 0
}
]
]
},
"Message Router": {
"main": [
[
{
"node": "Forward Message To Group",
"type": "main",
"index": 0
}
],
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
],
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Human Requested": {
"main": [
[
{
"node": "Confirm Operator",
"type": "main",
"index": 0
}
],
[
{
"node": "Last Message Exists",
"type": "main",
"index": 0
}
]
]
},
"Confirm Operator": {
"main": [
[
{
"node": "User Approved",
"type": "main",
"index": 0
}
]
]
},
"Personal Trigger": {
"main": [
[
{
"node": "Personal",
"type": "main",
"index": 0
}
]
]
},
"Telegram Trigger": {
"main": [
[
{
"node": "Topic Message",
"type": "main",
"index": 0
}
]
]
},
"Operator Confirmed": {
"main": [
[
{
"node": "Operator Attendance",
"type": "main",
"index": 0
}
],
[
{
"node": "Operator Declined Attendance",
"type": "main",
"index": 0
}
]
]
},
"Last Message Exists": {
"main": [
[
{
"node": "Row is Empty",
"type": "main",
"index": 0
}
]
]
},
"Operator Attendance": {
"main": [
[
{
"node": "Create Topic",
"type": "main",
"index": 0
}
]
]
},
"Get Temporary Message": {
"main": [
[
{
"node": "Message Router",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Azure OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 1
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
azureOpenAiApiopenRouterApismtptelegramApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This is a Telegram AI-to-Human Handover System that seamlessly transitions customer support conversations between an AI agent and human operators: AI-First Response: When users message the Telegram bot, an AI agent handles the conversation initially, using memory to maintain…
Source: https://n8n.io/workflows/9987/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
AI-powered Telegram bot for effortless expense tracking. Send receipts, voice messages, or text - the bot automatically extracts and categorizes your expenses. 📸 Receipt & Invoice OCR - Send photos of
This workflow contains community nodes that are only compatible with the self-hosted version of n8n.
Pitch Paul. Uses lmChatOpenRouter, telegram, outputParserStructured, supabaseTool. Event-driven trigger; 33 nodes.
This workflow automates the process of recording financial transactions from photos of receipts or shopping receipts. Users simply send an image of the receipt via Telegram. The image is processed usi
This workflow creates an AI-powered Telegram bot that allows users to generate and modify images using Grok Imagine models via the Kie AI API.