对话式旅行预订器:使用 AI 自动化航班和酒店预订
这是一个Support Chatbot、AI Chatbot领域的自动化工作流,包含 21 个节点。主要使用 Code、OpenAi、Switch、Webhook、EmailSend 等节点。 对话式旅行预订器:使用 GPT-3.5 自动化航班和酒店预订
- •OpenAI API Key
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
{
"id": "zqOUjpxu04PO1idj",
"meta": {
"instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
"templateCredsSetupCompleted": true
},
"name": "对话式旅行预订器:使用 AI 自动化航班和酒店预订",
"tags": [],
"nodes": [
{
"id": "8b53e7e2-cedb-42a9-8918-3d7e8d0a23d1",
"name": "Webhook触发器",
"type": "n8n-nodes-base.webhook",
"position": [
-660,
-80
],
"webhookId": "booking-webhook",
"parameters": {
"path": "booking-request",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 1
},
{
"id": "16a396bd-3200-4be1-80d4-364d8a7a65e6",
"name": "AI 请求解析器",
"type": "n8n-nodes-base.openAi",
"position": [
-440,
-80
],
"parameters": {
"model": "=gpt-3.5-turbo",
"prompt": "Hello",
"options": {
"temperature": 0.3
},
"requestOptions": {}
},
"credentials": {
"openAiApi": {
"id": "CDQ16eImh6D4tY15",
"name": "OpenAi account 2 - test"
}
},
"typeVersion": 1
},
{
"id": "d3d569ce-8e9b-4d88-ba84-e39f5cc41bf9",
"name": "预订类型路由器",
"type": "n8n-nodes-base.switch",
"position": [
-220,
-101
],
"parameters": {},
"typeVersion": 1
},
{
"id": "79041d5f-75e0-43e1-92be-486dcfb30847",
"name": "航班数据处理器",
"type": "n8n-nodes-base.code",
"position": [
0,
-180
],
"parameters": {
"jsCode": "// Parse AI response and prepare flight search\nconst aiResponse = $input.first().json.choices[0].message.content;\nlet bookingData;\n\ntry {\n // Try to parse as JSON first\n bookingData = JSON.parse(aiResponse);\n} catch {\n // If not JSON, extract info from text\n bookingData = {\n type: 'flight',\n origin: extractValue(aiResponse, ['from', 'origin', 'departure']),\n destination: extractValue(aiResponse, ['to', 'destination', 'arrival']),\n departDate: extractValue(aiResponse, ['depart', 'departure date', 'leaving']),\n passengers: extractValue(aiResponse, ['passenger', 'traveler', 'people']) || 1\n };\n}\n\nfunction extractValue(text, keywords) {\n for (const keyword of keywords) {\n const regex = new RegExp(`${keyword}[:\\s]+([^\\n,]+)`, 'i');\n const match = text.match(regex);\n if (match) return match[1].trim();\n }\n return null;\n}\n\n// Prepare flight search parameters\nconst flightSearch = {\n origin: bookingData.origin || 'NYC',\n destination: bookingData.destination || 'LAX',\n departureDate: bookingData.departDate || new Date().toISOString().split('T')[0],\n passengers: parseInt(bookingData.passengers) || 1,\n class: bookingData.class || 'economy'\n};\n\nreturn { json: { bookingData, flightSearch, originalRequest: $input.first().json } };"
},
"typeVersion": 2
},
{
"id": "ac45ba1d-40a7-4f4e-98f6-ce3a17c94cbe",
"name": "酒店数据处理器",
"type": "n8n-nodes-base.code",
"position": [
0,
20
],
"parameters": {
"jsCode": "// Parse AI response and prepare hotel search\nconst aiResponse = $input.first().json.choices[0].message.content;\nlet bookingData;\n\ntry {\n bookingData = JSON.parse(aiResponse);\n} catch {\n bookingData = {\n type: 'hotel',\n destination: extractValue(aiResponse, ['destination', 'city', 'location']),\n checkIn: extractValue(aiResponse, ['check in', 'arrival', 'checkin']),\n checkOut: extractValue(aiResponse, ['check out', 'departure', 'checkout']),\n guests: extractValue(aiResponse, ['guest', 'people', 'traveler']) || 2,\n rooms: extractValue(aiResponse, ['room']) || 1\n };\n}\n\nfunction extractValue(text, keywords) {\n for (const keyword of keywords) {\n const regex = new RegExp(`${keyword}[:\\s]+([^\\n,]+)`, 'i');\n const match = text.match(regex);\n if (match) return match[1].trim();\n }\n return null;\n}\n\n// Prepare hotel search parameters\nconst hotelSearch = {\n destination: bookingData.destination || 'New York',\n checkIn: bookingData.checkIn || new Date().toISOString().split('T')[0],\n checkOut: bookingData.checkOut || new Date(Date.now() + 86400000).toISOString().split('T')[0],\n guests: parseInt(bookingData.guests) || 2,\n rooms: parseInt(bookingData.rooms) || 1\n};\n\nreturn { json: { bookingData, hotelSearch, originalRequest: $input.first().json } };"
},
"typeVersion": 2
},
{
"id": "e9c34a77-e19b-4cf6-86ed-736b815c353f",
"name": "航班搜索 API",
"type": "n8n-nodes-base.httpRequest",
"position": [
220,
-180
],
"parameters": {
"url": "https://api.aviationstack.com/v1/flights",
"options": {},
"sendQuery": true,
"authentication": "predefinedCredentialType",
"queryParameters": {
"parameters": [
{
"name": "dep_iata",
"value": "={{ $json.flightSearch.origin }}"
},
{
"name": "arr_iata",
"value": "={{ $json.flightSearch.destination }}"
},
{
"name": "limit",
"value": "5"
}
]
},
"nodeCredentialType": "aviationStackApi"
},
"typeVersion": 4.1
},
{
"id": "d49ce324-9a2b-4bb2-81db-a55f3977aa0d",
"name": "酒店搜索 API",
"type": "n8n-nodes-base.httpRequest",
"position": [
220,
20
],
"parameters": {
"url": "https://api.booking.com/v1/hotels/search",
"options": {},
"sendQuery": true,
"authentication": "predefinedCredentialType",
"queryParameters": {
"parameters": [
{
"name": "dest_id",
"value": "={{ $json.hotelSearch.destination }}"
},
{
"name": "checkin_date",
"value": "={{ $json.hotelSearch.checkIn }}"
},
{
"name": "checkout_date",
"value": "={{ $json.hotelSearch.checkOut }}"
},
{
"name": "adults_number",
"value": "={{ $json.hotelSearch.guests }}"
},
{
"name": "room_number",
"value": "={{ $json.hotelSearch.rooms }}"
}
]
},
"nodeCredentialType": "bookingComApi"
},
"typeVersion": 4.1
},
{
"id": "0840d661-f296-4a66-94cc-4ee03dd30300",
"name": "航班预订处理器",
"type": "n8n-nodes-base.code",
"position": [
440,
-180
],
"parameters": {
"jsCode": "// Process flight search results and prepare booking\nconst searchResults = $input.first().json;\nconst bookingData = $input.first().json;\n\n// Mock flight results if API fails\nconst flights = searchResults.data || [\n {\n flight_number: 'AA123',\n airline: 'American Airlines',\n departure: { airport: bookingData.flightSearch?.origin || 'NYC', time: '09:00' },\n arrival: { airport: bookingData.flightSearch?.destination || 'LAX', time: '12:00' },\n price: 299,\n duration: '5h 30m'\n },\n {\n flight_number: 'DL456',\n airline: 'Delta Airlines', \n departure: { airport: bookingData.flightSearch?.origin || 'NYC', time: '14:00' },\n arrival: { airport: bookingData.flightSearch?.destination || 'LAX', time: '17:30' },\n price: 325,\n duration: '5h 30m'\n }\n];\n\n// Select best flight (lowest price)\nconst selectedFlight = flights.sort((a, b) => (a.price || 299) - (b.price || 325))[0];\n\n// Prepare booking confirmation\nconst booking = {\n type: 'flight',\n status: 'confirmed',\n confirmation: `FL${Date.now()}`,\n details: selectedFlight,\n passenger: {\n name: 'John Doe', // In real workflow, get from user data\n email: 'john@example.com'\n },\n total: selectedFlight.price || 299\n};\n\nreturn { json: { booking, searchResults: flights } };"
},
"typeVersion": 2
},
{
"id": "eb5d528a-6bd8-4546-8744-9ce2f0416ea4",
"name": "酒店预订处理器",
"type": "n8n-nodes-base.code",
"position": [
440,
20
],
"parameters": {
"jsCode": "// Process hotel search results and prepare booking\nconst searchResults = $input.first().json;\nconst bookingData = $input.first().json;\n\n// Mock hotel results if API fails\nconst hotels = searchResults.hotels || [\n {\n name: 'Grand Plaza Hotel',\n location: bookingData.hotelSearch?.destination || 'New York',\n rating: 4.5,\n price_per_night: 150,\n amenities: ['WiFi', 'Pool', 'Gym'],\n room_type: 'Deluxe Room'\n },\n {\n name: 'City Center Inn',\n location: bookingData.hotelSearch?.destination || 'New York',\n rating: 4.0,\n price_per_night: 120,\n amenities: ['WiFi', 'Breakfast'],\n room_type: 'Standard Room'\n }\n];\n\n// Select best hotel (highest rating)\nconst selectedHotel = hotels.sort((a, b) => (b.rating || 4) - (a.rating || 3.5))[0];\n\n// Calculate total nights\nconst checkIn = new Date(bookingData.hotelSearch?.checkIn || new Date());\nconst checkOut = new Date(bookingData.hotelSearch?.checkOut || new Date(Date.now() + 86400000));\nconst nights = Math.ceil((checkOut - checkIn) / (1000 * 60 * 60 * 24)) || 1;\n\n// Prepare booking confirmation\nconst booking = {\n type: 'hotel',\n status: 'confirmed',\n confirmation: `HT${Date.now()}`,\n details: selectedHotel,\n guest: {\n name: 'John Doe',\n email: 'john@example.com'\n },\n nights: nights,\n total: (selectedHotel.price_per_night || 120) * nights\n};\n\nreturn { json: { booking, searchResults: hotels } };"
},
"typeVersion": 2
},
{
"id": "ee741a63-77c7-4348-b62d-32150bdc4e4b",
"name": "确认消息生成器",
"type": "n8n-nodes-base.openAi",
"position": [
660,
-80
],
"parameters": {
"model": "=gpt-3.5-turbo",
"prompt": "{{json.data}}",
"options": {
"temperature": 0.7
},
"requestOptions": {}
},
"credentials": {
"openAiApi": {
"id": "CDQ16eImh6D4tY15",
"name": "OpenAi account 2 - test"
}
},
"typeVersion": 1
},
{
"id": "45c5475b-31d2-4de8-b4b0-19acc57ef344",
"name": "发送确认邮件",
"type": "n8n-nodes-base.emailSend",
"position": [
880,
-80
],
"webhookId": "f80f3193-3a16-47c4-b8b3-23ac37cb8dfd",
"parameters": {
"text": "{{json.data}}",
"options": {
"allowUnauthorizedCerts": true
},
"subject": "🎉 Your Travel Booking is Confirmed!",
"toEmail": "xyz@gmail.com",
"fromEmail": "abc@gmail.com"
},
"credentials": {
"smtp": {
"id": "G1kyF8cSWTZ4vouN",
"name": "SMTP -test"
}
},
"typeVersion": 2
},
{
"id": "1b362532-fb06-497b-9858-609d9ad6fa9b",
"name": "发送响应",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
1100,
-80
],
"parameters": {
"options": {},
"respondWith": "json",
"responseBody": {
"status": "success",
"booking": "{{ $('flight-booking-processor').item.json.booking || $('hotel-booking-processor').item.json.booking }}",
"message": "{{ $('confirmation-generator').item.json.choices[0].message.content }}",
"confirmation_code": "{{ $('flight-booking-processor').item.json.booking?.confirmation || $('hotel-booking-processor').item.json.booking?.confirmation }}"
}
},
"typeVersion": 1
},
{
"id": "6b6f2ebf-fda1-4a32-b8a3-5cb9525b4534",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-685,
-220
],
"parameters": {
"color": 5,
"width": 150,
"height": 300,
"content": "通过 HTTP POST 接受预订请求"
},
"typeVersion": 1
},
{
"id": "3a6ac642-06a1-4c10-93ec-a8ef60ed7f1f",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
195,
-320
],
"parameters": {
"color": 4,
"width": 150,
"height": 520,
"content": "搜索航班/酒店(带有模拟回退)"
},
"typeVersion": 1
},
{
"id": "4c698f05-39a6-4369-88a4-8e92f43b1b18",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-25,
-320
],
"parameters": {
"color": 6,
"width": 150,
"height": 520,
"content": "提取并结构化预订参数"
},
"typeVersion": 1
},
{
"id": "8721b991-ce05-4244-84bf-237312498fbc",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-240,
-220
],
"parameters": {
"width": 150,
"height": 300,
"content": "自动判断是航班还是酒店预订"
},
"typeVersion": 1
},
{
"id": "b1d232d9-31f0-4f31-9a0b-9ea14ee31ab5",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-465,
-220
],
"parameters": {
"color": 3,
"width": 150,
"height": 300,
"content": "使用 OpenAI 理解自然语言预订请求"
},
"typeVersion": 1
},
{
"id": "c001363a-c58c-406f-9cef-d7ad668fb071",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
855,
-220
],
"parameters": {
"color": 5,
"width": 150,
"height": 300,
"content": "通过电子邮件发送预订确认"
},
"typeVersion": 1
},
{
"id": "5d23d45e-23ab-45c8-8658-3a93ae8ec0c1",
"name": "### 需要帮助?",
"type": "n8n-nodes-base.stickyNote",
"position": [
635,
-220
],
"parameters": {
"color": 2,
"width": 150,
"height": 300,
"content": "创建个性化确认消息"
},
"typeVersion": 1
},
{
"id": "44b36b14-4353-45a1-894a-42596a2641fc",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
415,
-320
],
"parameters": {
"color": 3,
"width": 150,
"height": 520,
"content": "处理并确认预订"
},
"typeVersion": 1
},
{
"id": "7588a845-8d92-4e8f-aa07-b454126f61f1",
"name": "便签 11",
"type": "n8n-nodes-base.stickyNote",
"position": [
1075,
-220
],
"parameters": {
"color": 4,
"width": 150,
"height": 300,
"content": "返回结构化的预订数据"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "62307eb8-de4c-41a1-aa27-7efc27a9f954",
"connections": {
"Webhook Trigger": {
"main": [
[
{
"node": "AI Request Parser",
"type": "main",
"index": 0
}
]
]
},
"Hotel Search API": {
"main": [
[
{
"node": "Hotel Booking Processor",
"type": "main",
"index": 0
}
]
]
},
"AI Request Parser": {
"main": [
[
{
"node": "Booking Type Router",
"type": "main",
"index": 0
}
]
]
},
"Flight Search API": {
"main": [
[
{
"node": "Flight Booking Processor",
"type": "main",
"index": 0
}
]
]
},
"Booking Type Router": {
"main": [
[
{
"node": "Flight Data Processor",
"type": "main",
"index": 0
}
],
[
{
"node": "Hotel Data Processor",
"type": "main",
"index": 0
}
]
]
},
"Hotel Data Processor": {
"main": [
[
{
"node": "Hotel Search API",
"type": "main",
"index": 0
}
]
]
},
"Flight Data Processor": {
"main": [
[
{
"node": "Flight Search API",
"type": "main",
"index": 0
}
]
]
},
"Hotel Booking Processor": {
"main": [
[
{
"node": "Confirmation Message Generator",
"type": "main",
"index": 0
}
]
]
},
"Send Confirmation Email": {
"main": [
[
{
"node": "Send Response",
"type": "main",
"index": 0
}
]
]
},
"Flight Booking Processor": {
"main": [
[
{
"node": "Confirmation Message Generator",
"type": "main",
"index": 0
}
]
]
},
"Confirmation Message Generator": {
"main": [
[
{
"node": "Send Confirmation Email",
"type": "main",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Support Chatbot、AI Chatbot等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Oneclick AI Squad
@oneclick-aiThe AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.
分享此工作流