{
 "name": "S13 - Lead Engine (עיבוד)",
 "flow": [
  {
   "id": 1,
   "module": "gateway:CustomWebHook",
   "version": 1,
   "parameters": {
    "hook": null,
    "maxResults": 1
   },
   "mapper": {},
   "metadata": {
    "designer": {
     "x": 0,
     "y": 0,
     "name": "ליד מנורמל"
    }
   }
  },
  {
   "id": 2,
   "module": "util:SetVariables",
   "version": 1,
   "parameters": {},
   "mapper": {
    "variables": [
     {
      "name": "email",
      "value": "{{lower(trim(1.email))}}"
     },
     {
      "name": "domain",
      "value": "{{last(split(lower(trim(1.email)); \"@\"))}}"
     },
     {
      "name": "source",
      "value": "{{ifempty(1.source; \"website\")}}"
     }
    ],
    "scope": "roundtrip"
   },
   "metadata": {
    "designer": {
     "x": 300,
     "y": 0,
     "name": "נרמול"
    }
   },
   "filter": {
    "name": "מייל עסקי",
    "conditions": [
     [
      {
       "a": "{{1.email}}",
       "o": "text:matches",
       "b": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
      },
      {
       "a": "{{lower(1.email)}}",
       "o": "text:notContains",
       "b": "gmail."
      }
     ]
    ]
   }
  },
  {
   "id": 3,
   "module": "datastore:ExistRecord",
   "version": 1,
   "parameters": {
    "datastore": null
   },
   "mapper": {
    "key": "{{2.email}}"
   },
   "metadata": {
    "designer": {
     "x": 600,
     "y": 0,
     "name": "קיים?"
    }
   }
  },
  {
   "id": 4,
   "module": "openai-gpt-3:CreateCompletion",
   "version": 1,
   "parameters": {
    "__IMTCONN__": null
   },
   "mapper": {
    "select": "chat",
    "model": "gpt-4.1-mini",
    "temperature": "0.2",
    "max_tokens": "400",
    "response_format": "json_object",
    "messages": [
     {
      "role": "system",
      "content": "הלקוח האידיאלי: חברות B2B עם 20–500 עובדים, תהליכים ידניים, תקציב מעל 25,000 ₪. החזר JSON: {\"aiScore\":0-100,\"intent\":\"low|medium|high\",\"reason\":\"משפט אחד\"}"
     },
     {
      "role": "user",
      "content": "{{1.name}} · {{1.company}} · {{2.domain}} · {{1.message}}"
     }
    ]
   },
   "metadata": {
    "designer": {
     "x": 900,
     "y": 0,
     "name": "ציון AI"
    }
   },
   "filter": {
    "name": "ליד חדש",
    "conditions": [
     [
      {
       "a": "{{3.exists}}",
       "o": "equal",
       "b": "false"
      }
     ]
    ]
   }
  },
  {
   "id": 5,
   "module": "json:ParseJSON",
   "version": 1,
   "parameters": {
    "type": ""
   },
   "mapper": {
    "json": "{{4.choices[].message.content}}"
   },
   "metadata": {
    "designer": {
     "x": 1200,
     "y": 0,
     "name": "Parse JSON"
    }
   }
  },
  {
   "id": 6,
   "module": "util:FunctionIncrement",
   "version": 1,
   "parameters": {
    "reset": "never"
   },
   "mapper": {},
   "metadata": {
    "designer": {
     "x": 1500,
     "y": 0,
     "name": "מונה סבב"
    }
   }
  },
  {
   "id": 7,
   "module": "util:SetVariables",
   "version": 1,
   "parameters": {},
   "mapper": {
    "variables": [
     {
      "name": "owner",
      "value": "{{get(split(\"מיכל,רון,שירה\"; \",\"); (6.i - 1) mod 3 + 1)}}"
     },
     {
      "name": "finalScore",
      "value": "{{round(ifempty(1.rulesScore; 50) * 0.6 + 5.aiScore * 0.4)}}"
     }
    ],
    "scope": "roundtrip"
   },
   "metadata": {
    "designer": {
     "x": 1800,
     "y": 0,
     "name": "שיוך + ציון סופי"
    }
   }
  },
  {
   "id": 8,
   "module": "datastore:AddRecord",
   "version": 1,
   "parameters": {
    "datastore": null
   },
   "mapper": {
    "key": "{{2.email}}",
    "overwrite": true,
    "data": {
     "name": "{{1.name}}",
     "company": "{{1.company}}",
     "score": "{{7.finalScore}}",
     "owner": "{{7.owner}}",
     "reason": "{{5.reason}}",
     "receivedAt": "{{now}}"
    }
   },
   "metadata": {
    "designer": {
     "x": 2100,
     "y": 0,
     "name": "שמירה (Dedupe + CRM קל)"
    }
   }
  },
  {
   "id": 11,
   "module": "builtin:BasicRouter",
   "version": 1,
   "parameters": {},
   "mapper": null,
   "metadata": {
    "designer": {
     "x": 2400,
     "y": 0,
     "name": "חם / טיפוח"
    }
   },
   "routes": [
    {
     "flow": [
      {
       "id": 9,
       "module": "slack:CreateMessage",
       "version": 4,
       "parameters": {
        "__IMTCONN__": null
       },
       "mapper": {
        "channelType": "public",
        "channel": "",
        "text": "🔥 ליד חם ל-{{7.owner}}: *{{1.name}}* ({{1.company}}) · ציון {{7.finalScore}}\n{{5.reason}}"
       },
       "metadata": {
        "designer": {
         "x": 2700,
         "y": -120,
         "name": "🔥 לנציג ב-Slack"
        }
       },
       "filter": {
        "name": "≥ 75",
        "conditions": [
         [
          {
           "a": "{{7.finalScore}}",
           "o": "greaterOrEqual",
           "b": "75"
          }
         ]
        ]
       }
      }
     ]
    },
    {
     "flow": [
      {
       "id": 10,
       "module": "placeholder:Placeholder",
       "version": 1,
       "parameters": {},
       "mapper": {},
       "metadata": {
        "designer": {
         "x": 2700,
         "y": 120,
         "name": "🌱 טיפוח — סמנו stage = nurture ב-CRM"
        }
       },
       "filter": {
        "name": "< 75",
        "conditions": [
         [
          {
           "a": "{{7.finalScore}}",
           "o": "less",
           "b": "75"
          }
         ]
        ]
       }
      }
     ]
    }
   ]
  }
 ],
 "metadata": {
  "instant": true,
  "version": 1,
  "scenario": {
   "roundtrips": 1,
   "maxErrors": 3,
   "autoCommit": true,
   "autoCommitTriggerLast": true,
   "sequential": false,
   "slots": null,
   "confidential": false,
   "dataloss": false,
   "dlq": true,
   "freshVariables": false
  },
  "designer": {
   "orphans": []
  },
  "zone": "eu1.make.com"
 }
}