{
  "name": "Notion Client Portal — Purrly",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": 1,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": { "x": 0, "y": 0 },
        "restore": { "parameters": { "hook": { "label": "New Client Portal Webhook" } } },
        "parameters": [
          { "name": "hook", "type": "hook:gateway:CustomWebHook", "label": "Webhook" },
          { "name": "maxResults", "type": "number", "label": "Maximum number of results" }
        ]
      }
    },
    {
      "id": 2,
      "module": "notion:ActionQueryDatabase",
      "version": 1,
      "parameters": {
        "database": "[CLIENTS_DB]"
      },
      "mapper": {
        "databaseId": "[CLIENTS_DB]",
        "filter": {
          "property": "Status",
          "select": { "equals": "Portal Ready" }
        }
      },
      "metadata": {
        "designer": { "x": 300, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 3,
      "module": "notion:ActionCreatePage",
      "version": 1,
      "parameters": {},
      "mapper": {
        "parent": {
          "database_id": "[CLIENT_PORTALS_DB]"
        },
        "properties": {
          "Engagement": {
            "title": [
              {
                "type": "text",
                "text": {
                  "content": "{{2.results[0].properties.Engagement.title[0].text.content}}"
                }
              }
            ]
          },
          "Client": {
            "rich_text": [
              {
                "type": "text",
                "text": { "content": "{{2.results[0].properties.Name.title[0].text.content}}" }
              }
            ]
          },
          "Status": {
            "select": { "name": "Active" }
          },
          "Started": {
            "date": { "start": "{{formatDate(now; 'YYYY-MM-DD')}}" }
          }
        }
      },
      "metadata": {
        "designer": { "x": 600, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 4,
      "module": "notion:ActionCreatePage",
      "version": 1,
      "parameters": {},
      "mapper": {
        "parent": {
          "page_id": "[CLIENT_PORTAL_TEMPLATE_PAGE]"
        },
        "properties": {
          "title": [
            {
              "type": "text",
              "text": {
                "content": "{{2.results[0].properties.Engagement.title[0].text.content}} — Portal"
              }
            }
          ]
        }
      },
      "metadata": {
        "designer": { "x": 900, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 5,
      "module": "builtin:BasicAggregator",
      "version": 1,
      "parameters": {
        "aggregateMode": "array"
      },
      "mapper": {},
      "metadata": {
        "designer": { "x": 1200, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 6,
      "module": "notion:ActionAppendBlocks",
      "version": 1,
      "parameters": {},
      "mapper": {
        "pageId": "{{4.id}}",
        "blocks": [
          {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
              "rich_text": [{ "type": "text", "text": { "content": "Portal Landing" } }]
            }
          },
          {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
              "rich_text": [
                {
                  "type": "text",
                  "text": {
                    "content": "{{2.results[0].properties.Name.title[0].text.content}} — engagement kickoff. This portal is the single source of truth for the engagement: brief, files, decisions, and live status."
                  }
                }
              ]
            }
          },
          {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
              "rich_text": [{ "type": "text", "text": { "content": "Brief Summary" } }]
            }
          },
          {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
              "rich_text": [
                {
                  "type": "text",
                  "text": {
                    "content": "{{2.results[0].properties.Brief.rich_text[0].text.content}}"
                  }
                }
              ]
            }
          },
          {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
              "rich_text": [{ "type": "text", "text": { "content": "Key Milestones" } }]
            }
          },
          {
            "object": "block",
            "type": "to_do",
            "to_do": {
              "rich_text": [
                {
                  "type": "text",
                  "text": {
                    "content": "{{2.results[0].properties.Milestone1.rich_text[0].text.content}}"
                  }
                }
              ],
              "checked": false
            }
          },
          {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
              "rich_text": [{ "type": "text", "text": { "content": "Decisions Log" } }]
            }
          },
          {
            "object": "block",
            "type": "numbered_list_item",
            "numbered_list_item": {
              "rich_text": [
                {
                  "type": "text",
                  "text": { "content": "{{formatDate(now; 'YYYY-MM-DD')}} — Portal provisioned." }
                }
              ]
            }
          },
          {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
              "rich_text": [{ "type": "text", "text": { "content": "Next Steps" } }]
            }
          },
          {
            "object": "block",
            "type": "callout",
            "callout": {
              "rich_text": [
                {
                  "type": "text",
                  "text": {
                    "content": "Review the Brief, sign off on the milestones, and post your first decision here. The status board on the team side updates automatically."
                  }
                }
              ]
            }
          }
        ]
      },
      "metadata": {
        "designer": { "x": 1500, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 7,
      "module": "notion:ActionUpdatePage",
      "version": 1,
      "parameters": {},
      "mapper": {
        "pageId": "{{2.results[0].id}}",
        "properties": {
          "Status": {
            "select": { "name": "Active" }
          },
          "Portal URL": {
            "url": "{{4.url}}"
          }
        }
      },
      "metadata": {
        "designer": { "x": 1800, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 8,
      "module": "builtin:BasicRouter",
      "version": 1,
      "parameters": {},
      "mapper": {
        "routes": [
          {
            "label": "Skip portal email",
            "condition": "{{2.results[0].properties.SkipPortalEmail.checkbox}} === true",
            "output": "{{10}}"
          }
        ],
        "fallback": "{{9}}"
      },
      "metadata": {
        "designer": { "x": 2100, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 9,
      "module": "email:ActionSendEmail",
      "version": 1,
      "parameters": {},
      "mapper": {
        "to": "{{2.results[0].properties.Email.email}}",
        "subject": "Your Notion Client Portal is ready — {{2.results[0].properties.Engagement.title[0].text.content}}",
        "content": "<p>Hi {{2.results[0].properties.Name.title[0].text.content}},</p><p>Your Notion Client Portal is ready. You can browse the brief, the files, and the live status board here:</p><p><a href=\"{{4.url}}\">→ Open your portal</a></p><p>Everything is pre-populated from your engagement record — milestones are listed as checkboxes you can tick off, and your decisions log is ready for your first entry.</p><p>This email was sent by your Notion Client Portal automation.</p>",
        "contentType": "html"
      },
      "metadata": {
        "designer": { "x": 2400, "y": 0 },
        "parameters": [],
        "restore": {}
      }
    },
    {
      "id": 10,
      "module": "notion:ActionUpdatePage",
      "version": 1,
      "parameters": {},
      "mapper": {
        "pageId": "{{3.id}}",
        "properties": {
          "Status": {
            "select": { "name": "Active" }
          }
        }
      },
      "metadata": {
        "designer": { "x": 2400, "y": 120 },
        "parameters": [],
        "restore": {}
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com"
  }
}
