Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shraey96/9a02522c8190eff8de6e48f11531a513 to your computer and use it in GitHub Desktop.

Select an option

Save shraey96/9a02522c8190eff8de6e48f11531a513 to your computer and use it in GitHub Desktop.
Conversational Telegram Bot with GPT-4o for Text and Voice Messages - This n8n workflow leverages a Telegram Message Trigger to activate an intelligent AI Agent capable o
{
"id": "RV4zArpzN5InxYND",
"meta": {
"instanceId": "1e9c5d216f82eece259bdabdf191aced054cce6456f87af0ff7807ca2b37638a",
"templateCredsSetupCompleted": true
},
"name": "Conversational Telegram Bot with GPT-4o for Text and Voice Messages",
"tags": [
{
"id": "hlEHEpOdSg5lhIqi",
"name": "Template",
"createdAt": "2025-06-05T15:35:52.689Z",
"updatedAt": "2025-06-05T15:35:52.689Z"
}
],
"nodes": [
{
"id": "a33e3f45-f16e-4107-937e-0ce1d230060f",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
-660,
-180
],
"webhookId": "912e007f-19d9-4b5a-a90e-12ba01c9978d",
"parameters": {
"updates": [
"message",
"*"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "credential-id",
"name": "telegramApi Credential"
}
},
"typeVersion": 1.2
},
{
"id": "e17f452c-4f9a-48f8-91a2-526260159676",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
520,
420
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o",
"cachedResultName": "gpt-4o"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "credential-id",
"name": "openAiApi Credential"
}
},
"typeVersion": 1.2
},
{
"id": "9b33ec46-8772-4bfb-a448-fea5a673bbaa",
"name": "Simple Memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
740,
460
],
"parameters": {
"sessionKey": "={{ $json.sessionId }}",
"sessionIdType": "customKey",
"contextWindowLength": 10
},
"typeVersion": 1.3
},
{
"id": "8cdd7ba8-c998-4ea7-b861-8dcaf12febfe",
"name": "Get Voice",
"type": "n8n-nodes-base.telegram",
"position": [
80,
0
],
"webhookId": "1962cd81-9991-4199-a78a-2250bf29631a",
"parameters": {
"fileId": "={{ $json.message.voice.file_id }}",
"resource": "file"
},
"credentials": {
"telegramApi": {
"id": "credential-id",
"name": "telegramApi Credential"
}
},
"typeVersion": 1.2
},
{
"id": "7fa34d0e-5215-44e5-b1d3-1e8abb5771ae",
"name": "Text Or Voice",
"type": "n8n-nodes-base.switch",
"position": [
-240,
-180
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Text",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "0a236099-525e-4748-a57d-8b8e2c63c48b",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.message.text }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "Voice",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "24b7e8b8-6fce-4ddc-94b6-30b852891995",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.message.voice.file_id }}",
"rightValue": ""
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "b90a586b-5d90-4f76-8e4e-bd44095f9aac",
"name": "Transcribe The Voice",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
280,
0
],
"parameters": {
"options": {},
"resource": "audio",
"operation": "transcribe"
},
"credentials": {
"openAiApi": {
"id": "credential-id",
"name": "openAiApi Credential"
}
},
"typeVersion": 1.8
},
{
"id": "587adf8a-2e69-4078-a603-84f0322207cb",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
720,
80
],
"parameters": {
"text": "={{ $json.message.text }}",
"options": {
"systemMessage": "=# Overview\nYou are a personal assistant that helps user to fulfill their request.\n\nWhen you are asked to perform a task on the current date, please use the current time and date: {{$now}}\n\n## Output\nYou should output the result and don't include any link. Just mentioned where you added it to."
},
"promptType": "define"
},
"typeVersion": 1.9
},
{
"id": "2455c7cb-f341-4891-9096-dc62116298c0",
"name": "Typing Action",
"type": "n8n-nodes-base.telegram",
"position": [
-240,
-360
],
"webhookId": "2479f7f8-6d54-4d45-921e-af6dcfae768e",
"parameters": {
"chatId": "={{ $json.message.chat.id }}",
"operation": "sendChatAction"
},
"credentials": {
"telegramApi": {
"id": "credential-id",
"name": "telegramApi Credential"
}
},
"typeVersion": 1.2
},
{
"id": "8c2b6195-6101-4652-848c-505d13a3c1d2",
"name": "Send Response To Telegram",
"type": "n8n-nodes-base.telegram",
"position": [
1340,
80
],
"webhookId": "76e4b8a4-1086-4d24-b60e-b96942d83bdf",
"parameters": {
"text": "={{ $json.output }}",
"chatId": "={{$('Telegram Trigger').first().json.message.chat.id}}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "credential-id",
"name": "telegramApi Credential"
}
},
"typeVersion": 1.2
},
{
"id": "c8fd047d-8575-484e-939a-46064b81d035",
"name": "Send Context To AI Agent",
"type": "n8n-nodes-base.set",
"position": [
460,
-200
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "590b803f-833c-4854-bde7-5241d25b2b32",
"name": "message.text",
"type": "string",
"value": "={{ $json.message.text }}"
},
{
"id": "303e0b5d-3d37-48fc-bbd3-ce62dbe7ef78",
"name": "sessionId",
"type": "string",
"value": "={{ $json.message.chat.id }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f7e90526-08a5-4a59-956f-d39e6ff472f0",
"name": "Send Transcribe Context To AI Agent",
"type": "n8n-nodes-base.set",
"position": [
460,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "2bb71aef-0ca1-4c26-95e1-c0c83bc82068",
"name": "message.text",
"type": "string",
"value": "={{ $json.text }}"
},
{
"id": "692a2bae-35da-41d3-be8d-32c0f5dfbbef",
"name": "sessionId",
"type": "string",
"value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
}
]
}
},
"typeVersion": 3.4
}
],
"active": false,
"pinData": {},
"settings": {
"timezone": "Australia/Sydney",
"callerPolicy": "workflowsFromSameOwner",
"executionOrder": "v1"
},
"versionId": "3a29c25b-e7bd-41a7-91ee-4438fa9c1c1a",
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Send Response To Telegram",
"type": "main",
"index": 0
}
]
]
},
"Get Voice": {
"main": [
[
{
"node": "Transcribe The Voice",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Text Or Voice": {
"main": [
[
{
"node": "Send Context To AI Agent",
"type": "main",
"index": 0
}
],
[
{
"node": "Get Voice",
"type": "main",
"index": 0
}
]
]
},
"Typing Action": {
"main": [
[]
]
},
"Telegram Trigger": {
"main": [
[
{
"node": "Text Or Voice",
"type": "main",
"index": 0
},
{
"node": "Typing Action",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Transcribe The Voice": {
"main": [
[
{
"node": "Send Transcribe Context To AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Send Context To AI Agent": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Send Transcribe Context To AI Agent": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment