diff --git a/workflows/command-router.json b/workflows/command-router.json new file mode 100644 index 0000000..9ca241b --- /dev/null +++ b/workflows/command-router.json @@ -0,0 +1,174 @@ +{ + "name": "Agentic Command Router", + "nodes": [ + { + "parameters": { + "httpMethod": "POST", + "path": "command", + "responseMode": "responseNode", + "options": {} + }, + "id": "webhook-1", + "name": "Webhook", + "type": "n8n-nodes-base.webhook", + "typeVersion": 2, + "position": [250, 300] + }, + { + "parameters": { + "jsCode": "// Parse incoming command from chat platforms +const body = $input.first().json.body; + +// Extract command and args +let message = ''; +let platform = 'unknown'; +let userId = ''; +let channelId = ''; + +// Zulip format +if (body.data) { + message = body.data.content || ''; + platform = 'zulip'; + userId = body.data.sender_id || ''; + channelId = body.data.stream_id || ''; +} +// Telegram format +else if (body.message) { + message = body.message.text || ''; + platform = 'telegram'; + userId = body.message.from?.id || ''; + channelId = body.message.chat?.id || ''; +} +// Slack format +else if (body.text) { + message = body.text || ''; + platform = 'slack'; + userId = body.user_id || ''; + channelId = body.channel_id || ''; +} + +// Parse command +const match = message.match(/^\/([a-z-]+)(?:\s+([a-z-]+))?(?:\s+(.*))?$/i); + +if (!match) { + return [{ json: { error: 'Invalid command format', message } }]; +} + +const [_, category, action, args] = match; + +return [{ + json: { + category: category.toLowerCase(), + action: action?.toLowerCase() || 'default', + args: args || '', + platform, + userId, + channelId, + rawMessage: message + } +}];" + }, + "id": "parse-command", + "name": "Parse Command", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [450, 300] + }, + { + "parameters": { + "rules": { + "rules": [ + { + "outputKey": "project", + "conditions": { + "options": { "caseSensitive": false }, + "conditions": [{ "leftValue": "={{ $json.category }}", "rightValue": "project", "operator": { "type": "string", "operation": "equals" } }] + } + }, + { + "outputKey": "code", + "conditions": { + "options": { "caseSensitive": false }, + "conditions": [{ "leftValue": "={{ $json.category }}", "rightValue": "code", "operator": { "type": "string", "operation": "equals" } }] + } + }, + { + "outputKey": "deploy", + "conditions": { + "options": { "caseSensitive": false }, + "conditions": [{ "leftValue": "={{ $json.category }}", "rightValue": "deploy", "operator": { "type": "string", "operation": "equals" } }] + } + }, + { + "outputKey": "sprint", + "conditions": { + "options": { "caseSensitive": false }, + "conditions": [{ "leftValue": "={{ $json.category }}", "rightValue": "sprint", "operator": { "type": "string", "operation": "equals" } }] + } + }, + { + "outputKey": "dt", + "conditions": { + "options": { "caseSensitive": false }, + "conditions": [{ "leftValue": "={{ $json.category }}", "rightValue": "dt", "operator": { "type": "string", "operation": "equals" } }] + } + } + ], + "fallbackOutput": "unknown" + } + }, + "id": "route-command", + "name": "Route Command", + "type": "n8n-nodes-base.switch", + "typeVersion": 3, + "position": [650, 300] + }, + { + "parameters": { + "method": "GET", + "url": "=https://gitea.mylder.io/admin/skills-library/raw/branch/main/skills/{{ $json.category }}/{{ $json.action }}.md", + "options": {} + }, + "id": "load-skill", + "name": "Load Skill", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [850, 200] + }, + { + "parameters": { + "respondWith": "json", + "responseBody": "={{ JSON.stringify({ status: 'success', command: $json.category + ' ' + $json.action, message: 'Command processed' }) }}" + }, + "id": "respond", + "name": "Respond", + "type": "n8n-nodes-base.respondToWebhook", + "typeVersion": 1.1, + "position": [1250, 300] + } + ], + "connections": { + "Webhook": { + "main": [[{ "node": "Parse Command", "type": "main", "index": 0 }]] + }, + "Parse Command": { + "main": [[{ "node": "Route Command", "type": "main", "index": 0 }]] + }, + "Route Command": { + "main": [ + [{ "node": "Load Skill", "type": "main", "index": 0 }], + [{ "node": "Load Skill", "type": "main", "index": 0 }], + [{ "node": "Load Skill", "type": "main", "index": 0 }], + [{ "node": "Load Skill", "type": "main", "index": 0 }], + [{ "node": "Load Skill", "type": "main", "index": 0 }], + [{ "node": "Respond", "type": "main", "index": 0 }] + ] + }, + "Load Skill": { + "main": [[{ "node": "Respond", "type": "main", "index": 0 }]] + } + }, + "settings": { + "executionOrder": "v1" + } +}