{
  "name": "Moqi : recevoir les rappels",
  "nodes": [
    {
      "parameters": {
        "content": "## Recevoir les rappels de Moqi\n\n1. Copie la **Production URL** du nœud **Appel de Moqi** (elle existe avant la mise en production).\n2. Colle-la sur **moqi.fr/compte/api**, dans **Rappel automatique**. Moqi affiche un secret, une seule fois.\n3. Colle ce secret dans **Signature attendue**, champ Secret, à la place de `COLLE_ICI_LE_SECRET_DU_CROCHET`.\n4. Dans **Lire le découpage** et **Lire la création** : *Generic Credential Type*, puis *Header Auth*, Name `Authorization`, Value `Bearer ta_clé`.\n5. Enregistre, et seulement ensuite mets le workflow en production (Active ou Publish, selon ta version de n8n) : une retouche faite après peut rester en brouillon.\n\nChaque appel est vérifié avant d'être cru : sa signature, et son heure (5 minutes au plus). Tant que le secret d'exemple est en place, tout est refusé : ce modèle est public, son secret aussi. Ensuite le modèle relit le travail chez Moqi avec ta clé.\n\nSix évènements : découpage fini ou échoué, vidéo générée prête ou échouée, publication en ligne ou refusée. Une publication échouée avec `certaine: false` n'a pas eu de réponse du réseau : vérifie avant de la relancer. Remplace chaque nœud **Ton action** par ce que tu veux : Drive, Slack, Notion, un mail.",
        "height": 520,
        "width": 460,
        "color": 5
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f01",
      "name": "Mode d'emploi",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-600, -200]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "moqi-crochets",
        "options": {}
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f02",
      "name": "Appel de Moqi",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0],
      "webhookId": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f31"
    },
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ $json.headers['x-moqi-horodatage'] + '.' + JSON.stringify($json.body) }}",
        "dataPropertyName": "signature_attendue",
        "secret": "COLLE_ICI_LE_SECRET_DU_CROCHET",
        "encoding": "hex"
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f03",
      "name": "Signature attendue",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [220, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f21",
              "leftValue": "={{ 'sha256=' + $json.signature_attendue }}",
              "rightValue": "={{ String($json.headers['x-moqi-signature'] || '') }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f22",
              "leftValue": "={{ Math.abs($now.toSeconds() - Number($json.headers['x-moqi-horodatage'] || 0)) }}",
              "rightValue": 300,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            },
            {
              "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f26",
              "leftValue": "={{ String($('Signature attendue').params.secret || '') }}",
              "rightValue": "COLLE_ICI_LE_SECRET_DU_CROCHET",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f04",
      "name": "Appel authentique ?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [440, 0]
    },
    {
      "parameters": {},
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f05",
      "name": "Refusé, ni lu ni cru",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [660, 200]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f23",
                    "leftValue": "={{ $json.body.evenement }}",
                    "rightValue": "decoupage.fini",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "decoupage.fini"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f24",
                    "leftValue": "={{ $json.body.evenement }}",
                    "rightValue": "creation.prete",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "creation.prete"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f25",
                    "leftValue": "={{ $json.body.evenement }}",
                    "rightValue": "publication.publiee",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "publication.publiee"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Échec ou autre"
        }
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f06",
      "name": "Quel évènement ?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [660, -40]
    },
    {
      "parameters": {
        "url": "=https://moqi.fr/api/v1/decoupages/{{ $json.body.donnees.decoupage }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f07",
      "name": "Lire le découpage",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, -260]
    },
    {
      "parameters": {
        "fieldToSplitOut": "clips",
        "options": {}
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f08",
      "name": "Un élément par clip",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [1120, -260]
    },
    {
      "parameters": {},
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f09",
      "name": "Ton action pour chaque clip",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [1340, -260]
    },
    {
      "parameters": {
        "url": "=https://moqi.fr/api/v1/creations/{{ $json.body.donnees.creation }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f10",
      "name": "Lire la création",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, -100]
    },
    {
      "parameters": {},
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f11",
      "name": "Ton action pour la vidéo générée",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [1120, -100]
    },
    {
      "parameters": {},
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f12",
      "name": "Ton action quand c'est en ligne",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [900, 60]
    },
    {
      "parameters": {},
      "id": "6e2a1d2f-9b4c-4d3e-8f21-1b2c3d4e5f13",
      "name": "Ton action en cas d'échec",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [900, 220]
    }
  ],
  "connections": {
    "Appel de Moqi": {
      "main": [[{ "node": "Signature attendue", "type": "main", "index": 0 }]]
    },
    "Signature attendue": {
      "main": [[{ "node": "Appel authentique ?", "type": "main", "index": 0 }]]
    },
    "Appel authentique ?": {
      "main": [
        [{ "node": "Quel évènement ?", "type": "main", "index": 0 }],
        [{ "node": "Refusé, ni lu ni cru", "type": "main", "index": 0 }]
      ]
    },
    "Quel évènement ?": {
      "main": [
        [{ "node": "Lire le découpage", "type": "main", "index": 0 }],
        [{ "node": "Lire la création", "type": "main", "index": 0 }],
        [{ "node": "Ton action quand c'est en ligne", "type": "main", "index": 0 }],
        [{ "node": "Ton action en cas d'échec", "type": "main", "index": 0 }]
      ]
    },
    "Lire le découpage": {
      "main": [[{ "node": "Un élément par clip", "type": "main", "index": 0 }]]
    },
    "Un élément par clip": {
      "main": [[{ "node": "Ton action pour chaque clip", "type": "main", "index": 0 }]]
    },
    "Lire la création": {
      "main": [[{ "node": "Ton action pour la vidéo générée", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}
