Files
agents/n8n-bale-publicchat-file-fetch/json/Bale Metro File Agent (client-auth demo).json
2026-08-30 22:30:31 +03:30

176 lines
5.4 KiB
JSON

{
"name": "Bale Metro File Agent (client-auth demo)",
"nodes": [
{
"parameters": {
"options": {}
},
"id": "6bb427a1-bb35-4742-93e6-ebb320950224",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"typeVersion": 1.1,
"position": [
3344,
384
],
"webhookId": "fdae82fa-cb2d-4d9a-83ba-4ae9bddd0a6e"
},
{
"parameters": {
"method": "POST",
"url": "https://api.bazaarlink.ai/v1/chat/completions",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer sk-bl-RszuRzm4SBYwRapwenmPDyHMNZnxVkZ3w8UxtNPArWTFos23"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ model: \"auto:free\", messages: [ { role: \"system\", content: \"You extract a single short search keyword describing the file the user wants. IMPORTANT: the files you are searching are Bale bot messages with Persian (Farsi) captions and filenames -- no matter what language the user writes in, output the keyword translated into a plausible Persian word likely to appear in that caption (e.g. a request for 'the metro map' should become the keyword 'نقشه' or 'خطوط', not 'map'). Reply with ONLY compact JSON like {\\\"keyword\\\":\\\"خطوط\\\"}. No prose, no markdown fences.\" }, { role: \"user\", content: $json.chatInput } ] }) }}",
"options": {}
},
"id": "47b99f54-f43e-4a16-b281-5a20bf8150a5",
"name": "Parse request (LLM)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
3792,
384
]
},
{
"parameters": {
"jsCode": "let raw = $input.first().json.choices[0].message.content.trim();\nraw = raw.replace(/^```json\\s*/i, '').replace(/^```\\s*/i, '').replace(/```\\s*$/i, '');\nconst parsed = JSON.parse(raw);\nreturn [{ json: parsed }];"
},
"id": "1156dfdb-4cae-49fb-92c2-cfaa35ff86e0",
"name": "Extract keyword",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
4016,
384
]
},
{
"parameters": {
"command": "=python3 /mnt/storage/bale-downloads/fetch_metro_smart.py \"{{ $json.keyword }}\""
},
"id": "ede1882a-c5df-4074-a1a0-4bfac8dca00e",
"name": "Run client-auth fetch",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
4240,
384
],
"notes": "Runs fetch_metro_smart.py, passing the LLM-parsed keyword through. The script searches this bot chat's full history for a document whose filename/caption matches the keyword -- it does NOT send a new command, it decides from what's already there."
},
{
"parameters": {
"jsCode": "const result = JSON.parse($input.first().json.stdout);\nconst files = result.files || [];\nreturn [{ json: {\n found: files.length,\n files,\n summary: files.length\n ? `Found ${files.length} file(s):\\n` + files.join('\\n')\n : 'No file in this chat\\'s history matched that description.'\n} }];"
},
"id": "18f2ad30-f652-45a1-a825-b57183d498ca",
"name": "Parse results",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
4464,
384
]
},
{
"parameters": {
"fileSelector": "={{ $json.files[0] }}",
"options": {}
},
"id": "95ca5a02-c89c-4b90-b476-69f1b3382de9",
"name": "Save to disk",
"type": "n8n-nodes-base.readWriteFile",
"typeVersion": 1,
"position": [
4688,
384
],
"notes": "The file is already on disk (the Python script wrote it). This node just reads it back so n8n shows the binary preview + Download button, same as the original Bot-API demo -- purely visual."
}
],
"pinData": {},
"connections": {
"When chat message received": {
"main": [
[
{
"node": "Parse request (LLM)",
"type": "main",
"index": 0
}
]
]
},
"Parse request (LLM)": {
"main": [
[
{
"node": "Extract keyword",
"type": "main",
"index": 0
}
]
]
},
"Extract keyword": {
"main": [
[
{
"node": "Run client-auth fetch",
"type": "main",
"index": 0
}
]
]
},
"Run client-auth fetch": {
"main": [
[
{
"node": "Parse results",
"type": "main",
"index": 0
}
]
]
},
"Parse results": {
"main": [
[
{
"node": "Save to disk",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1",
"binaryMode": "separate",
"availableInMCP": false
},
"versionId": "a1d3946d-dfda-478a-93eb-e11cb88d4722",
"meta": {
"instanceId": "a8618b8efe9a0b8c68300d12dc12f140ace3ebe855b80198b7819ca3e0922fe9"
},
"nodeGroups": [],
"id": "L9iWiHBHGxQZDvGU",
"tags": []
}