UNPKG

n8n-nodes-hotelplanet

Version:

n8n node for HotelPlanet booking operations - AI Agent compatible

450 lines 19.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HotelPlanet = void 0; const n8n_workflow_1 = require("n8n-workflow"); const axios_1 = __importDefault(require("axios")); class HotelPlanet { constructor() { this.description = { displayName: 'HotelPlanet', name: 'hotelPlanet', icon: 'fa:hotel', group: ['transform'], version: 1, description: 'Complete hotel booking and management system. Search hotels, check availability, make bookings, and manage reservations. Perfect for travel agencies, booking platforms, and hotel management workflows.', defaults: { name: 'HotelPlanet', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'hotelPlanetApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Get Hotels by Location', value: 'getHotelsByLocation', description: 'Search for hotels by country and/or city with filters', action: 'Get hotels by location', }, { name: 'Search Hotels', value: 'searchHotels', description: 'Search hotels by name, description, or location', action: 'Search hotels', }, { name: 'Get Hotel Details', value: 'getHotelDetails', description: 'Get detailed information about a specific hotel', action: 'Get hotel details', }, { name: 'Check Availability', value: 'checkAvailability', description: 'Check hotel availability for specific dates and guests', action: 'Check hotel availability', }, { name: 'Book Hotel', value: 'bookHotel', description: 'Book a hotel room with guest information', action: 'Book a hotel room', }, { name: 'Get Booking Details', value: 'getBookingDetails', description: 'Get details of a specific booking', action: 'Get booking details', }, { name: 'Cancel Booking', value: 'cancelBooking', description: 'Cancel an existing booking', action: 'Cancel a booking', }, { name: 'Get User Bookings', value: 'getUserBookings', description: 'Get all bookings for a user by email', action: 'Get user bookings', }, ], default: 'getHotelsByLocation', }, { displayName: 'Country', name: 'country', type: 'string', default: '', displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'Country name (optional)', }, { displayName: 'City', name: 'city', type: 'string', default: '', displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'City name (optional)', }, { displayName: 'Min Price', name: 'minPrice', type: 'number', default: 0, displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'Minimum price filter', }, { displayName: 'Max Price', name: 'maxPrice', type: 'number', default: 0, displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'Maximum price filter', }, { displayName: 'Rating', name: 'rating', type: 'number', default: 0, displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'Minimum rating filter', }, { displayName: 'Amenities', name: 'amenities', type: 'string', default: '', displayOptions: { show: { operation: ['getHotelsByLocation'], }, }, description: 'Comma-separated list of amenities', }, { displayName: 'Search Query', name: 'query', type: 'string', default: '', displayOptions: { show: { operation: ['searchHotels'], }, }, description: 'Search query for hotel name, description, or location', }, { displayName: 'Hotel ID', name: 'hotelId', type: 'string', default: '', displayOptions: { show: { operation: ['getHotelDetails', 'checkAvailability', 'bookHotel'], }, }, description: 'Hotel ID', }, { displayName: 'Check-in Date', name: 'checkIn', type: 'dateTime', default: '', displayOptions: { show: { operation: ['checkAvailability', 'bookHotel'], }, }, description: 'Check-in date', }, { displayName: 'Check-out Date', name: 'checkOut', type: 'dateTime', default: '', displayOptions: { show: { operation: ['checkAvailability', 'bookHotel'], }, }, description: 'Check-out date', }, { displayName: 'Number of Guests', name: 'guests', type: 'number', default: 1, displayOptions: { show: { operation: ['checkAvailability', 'bookHotel'], }, }, description: 'Number of guests', }, { displayName: 'Number of Rooms', name: 'rooms', type: 'number', default: 1, displayOptions: { show: { operation: ['checkAvailability'], }, }, description: 'Number of rooms needed', }, { displayName: 'Room IDs', name: 'roomIds', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Comma-separated list of room IDs to book', }, { displayName: 'Guest First Name', name: 'firstName', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Guest first name', }, { displayName: 'Guest Last Name', name: 'lastName', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Guest last name', }, { displayName: 'Guest Email', name: 'email', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Guest email address', }, { displayName: 'Guest Phone', name: 'phone', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Guest phone number', }, { displayName: 'Special Requests', name: 'specialRequests', type: 'string', default: '', displayOptions: { show: { operation: ['bookHotel'], }, }, description: 'Special requests (optional)', }, { displayName: 'Booking ID', name: 'bookingId', type: 'string', default: '', displayOptions: { show: { operation: ['getBookingDetails', 'cancelBooking'], }, }, description: 'Booking ID', }, { displayName: 'User Email', name: 'userEmail', type: 'string', default: '', displayOptions: { show: { operation: ['getUserBookings'], }, }, description: 'User email address', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const credentials = await this.getCredentials('hotelPlanetApi'); const baseUrl = credentials.baseUrl || 'http://localhost:3000'; for (let i = 0; i < items.length; i++) { try { const operation = this.getNodeParameter('operation', i); let response; switch (operation) { case 'getHotelsByLocation': const country = this.getNodeParameter('country', i); const city = this.getNodeParameter('city', i); const minPrice = this.getNodeParameter('minPrice', i); const maxPrice = this.getNodeParameter('maxPrice', i); const rating = this.getNodeParameter('rating', i); const amenities = this.getNodeParameter('amenities', i); const params = new URLSearchParams(); if (country) params.append('country', country); if (city) params.append('city', city); if (minPrice > 0) params.append('minPrice', minPrice.toString()); if (maxPrice > 0) params.append('maxPrice', maxPrice.toString()); if (rating > 0) params.append('rating', rating.toString()); if (amenities) params.append('amenities', amenities); response = await axios_1.default.get(`${baseUrl}/api/hotels?${params.toString()}`); break; case 'searchHotels': const query = this.getNodeParameter('query', i); response = await axios_1.default.get(`${baseUrl}/api/hotels/search?query=${encodeURIComponent(query)}`); break; case 'getHotelDetails': const hotelId = this.getNodeParameter('hotelId', i); response = await axios_1.default.get(`${baseUrl}/api/hotels/${hotelId}`); break; case 'checkAvailability': const checkIn = this.getNodeParameter('checkIn', i); const checkOut = this.getNodeParameter('checkOut', i); const guests = this.getNodeParameter('guests', i); const rooms = this.getNodeParameter('rooms', i); const availabilityHotelId = this.getNodeParameter('hotelId', i); response = await axios_1.default.post(`${baseUrl}/api/availability`, { hotelId: availabilityHotelId, checkIn: new Date(checkIn).toISOString().split('T')[0], checkOut: new Date(checkOut).toISOString().split('T')[0], guests, rooms, }); break; case 'bookHotel': const bookHotelId = this.getNodeParameter('hotelId', i); const roomIds = this.getNodeParameter('roomIds', i); const bookCheckIn = this.getNodeParameter('checkIn', i); const bookCheckOut = this.getNodeParameter('checkOut', i); const bookGuests = this.getNodeParameter('guests', i); const firstName = this.getNodeParameter('firstName', i); const lastName = this.getNodeParameter('lastName', i); const bookEmail = this.getNodeParameter('email', i); const bookPhone = this.getNodeParameter('phone', i); const specialRequests = this.getNodeParameter('specialRequests', i); response = await axios_1.default.post(`${baseUrl}/api/bookings`, { hotelId: bookHotelId, roomIds: roomIds.split(',').map(id => id.trim()), checkIn: new Date(bookCheckIn).toISOString().split('T')[0], checkOut: new Date(bookCheckOut).toISOString().split('T')[0], guestInfo: { firstName, lastName, email: bookEmail, phone: bookPhone, }, guests: bookGuests, specialRequests, }); break; case 'getBookingDetails': const bookingId = this.getNodeParameter('bookingId', i); response = await axios_1.default.get(`${baseUrl}/api/bookings/${bookingId}`); break; case 'cancelBooking': const cancelBookingId = this.getNodeParameter('bookingId', i); response = await axios_1.default.delete(`${baseUrl}/api/bookings/${cancelBookingId}`); break; case 'getUserBookings': const userEmail = this.getNodeParameter('userEmail', i); response = await axios_1.default.get(`${baseUrl}/api/bookings/user/${encodeURIComponent(userEmail)}`); break; default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation ${operation} not supported`); } if (response.data.success) { returnData.push({ json: response.data, }); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), response.data.error || 'API request failed'); } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error instanceof Error ? error.message : String(error), }, }); continue; } throw error; } } return [returnData]; } } exports.HotelPlanet = HotelPlanet; //# sourceMappingURL=HotelPlanet.node.js.map