{
  "name": "line_bot",
  "nodes": [
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "typeVersion": 1,
      "position": [
        -280,
        1520
      ],
      "id": "cc51834b-7839-4eed-bfbc-71dc3e43d2c7",
      "name": "Azure OpenAI Chat Model1"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        160,
        1220
      ],
      "id": "cf0450a6-576a-44f6-865e-9242638b32f3",
      "name": "Merge"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "\n# \u5728 n8n \u7684 Python Code \u7bc0\u9ede\u4e2d\u4f7f\u7528\uff0c\u8f38\u5165\u8b8a\u6578\u70ba items\uff08List[Dict]\uff09\n\n\n# \u78ba\u4fdd\u5fc5\u8981\u6578\u64da\u5b58\u5728\nreply_token_item = next(\n    (\n        item for item in items\n        if item.get('json', {}) \\\n               .get('body', {}) \\\n               .get('events', [{}])[0] \\\n               .get('replyToken')\n    ),\n    None\n)\n\n\n\noutput_item = next(\n    (\n        item for item in items\n        if item.get('json', {}).get('output') is not None\n    ),\n    None\n)\n\n\nif not reply_token_item or not output_item:\n    raise ValueError(\"\u7f3a\u5c11\u5fc5\u8981\u6578\u64da\uff0c\u8acb\u6aa2\u67e5 Webhook & AI Agent \u7bc0\u9ede\u8f38\u51fa\")\n\n# \u53d6\u5f97 replyToken \u548c AI Agent \u56de\u50b3\u6587\u5b57\uff0c\u4e26\u79fb\u9664\u591a\u9918\u7684\u63db\u884c\nreply_token = reply_token_item['json']['body']['events'][0]['replyToken']\ntext = output_item['json']['output'].strip()\n\n# \u56de\u50b3\u6574\u7406\u5f8c\u7684\u7d50\u679c\nreturn [\n    {\n        'json': {\n            'replyToken': reply_token,\n            'text': text\n        }\n    }\n]\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        360,
        1220
      ],
      "id": "a43b0774-b902-4d40-99d5-9def813648ef",
      "name": "Code"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=\u56de\u61c9\u9019\u500b\u8a0a\u606f\uff1a{{ $json.body.events[0].message.text }}\n\u4ee5\u7e41\u9ad4\u4e2d\u6587\uff0c\u7d14\u6587\u5b57\u8f38\u51fa\uff0c\u4e0d\u8981\u5e36 HTML\u3002",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        -280,
        1280
      ],
      "id": "6d41c324-8d02-4a22-8307-98abe28cda11",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "callback",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -520,
        1200
      ],
      "id": "46d25c77-bb30-404b-ae45-bb5e92826ee4",
      "name": "Webhook1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.line.me/v2/bot/message/reply",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer fGYFFTC5pNVcr18u7zV6qZR5lNNHDH3/0hmlXmritsnfHEsRvNS8nF6ZGB/7avPNuxh9PlLf+1BAvaIgdQ3PtZupaOoKDhdH7ab4q2/VEtuBr8wsL29UUwoLSzbgGoix1LPHJZc9xKyNeOWVtXW7mQdB04t89/1O/w1cDnyilFU="
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"replyToken\": \"{{ $json.replyToken }}\",\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"{{ $json.text }}\"\n    }\n  ]\n}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        580,
        1220
      ],
      "id": "0238e96f-bd43-42fa-8154-200078e18881",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "content": "# Trigger Node",
        "height": 180
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -600,
        1140
      ],
      "id": "8df83eb7-0e58-4a09-8923-3a3487b845cc",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "# Cluster Node",
        "height": 260,
        "width": 360,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -320,
        1160
      ],
      "id": "7bcb2cde-761a-45dc-8804-cc1b75d9492b",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "# Sub-Node",
        "height": 200,
        "width": 300,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -440,
        1460
      ],
      "id": "740242cd-c220-43a6-8a30-c929d1d7b75f",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "# Flow Node",
        "height": 180,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        60,
        1160
      ],
      "id": "8b0f915c-fb9f-40f6-8402-7aca06e782dd",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "# Core Node",
        "height": 220,
        "width": 420,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        340,
        1160
      ],
      "id": "87e93453-3f1b-432d-b5a0-2aeb6d3eb5a8",
      "name": "Sticky Note4"
    }
  ],
  "connections": {
    "Azure OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a81f2b73-b1b2-4c5e-bb01-c147b2526428",
  "id": "kbajzS6mJ7RdKYRO",
  "tags": []
}