{
  "name": "HashtagME Zero-UI - Outlook to Cloudflare D1",
  "description": "Zero-UI pijplijn: Outlook e-mail trigger -> Cloudflare Worker v0.5.1 -> D1. Beveiligd met X-Webhook-Secret.",
  "version": "v0.5.1",
  "trigger": {
    "app": "outlook",
    "type": "new_email_matching_search",
    "config": {
      "search": "hashtagme OR qnft OR ijara OR murabaha",
      "note": "Pas deze zoekterm aan. Elke e-mail die hieraan voldoet triggert de Worker."
    }
  },
  "steps": [
    {
      "id": "parse_email",
      "name": "Parse Email to Action",
      "type": "code - Node.js",
      "code": "export default defineComponent({\n  async run({ steps, $ }) {\n    // Haal subject en body op uit Outlook trigger\n    const subject = steps.trigger.event.subject || '';\n    const body = steps.trigger.event.body?.content || steps.trigger.event.body || '';\n    \n    // Simpele parser: verwacht in e-mail iets als: id: qnft-005, financing: ijara, lease_end: 2026-12-01\n    // Je kunt dit uitbreiden naar wat jij in je e-mail zet\n    const idMatch = (subject + body).match(/id:\\s*([a-z0-9-_]+)/i);\n    const financingMatch = (subject + body).match(/financing:\\s*(ijara|murabaha|musharaka)/i);\n    const leaseMatch = (subject + body).match(/lease_end:\\s*([0-9]{4}-[0-9]{2}-[0-9]{2})/i);\n    \n    const asset = {\n      id: idMatch ? idMatch[1] : `qnft-${Date.now()}`,\n      financing: financingMatch ? financingMatch[1].toLowerCase() : 'ijara',\n      lease_end: leaseMatch ? leaseMatch[1] : null,\n      name: subject,\n      description: `Created via Outlook Zero-UI: ${subject}`,\n    };\n    \n    return {\n      action: 'create_asset',\n      data: asset,\n      raw_email: { subject, snippet: body.substring(0,500) }\n    };\n  },\n})"
    },
    {
      "id": "call_worker",
      "name": "POST to Cloudflare Worker v0.5.1",
      "type": "http - POST",
      "config": {
        "url": "https://api.hashtagmeonline.space/webhooks/outlook",
        "method": "POST",
        "headers": {
          "Content-Type": "application/json",
          "X-Webhook-Secret": "{{process.env.WEBHOOK_SECRET}} - VUL HIER JOUW SECRET IN OF GEBRUIK PIPEDREAM ENV"
        },
        "body": {
          "action": "{{steps.parse_email.action}}",
          "data": "{{steps.parse_email.data}}"
        },
        "note": "Zet je WEBHOOK_SECRET in Pipedream > Environment Variables of vervang direct in header. Deze moet gelijk zijn aan npx wrangler secret put WEBHOOK_SECRET"
      }
    },
    {
      "id": "notify_success",
      "name": "Log Success",
      "type": "code - Node.js",
      "code": "export default defineComponent({\n  async run({ steps }) {\n    console.log('Worker response:', steps.call_worker);\n    return { success: true, worker_response: steps.call_worker };\n  }\n})"
    }
  ],
  "alternative_manus_flow": {
    "description": "Voor hashtagme3@manus.bot",
    "instruction_email_to_manus": "Elke keer als ik je mail met onderwerp dat begint met 'RUN:', stuur een POST naar https://api.hashtagmeonline.space/webhooks/execute met header X-Webhook-Secret: JOUW_WEBHOOK_SECRET en body { action: 'create_asset', data: { id, financing, lease_end, name } } parsed uit mijn e-mail body. Gebruik mijn WEBHOOK_SECRET die ik je apart stuur.",
    "curl_test": "curl -X POST https://api.hashtagmeonline.space/webhooks/execute -H \"X-Webhook-Secret: JOUW_SECRET\" -H \"Content-Type: application/json\" -d '{\"action\":\"create_asset\",\"data\":{\"id\":\"qnft-005\",\"financing\":\"ijara\",\"lease_end\":\"2026-12-15\",\"name\":\"Manus Test\"}}'"
  },
  "secrets_setup": {
    "cloudflare": [
      "npx wrangler secret put API_SECRET",
      "npx wrangler secret put WEBHOOK_SECRET",
      "npx wrangler secret put TELEGRAM_BOT_TOKEN (optioneel)",
      "npx wrangler secret put TELEGRAM_CHAT_ID (optioneel)"
    ],
    "pipedream": [
      "Ga naar Pipedream > je workflow > Environment Variables > Add WEBHOOK_SECRET = zelfde als in Cloudflare",
      "Koppel je Outlook account bij de trigger"
    ]
  }
}