{
  "name": "FAQ Chatbot with Human Fallback",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "faq-chat",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000001",
      "name": "FAQ Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "set-question",
              "name": "question",
              "value": "={{ $json.body.question }}",
              "type": "string"
            },
            {
              "id": "set-user-email",
              "name": "userEmail",
              "value": "={{ $json.body.email || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000002",
      "name": "Extract Question",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are an FAQ chatbot. Answer common questions about our product/service based on the knowledge below. If you are confident in your answer, include \"CONFIDENCE: HIGH\" at the end. If the question is outside your knowledge or you are unsure, include \"CONFIDENCE: LOW\" at the end.\n\nKnowledge base:\n- Business hours: Mon-Fri 9am-6pm EST\n- Free trial: 14 days, no credit card required\n- Pricing: Starter $29/mo, Pro $79/mo, Enterprise custom\n- Refund policy: 30-day money-back guarantee\n- Support: email support@example.com or live chat\n- Integrations: Slack, Salesforce, HubSpot, Zapier, n8n\n- Data storage: AWS US-East, SOC2 compliant, GDPR ready\n- API: RESTful API available on Pro and Enterprise plans"
            },
            {
              "role": "user",
              "content": "={{ $json.question }}"
            }
          ]
        },
        "options": {
          "temperature": 0.3,
          "maxTokens": 500
        }
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000003",
      "name": "OpenAI FAQ Answer",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        680,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "check-confidence",
              "leftValue": "={{ $json.message.content }}",
              "rightValue": "CONFIDENCE: HIGH",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000004",
      "name": "IF Confident Answer",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ answer: $json.message.content.replace('CONFIDENCE: HIGH', '').trim(), confident: true, escalated: false }) }}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000005",
      "name": "Respond with Answer",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        200
      ]
    },
    {
      "parameters": {
        "channel": "#support-escalations",
        "text": "=:question: *New FAQ Escalation*\n\n*Question:* {{ $('Extract Question').item.json.question }}\n*User Email:* {{ $('Extract Question').item.json.userEmail || 'Not provided' }}\n*AI Attempted Answer:* {{ $json.message.content.replace('CONFIDENCE: LOW', '').trim() }}\n\nPlease follow up with the customer.",
        "otherOptions": {}
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000006",
      "name": "Escalate to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1120,
        420
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ answer: \"I'm not fully confident in my answer to this question. I've escalated it to our support team who will get back to you shortly.\", confident: false, escalated: true }) }}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "e5f6a7b8-5555-4000-8000-000000000007",
      "name": "Respond with Escalation",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1340,
        420
      ]
    }
  ],
  "connections": {
    "FAQ Webhook": {
      "main": [
        [
          {
            "node": "Extract Question",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Question": {
      "main": [
        [
          {
            "node": "OpenAI FAQ Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI FAQ Answer": {
      "main": [
        [
          {
            "node": "IF Confident Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Confident Answer": {
      "main": [
        [
          {
            "node": "Respond with Answer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Escalate to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Escalate to Slack": {
      "main": [
        [
          {
            "node": "Respond with Escalation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}