From df9a4420e93210ec5f19178814d2975112b3d527 Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Wed, 4 Feb 2026 22:21:50 -0500 Subject: [PATCH] fix(batch): support text-based batch commands (not just keyboard) Text-based batch commands (e.g., /start container1 container2) were failing because Send Batch Start Message always used editMessageText, but you can't edit the user's message. Fixed by: - Conditionally use sendMessage vs editMessageText based on fromKeyboard - Capture new message_id from sendMessage response for progress updates Co-Authored-By: Claude Opus 4.5 --- n8n-workflow.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/n8n-workflow.json b/n8n-workflow.json index deab130..5769bbb 100644 --- a/n8n-workflow.json +++ b/n8n-workflow.json @@ -2875,10 +2875,10 @@ { "parameters": { "method": "POST", - "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText", + "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/{{ $json.fromKeyboard ? 'editMessageText' : 'sendMessage' }}", "sendBody": true, "specifyBody": "json", - "jsonBody": "={{ JSON.stringify({ chat_id: $json.chatId, message_id: $json.messageId, text: 'Batch ' + $json.action + '\\n\\nStarting ' + $json.action + ' for ' + $json.totalCount + ' containers...', parse_mode: 'HTML' }) }}", + "jsonBody": "={{ JSON.stringify($json.fromKeyboard ? { chat_id: $json.chatId, message_id: $json.messageId, text: 'Batch ' + $json.action + '\\n\\nStarting ' + $json.action + ' for ' + $json.totalCount + ' containers...', parse_mode: 'HTML' } : { chat_id: $json.chatId, text: 'Batch ' + $json.action + '\\n\\nStarting ' + $json.action + ' for ' + $json.totalCount + ' containers...', parse_mode: 'HTML' }) }}", "options": {} }, "id": "http-send-batch-start", @@ -2892,7 +2892,7 @@ }, { "parameters": { - "jsCode": "// Store progress message ID and prepare first iteration\nlet batchState;\ntry {\n batchState = $('Initialize Batch State').item.json;\n} catch (e) {\n throw new Error('Failed to get Initialize Batch State: ' + e.message);\n}\n\nif (!batchState || !batchState.containers || !Array.isArray(batchState.containers)) {\n throw new Error('Invalid batch state');\n}\n\n// Use the original messageId from Initialize Batch State\n// (we edit the batch select message in place)\nconst progressMessageId = batchState.messageId || null;\n\n// Return single item with all data for manual loop\n// We'll process containers[currentIndex] and increment\nreturn {\n json: {\n containers: batchState.containers,\n currentIndex: 0,\n container: batchState.containers[0],\n action: batchState.action,\n totalCount: batchState.totalCount,\n chatId: batchState.chatId,\n progressMessageId: progressMessageId,\n successCount: 0,\n failureCount: 0,\n warningCount: 0,\n results: [],\n fromKeyboard: batchState.fromKeyboard || false\n }\n};" + "jsCode": "// Store progress message ID and prepare first iteration\nlet batchState;\ntry {\n batchState = $('Initialize Batch State').item.json;\n} catch (e) {\n throw new Error('Failed to get Initialize Batch State: ' + e.message);\n}\n\nif (!batchState || !batchState.containers || !Array.isArray(batchState.containers)) {\n throw new Error('Invalid batch state');\n}\n\n// Get the message ID for progress updates\n// For keyboard: use original messageId (we edit in place)\n// For text commands: use the new message_id from sendMessage response\nlet progressMessageId;\nif (batchState.fromKeyboard) {\n progressMessageId = batchState.messageId;\n} else {\n // Get message_id from Send Batch Start Message response\n const sendResponse = $json;\n progressMessageId = sendResponse.result?.message_id || batchState.messageId;\n}\n\n// Return single item with all data for manual loop\n// We'll process containers[currentIndex] and increment\nreturn {\n json: {\n containers: batchState.containers,\n currentIndex: 0,\n container: batchState.containers[0],\n action: batchState.action,\n totalCount: batchState.totalCount,\n chatId: batchState.chatId,\n progressMessageId: progressMessageId,\n successCount: 0,\n failureCount: 0,\n warningCount: 0,\n results: [],\n fromKeyboard: batchState.fromKeyboard || false\n }\n};" }, "id": "code-prepare-batch-loop", "name": "Prepare Batch Loop",