{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567802",
  "name": "HotBot \u2014 02 Chat Pipeline",
  "nodes": [
    {
      "id": "node-webhook-chat",
      "name": "Webhook \u2014 Chat",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "hotbotstudios.com",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      }
    },
    {
      "id": "node-validate-chat",
      "name": "Validate & Prepare",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "jsCode": "const body = $input.first().json.body || $input.first().json;\nconst message = (body.message || '').trim();\nconst sessionId = body.sessionId || ('session-' + Date.now());\nconst history = Array.isArray(body.history) ? body.history.slice(-10) : [];\nconst meta = body._meta || {};\n\nif (!message || message.length < 1) throw new Error('Empty message');\nif (message.length > 2000) throw new Error('Message too long');\n\nreturn [{\n  json: {\n    message,\n    sessionId,\n    history,\n    timestamp: new Date().toISOString(),\n    source: meta.source || 'website-chat'\n  }\n}];"
      }
    },
    {
      "id": "node-llm-chat",
      "name": "OpenAI \u2014 HotBot LLM",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [
        720,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are HotBot, the AI assistant for HotBot Studios \u2014 a premium AI automation and digital marketing agency.\n\nYour role:\n- Answer questions about HotBot Studios' services: AI Automation, Marketing Services, Content Studio, Software Development, Public Relations, UI/UX Design, and Consultancy\n- Qualify leads by asking about their business needs, budget, and timeline\n- Guide users toward booking a consultation or filling out the contact form\n- Be professional, concise, and enthusiastic about AI solutions\n\nServices overview:\n1. AI Automation \u2014 Custom bots, n8n workflows, process automation\n2. Marketing Services \u2014 SEO, PPC, social media, growth hacking\n3. Content Studio \u2014 Blog, video, copywriting, brand voice\n4. Software Development \u2014 Web apps, APIs, integrations\n5. Public Relations \u2014 Brand reputation, media outreach, press\n6. UI/UX Design \u2014 Figma, prototyping, user research\n7. AI Consultancy \u2014 Strategy, implementation, training\n\nPricing: Projects start from $500. Custom quotes based on scope.\nContact: hello@hotbotstudios.com | WhatsApp: +91-XXXXXXXXXX\nWebsite: https://hotbotstudios.com\n\nImportant rules:\n- Never make up pricing or guarantees\n- If unsure, say 'Let me connect you with our team'\n- Keep responses under 150 words unless explaining something complex\n- End responses with a gentle call to action when appropriate"
            },
            {
              "role": "user",
              "content": "={{ $json.message }}"
            }
          ]
        },
        "options": {
          "temperature": 0.7,
          "maxTokens": 500
        }
      }
    },
    {
      "id": "node-intent-classifier",
      "name": "Intent Classifier",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "jsCode": "const llmResponse = $input.first().json;\nconst aiMessage = llmResponse.message?.content || llmResponse.choices?.[0]?.message?.content || 'I can help with that. Please tell me more about your needs.';\nconst userMessage = $('Validate & Prepare').first().json.message.toLowerCase();\n\n// Detect intent\nconst bookingKeywords = ['book', 'schedule', 'appointment', 'meeting', 'call', 'consult', 'demo'];\nconst formKeywords = ['quote', 'proposal', 'price', 'cost', 'budget', 'get started', 'contact', 'reach out'];\nconst whatsappKeywords = ['whatsapp', 'chat', 'message', 'urgent', 'asap', 'immediately'];\n\nconst intent = bookingKeywords.some(k => userMessage.includes(k)) ? 'booking'\n  : formKeywords.some(k => userMessage.includes(k)) ? 'form'\n  : whatsappKeywords.some(k => userMessage.includes(k)) ? 'whatsapp'\n  : 'continue';\n\nreturn [{\n  json: {\n    aiMessage,\n    intent,\n    sessionId: $('Validate & Prepare').first().json.sessionId,\n    timestamp: $('Validate & Prepare').first().json.timestamp\n  }\n}];"
      }
    },
    {
      "id": "node-switch-intent",
      "name": "Route by Intent",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "mode": "expression",
        "output": "={{ $json.intent }}",
        "rules": {
          "rules": [
            {
              "outputKey": "booking",
              "value": "booking"
            },
            {
              "outputKey": "form",
              "value": "form"
            },
            {
              "outputKey": "whatsapp",
              "value": "whatsapp"
            }
          ]
        },
        "fallbackOutput": "none"
      }
    },
    {
      "id": "node-telegram-booking",
      "name": "Telegram \u2014 Booking Alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1440,
        100
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "parameters": {
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "text": "=\ud83d\udcc5 *Booking Intent Detected*\n\n\ud83d\udcac User wants to book/schedule\nSession: {{ $json.sessionId }}\nMessage context: see chat logs\n\n\u23f0 {{ $json.timestamp }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      }
    },
    {
      "id": "node-respond-chat",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1680,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ message: $('Intent Classifier').first().json.aiMessage }) }}",
        "options": {
          "responseCode": 200
        }
      }
    }
  ],
  "connections": {
    "Webhook \u2014 Chat": {
      "main": [
        [
          {
            "node": "Validate & Prepare",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate & Prepare": {
      "main": [
        [
          {
            "node": "OpenAI \u2014 HotBot LLM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI \u2014 HotBot LLM": {
      "main": [
        [
          {
            "node": "Intent Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Intent Classifier": {
      "main": [
        [
          {
            "node": "Route by Intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Intent": {
      "main": [
        [
          {
            "node": "Telegram \u2014 Booking Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram \u2014 Booking Alert": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "tags": [
    {
      "id": "tag-hotbot",
      "name": "hotbot-studios"
    },
    {
      "id": "tag-chat",
      "name": "chat-pipeline"
    }
  ]
}