{
  "id": "SoJXbESQ4lWQWcVt",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Strava Social Manager (AI Title & Description Generation)",
  "tags": [
    {
      "id": "NabIyPgRf7ZggE5B",
      "name": "Showcase",
      "createdAt": "2025-06-03T15:41:30.076Z",
      "updatedAt": "2025-06-03T15:41:30.076Z"
    }
  ],
  "nodes": [
    {
      "id": "58ef8481-49d7-4522-9797-f191db60fa33",
      "name": "Combine Everything",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        340
      ],
      "parameters": {
        "jsCode": "// Recursive function to flatten JSON into a single string\nfunction flattenJson(obj, prefix = '') {\n    let str = '';\n    for (const key in obj) {\n        if (typeof obj[key] === 'object' && obj[key] !== null) {\n            str += flattenJson(obj[key], `${prefix}${key}.`);\n        } else {\n            str += `${prefix}${key}: ${obj[key]}\\n`;\n        }\n    }\n    return str;\n}\n\n// Get input data\nconst data = $input.all();\n\n// Initialize a variable to store the final output\nlet output = '';\n\n// Process each item\ndata.forEach(item => {\n    output += flattenJson(item.json);\n    output += '\\n---\\n'; // Separator between records\n});\n\n// Return the merged string as output\nreturn [{ json: { data: output } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d81a3699-09c6-4114-ad6e-652ce34854e8",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        -300,
        340
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "ee87a5ae-331f-4066-84e8-43acdfaaf038",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        160,
        520
      ],
      "parameters": {
        "model": "deepseek/deepseek-r1:free",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7690c43e-282c-4fc6-af91-ba468040fdba",
      "name": "Strava Trigger",
      "type": "n8n-nodes-base.stravaTrigger",
      "position": [
        -520,
        340
      ],
      "parameters": {
        "event": "create",
        "object": "activity",
        "options": {}
      },
      "credentials": {
        "stravaOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b0dbf6f6-d3c9-43e3-997a-3593229e891e",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        520,
        340
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fe37d921-5f51-4809-8fa9-e93b0983a566",
              "name": "Name",
              "type": "string",
              "value": "={{ $json.output.split('\\n')[0].split(': ')[1] }}"
            },
            {
              "id": "528a732c-7b96-47c1-8c8e-4354258569d9",
              "name": "Description",
              "type": "string",
              "value": "={{ $json.output.split('\\n')[1].split(': ')[1] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "38316beb-1f92-43e5-ac48-ac982be6407f",
      "name": "Strava",
      "type": "n8n-nodes-base.strava",
      "position": [
        740,
        340
      ],
      "parameters": {
        "operation": "update",
        "activityId": "={{ $('Strava Trigger').item.json.object_id }}",
        "updateFields": {
          "name": "={{ $json.Name }}",
          "description": "={{ $json.Description }}"
        }
      },
      "credentials": {
        "stravaOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "4be1f7de-7f50-45fb-8aa0-4707d25a23fb",
      "name": "Strava Social Manager",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        140,
        340
      ],
      "parameters": {
        "text": "=Tu es un assistant virtuel passionn\u00e9 de cyclisme.  \n\u00c0 partir des informations ci-dessous sur ma sortie v\u00e9lo, g\u00e9n\u00e8re\u202f:\n- Un **titre accrocheur** (max 10 mots), original et adapt\u00e9 au contexte de la sortie.\n- Une **description** motivante, d\u00e9taill\u00e9e et personnalis\u00e9e (3 \u00e0 5 phrases), qui met en valeur les aspects marquants de la sortie (lieux travers\u00e9s, m\u00e9t\u00e9o, performance, sensations, anecdotes, etc.).  \n\nUtilise un ton positif, dynamique et inspirant, comme si tu \u00e9crivais pour un carnet d\u2019aventure cycliste.  \n\n**Donn\u00e9es de la sortie\u202f:**\n- Distance\u202f: [X] km\n- Dur\u00e9e\u202f: [X] h [X] min\n- D\u00e9nivel\u00e9\u202f: [X] m\n- Vitesse moyenne\u202f: [X] km/h\n- Lieu/d\u00e9part\u202f: [Ville/lieu]\n- M\u00e9t\u00e9o\u202f: [ensoleill\u00e9, pluvieux, vent, etc.]\n- Ressenti\u202f: [facile, difficile, super sensations, etc.]\n- Particularit\u00e9s\u202f: [d\u00e9couverte d\u2019un nouveau parcours, sortie en groupe, crevaison, etc.]\n\n**Format attendu\u202f:**\n```\nTitre\u202f: [Titre g\u00e9n\u00e9r\u00e9]\nDescription\u202f: [Description g\u00e9n\u00e9r\u00e9e]\n```\n\n---\n\nVoici les donn\u00e9es de l'activit\u00e9 : \n{{ $json.data }}",
        "agent": "conversationalAgent",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "f2941949-f743-4214-88a6-37899770e4df",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -940,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 340,
        "height": 680,
        "content": "### **Step 0 \u2013 Connecting to the Strava API**\nBefore anything else, connect your Strava account to n8n via OAuth2:\n- Go to **Credentials** > **Strava OAuth2 API** in n8n.\n- Enter the Client ID and Client Secret obtained from the Strava developer portal.\n- Authorize the necessary scopes (`activity:read_all`, `activity:write`).\n- This connection allows n8n to securely access and modify your Strava activities.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "885370b1-7f2f-4411-b35e-3090dcbec2b8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        0
      ],
      "parameters": {
        "width": 220,
        "height": 680,
        "content": "### **Step 1 \u2013 Strava Trigger**\nThis node automatically monitors the creation of new activities on your Strava account.\n- For each new activity, it retrieves all associated data (distance, duration, elevation gain, etc.).\n- It serves as the workflow\u2019s entry point and passes the raw activity data to the next steps."
      },
      "typeVersion": 1
    },
    {
      "id": "28121d2d-ddd0-422b-b56d-099a32708216",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        0
      ],
      "parameters": {
        "width": 420,
        "height": 680,
        "content": "### **Step 2a \u2013 Data Processing (Code)**\nA Code node (JavaScript) adds or modifies fields in the activity data.\n- Example: Adding a custom field `myNewField` to enrich or prepare the data for use by the AI or other nodes.\n\n### **Step 2b \u2013 Data Flattening and Formatting (Combine Everything)**\nThis Code node \"flattens\" the complex Strava activity JSON structure into a simple text string.\n- It makes the data easily usable by the AI by presenting it as a readable, well-structured text.\n- Each activity key/value is listed on a line, making contextual analysis easier."
      },
      "typeVersion": 1
    },
    {
      "id": "fb1139ae-b154-49fa-a2f0-dd9e1d440f17",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        0
      ],
      "parameters": {
        "width": 340,
        "height": 680,
        "content": "### **Step 3 \u2013 AI Generation of Title and Description (Strava Social Manager)**\nThis node calls an AI agent (via OpenRouter or other service) with a detailed prompt:\n- It sends the activity data (flattened previously) to the AI.\n- The AI generates a catchy title and a personalized description, inspired by the context, performance, and highlights of the ride.\n- The prompt is designed to get an inspiring result tailored to the cycling community."
      },
      "typeVersion": 1
    },
    {
      "id": "c2897c26-5e64-44a4-8201-12f25f3a8e13",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        0
      ],
      "parameters": {
        "height": 680,
        "content": "### **Step 4 \u2013 Extracting AI Results (Edit Fields)**\nThe Set node extracts the AI-generated title and description from the output text.\n- It splits the text to isolate the title and description, storing them in separate fields.\n- This step prepares the data for updating on Strava.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "88418116-adc3-4438-8fa5-0fbfd399495b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        0
      ],
      "parameters": {
        "height": 680,
        "content": "### **Step 5 \u2013 Automatic Update of the Activity on Strava**\nThe Strava node updates the relevant activity with the generated title and description.\n- It uses the activity ID provided by the initial trigger.\n- The `name` (title) and `description` fields are updated directly on Strava, making the ride more attractive and personalized."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "faf93495-ffbf-40f8-8dfe-89be52af5ba1",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Combine Everything",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Strava",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Strava Trigger": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Everything": {
      "main": [
        [
          {
            "node": "Strava Social Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Strava Social Manager",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Strava Social Manager": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}