ceo-api/n8n-workflows/weekly-review.json

270 lines
No EOL
7.1 KiB
JSON

{
"name": "CEO OS — Weekly Review Generator",
"nodes": [
{
"id": "n1-trigger",
"name": "Every Monday 8:00",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1,
"position": [
0,
300
],
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 8 * * 1"
}
]
}
}
},
{
"id": "n1-vars",
"name": "Config",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"position": [
220,
300
],
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{
"id": "a1",
"name": "api",
"value": "={{$env['CEO_OS_API_URL'] ?? 'https://boardmind.dev/api'}}",
"type": "string"
},
{
"id": "a2",
"name": "tenantId",
"value": "={{$env['CEO_OS_TENANT_ID']}}",
"type": "string"
},
{
"id": "a3",
"name": "serviceKey",
"value": "={{$env['CEO_OS_SERVICE_KEY']}}",
"type": "string"
},
{
"id": "a4",
"name": "weekAgo",
"value": "={{DateTime.now().minus({days: 7}).toISO()}}",
"type": "string"
}
]
}
}
},
{
"id": "n1-get-tasks",
"name": "Get Completed Tasks",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
440,
200
],
"parameters": {
"url": "={{$json.api}}/v1/tasks?tenantId={{$json.tenantId}}&status=completed",
"method": "GET",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Service-Key",
"value": "={{$json.serviceKey}}"
}
]
}
}
},
{
"id": "n1-get-goals",
"name": "Get Active Goals",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
440,
400
],
"parameters": {
"url": "={{$('Config').item.json.api}}/v1/goals?tenantId={{$('Config').item.json.tenantId}}",
"method": "GET",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Service-Key",
"value": "={{$('Config').item.json.serviceKey}}"
}
]
}
}
},
{
"id": "n1-build-prompt",
"name": "Build Review Prompt",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
680,
300
],
"parameters": {
"jsCode": "const cfg = $('Config').item.json;\nconst tasks = $('Get Completed Tasks').all().map(i => i.json);\nconst goals = $('Get Active Goals').all().map(i => i.json);\n\nconst completedThisWeek = tasks.filter(t => {\n const d = new Date(t.completedAt || t.updatedAt || '');\n return Date.now() - d.getTime() < 7 * 86400000;\n});\n\nconst prompt = [\n `Generează o retrospectivă săptămânală pentru CEO OS. Data: ${new Date().toLocaleDateString('ro-RO')}.`,\n '',\n `## Task-uri finalizate săptămâna aceasta (${completedThisWeek.length}):`,\n ...completedThisWeek.slice(0, 20).map(t => `- ${t.title}`),\n '',\n `## Obiective active (${goals.length}):`,\n ...goals.slice(0, 10).map(g => `- ${g.title} [${g.progress ?? 0}%]`),\n '',\n 'Structurează răspunsul în: ✅ Ce am realizat, 🚀 Ce urmează, ⚠️ Blocaje, 💡 Lecții învățate. Max 300 cuvinte.',\n].join('\\n');\n\nreturn [{ json: {\n messages: [{ role: 'user', content: prompt }],\n context: JSON.stringify({ tenantId: cfg.tenantId, weeklyReview: true }),\n api: cfg.api,\n tenantId: cfg.tenantId,\n serviceKey: cfg.serviceKey,\n}}];"
}
},
{
"id": "n1-ai-ask",
"name": "Generate Review via Hermes",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
900,
300
],
"parameters": {
"url": "={{$json.api}}/v1/ai/ask",
"method": "POST",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Service-Key",
"value": "={{$json.serviceKey}}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\"messages\": {{JSON.stringify($json.messages)}}, \"context\": {{JSON.stringify($json.context)}}}"
}
},
{
"id": "n1-save-obs",
"name": "Save Weekly Review",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
1120,
300
],
"parameters": {
"url": "={{$('Build Review Prompt').item.json.api}}/v1/observations",
"method": "POST",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Service-Key",
"value": "={{$('Build Review Prompt').item.json.serviceKey}}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\"tenantId\": \"{{$('Build Review Prompt').item.json.tenantId}}\", \"metric\": \"weekly-review\", \"value\": {{JSON.stringify($json.reply)}}, \"subjectType\": \"review\", \"confidence\": 1}"
}
}
],
"connections": {
"Every Monday 8:00": {
"main": [
[
{
"node": "Config",
"type": "main",
"index": 0
}
]
]
},
"Config": {
"main": [
[
{
"node": "Get Completed Tasks",
"type": "main",
"index": 0
},
{
"node": "Get Active Goals",
"type": "main",
"index": 0
}
]
]
},
"Get Completed Tasks": {
"main": [
[
{
"node": "Build Review Prompt",
"type": "main",
"index": 0
}
]
]
},
"Get Active Goals": {
"main": [
[
{
"node": "Build Review Prompt",
"type": "main",
"index": 0
}
]
]
},
"Build Review Prompt": {
"main": [
[
{
"node": "Generate Review via Hermes",
"type": "main",
"index": 0
}
]
]
},
"Generate Review via Hermes": {
"main": [
[
{
"node": "Save Weekly Review",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"tags": [
{
"name": "ceo-os"
},
{
"name": "automation"
}
]
}