{
 "name": "תבנית קורס: סוכן מוסך עם אישור אנושי",
 "nodes": [
  {
   "id": "n1",
   "name": "הפעלה ידנית",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    300
   ],
   "parameters": {}
  },
  {
   "id": "n2",
   "name": "פנייה מדומה",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    220,
    300
   ],
   "parameters": {
    "mode": "manual",
    "assignments": {
     "assignments": [
      {
       "id": "a1",
       "name": "request",
       "type": "string",
       "value": "כמה עולה טיפול שנתי לטנדר?"
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "n3",
   "name": "סיווג וטיוטה",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    440,
    300
   ],
   "parameters": {
    "method": "POST",
    "url": "https://api.anthropic.com/v1/messages",
    "authentication": "genericCredentialType",
    "genericAuthType": "httpHeaderAuth",
    "sendHeaders": true,
    "headerParameters": {
     "parameters": [
      {
       "name": "anthropic-version",
       "value": "2023-06-01"
      }
     ]
    },
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify({ model: \"claude-haiku-4-5-20251001\", max_tokens: 400, system: \"אתה מסווג פניות של מוסך. בחר קטגוריה אחת: דחוף, הצעת מחיר, תלונה, אחר.\\nדחוף: רכב שלא נוסע או חשש בטיחותי.\\nאם הפנייה לא ברורה, או שיש בה בקשות סותרות, כתוב \\\"לבדיקה\\\".\\nנסח תשובה קצרה בעברית. אסור לציין מחיר, אבחון או מועד.\\nבחשש בטיחותי הנחה לעצור בצד בבטחה, ולפנות לגורמי החירום אם צריך.\\nהחזר JSON בלבד, עם השדות category ו-reply.\", messages: [{ role: \"user\", content: $json.request }] }) }}",
    "options": {}
   }
  },
  {
   "id": "n4",
   "name": "פענוח התשובה",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    660,
    300
   ],
   "parameters": {
    "language": "javaScript",
    "mode": "runOnceForEachItem",
    "jsCode": "const text = $json.content[0].text;\nconst start = text.indexOf('{');\nconst end = text.lastIndexOf('}');\nlet out = { category: 'לבדיקה', reply: '' };\ntry { out = JSON.parse(text.slice(start, end + 1)); } catch (e) {}\nreturn { json: { request: $('פנייה מדומה').item.json.request, ...out } };"
   }
  },
  {
   "id": "n5",
   "name": "המתנה לאישור אדם",
   "type": "n8n-nodes-base.wait",
   "typeVersion": 1.1,
   "position": [
    880,
    300
   ],
   "parameters": {
    "resume": "form",
    "formTitle": "אישור תשובה ללקוח",
    "formDescription": "=סיווג: {{ $json.category }}\nטיוטה: {{ $json.reply }}",
    "formFields": {
     "values": [
      {
       "fieldLabel": "החלטה",
       "fieldType": "dropdown",
       "fieldOptions": {
        "values": [
         {
          "option": "לאשר"
         },
         {
          "option": "לעצור"
         }
        ]
       },
       "requiredField": true
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "n6",
   "name": "אושר?",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.2,
   "position": [
    1100,
    300
   ],
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "strict",
      "version": 2
     },
     "conditions": [
      {
       "id": "c1",
       "leftValue": "={{ $json[\"החלטה\"] }}",
       "rightValue": "לאשר",
       "operator": {
        "type": "string",
        "operation": "equals"
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   }
  },
  {
   "id": "n7",
   "name": "לשליחה (רישום בלבד)",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    1320,
    200
   ],
   "parameters": {
    "mode": "manual",
    "assignments": {
     "assignments": [
      {
       "id": "a2",
       "name": "status",
       "type": "string",
       "value": "לשליחה"
      },
      {
       "id": "a3",
       "name": "reply",
       "type": "string",
       "value": "={{ $('פענוח התשובה').item.json.reply }}"
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "n8",
   "name": "נעצר",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    1320,
    400
   ],
   "parameters": {
    "mode": "manual",
    "assignments": {
     "assignments": [
      {
       "id": "a4",
       "name": "status",
       "type": "string",
       "value": "נעצר על ידי אדם"
      }
     ]
    },
    "options": {}
   }
  }
 ],
 "connections": {
  "הפעלה ידנית": {
   "main": [
    [
     {
      "node": "פנייה מדומה",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "פנייה מדומה": {
   "main": [
    [
     {
      "node": "סיווג וטיוטה",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "סיווג וטיוטה": {
   "main": [
    [
     {
      "node": "פענוח התשובה",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "פענוח התשובה": {
   "main": [
    [
     {
      "node": "המתנה לאישור אדם",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "המתנה לאישור אדם": {
   "main": [
    [
     {
      "node": "אושר?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "אושר?": {
   "main": [
    [
     {
      "node": "לשליחה (רישום בלבד)",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "נעצר",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "pinData": {}
}