{
 "id": "faqchatbot",
 "name": "AutomateRecipes \u2013 faq-chatbot",
 "nodes": [
  {
   "parameters": {},
   "name": "Manual Trigger",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    0
   ],
   "id": "285a1c77-1e44-4c2f-8873-5be00672516d"
  },
  {
   "parameters": {
    "jsCode": "const faq=[{q:'opening hours',a:'We are open 9am-9pm Sat-Thu.'},{q:'delivery',a:'We deliver within 10 km for 15 SAR.'},{q:'refund',a:'Refunds within 7 days with receipt.'}];const msg='Do you do delivery to my area?';const hit=faq.find(f=>msg.toLowerCase().includes(f.q.split(' ')[0]));return [{json:{msg,context:hit?hit.a:null}}];"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S1",
   "position": [
    220,
    0
   ],
   "id": "adc0a28e-47c9-45b2-92ff-0d48a3d8d725"
  },
  {
   "parameters": {
    "jsCode": "const i=$input.first().json;if(!i.context)return [{json:{service:'gmail/send',payload:{to:'owner@shop.test',subject:'Chatbot handoff',text:i.msg}}}];return [{json:{...i,service:'openai/v1/chat/completions',payload:{messages:[{role:'user',content:'Answer only from: '+i.context+' Q: '+i.msg}]}}}];"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "AIPREP",
   "position": [
    440,
    0
   ],
   "id": "ceabfdf9-d205-409c-ba8b-cafe4160afb3"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=http://127.0.0.1:9000/{{ $json.service }}",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify($json.payload) }}",
    "options": {}
   },
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "name": "S3 POST mock (send)",
   "position": [
    660,
    0
   ],
   "id": "44555a9c-30c0-4f29-8d84-887051b8fb2f"
  },
  {
   "parameters": {
    "jsCode": "const c=$input.first().json.choices;if(!c)throw new Error('no answer');return [{json:{reply:c[0].message.content}}];"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S4",
   "position": [
    880,
    0
   ],
   "id": "a47c6bbf-f8b8-42cb-afea-eb0253c2b4f0"
  }
 ],
 "connections": {
  "Manual Trigger": {
   "main": [
    [
     {
      "node": "S1",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S1": {
   "main": [
    [
     {
      "node": "AIPREP",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "AIPREP": {
   "main": [
    [
     {
      "node": "S3 POST mock (send)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S3 POST mock (send)": {
   "main": [
    [
     {
      "node": "S4",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {},
 "active": false,
 "pinData": {},
 "meta": {
  "note": "Tested on n8n 1.70.3 with local mocks for: Chat Trigger, embeddings/vector store (replaced by keyword retrieval), OpenAI. Replace 'POST mock'/'GET mock' HTTP nodes with the real app nodes + credentials before production."
 }
}