This publication was originally written in Spanish. You're viewing an automated translation into English.
This project is a tourism chatbot developed in TypeScript using Express.js, LangChain and LangGraph and Vite.
The chatbot interacts with several external APIs to provide information about weather, hotels, flights and
tourist activities. It also manages conversations with users through a thread and memory system,
using specialized agents for each task.
-Weather Query: Obtain weather information using the OpenWeatherMap API.
-Hotel availability: Check hotel availability using the Amadeus API.
-Flight Search: Search for flights using the Amadeus API.
-Tourist Activities: Suggests tourist activities based on the city and budget, integrating links
to Civitatis for complete options.
-Conversation management: Maintains a history of conversations per user using a threading system and
LangChain agents.
-Specialized Agents: Use LangChain agents to handle specific tasks, such as flight search,
hotels and weather
-Frontend with Vite: The frontend is developed with Vite, a modern tool that offers performance
superior and a faster development experience.
OpenWeatherMap: For weather information.
OpenWeatherMap documentation: https://www.weatherapi.com/my/#
Amadeus: To check hotel and flight availability.
Civitatis: For tourist activities and tours.
Civitatis documentation: https://www.civitatis.com/ar
Open_AI: to generate natural language tools.
Open_AI documentation: https://platform.openai.com/docs/overview
Makcorps: To obtain city codes.
Makcorps Documentation: https://docs.makcorps.com/
#############################################################################################################
Choosing Amadeus over Makcorps
The choice of Amadeus over Markcorps is because Markcorps offers a more complete and robust API for
The flight and hotel search only allows about 10 test calls in its FREE version.
For further inquiries it is already paid, US$ 350 per month 10k free per month.
So this example is done with Amadeus, which does not have an updated list of hotels in some locations.
#############################################################################################################
-LangChain
LangChain is used to manage agent logic and interaction with external APIs.
Agents are responsible for handling specific tasks, such as searching for flights, hotels, and weather.
Each agent is designed to interact with a specific API and return structured results.
-LangGraph
LangGraph is used to manage the flow of conversations and user memory. It allows you to maintain
a history of interactions per user and manage conversation threads efficiently.
-Agents
Weather Agent: Interact with OpenWeatherMap to obtain weather information.
Hotel Agent: Interact with the Amadeus API to check hotel availability.
Flight Agent: Interact with the Amadeus API to search for flights.
Activities Agent: Suggests tourist activities based on city and budget, integrating links
to Civitatis.
The project follows a modular architecture based on layers:
Routes Layer: Defines the API endpoints (index.ts and routes/chat.ts).
Controller Layer: Handles business logic and interactions with LangChain agents.
Agent Layer: Contains specialized agents that interact with external APIs
(agents/WeatherAgent.ts, agents/HotelAgent.ts, etc.).
Utility Layer: Helper functions for handling data and additional logic
(utils/extracTravelinfo.ts, utils/process_messages.ts).
Memory Layer: Manages the state of conversations using threads and LangGraph
(utils/thread_management.ts).
Architecture Diagram
plaintext
Copy
Frontend (Vite + React)
|
v
Backend (Express.js)
|
v
LangChain (Agents)
|
v
-Facility
Follow these steps to install and run the frontend and backend in your local environment.
-Prerequisites
Node.js (v16 or higher)
npm (v8 or higher)
API keys for OpenWeatherMap, Amadeus, and Makcorps.
Clone the repository:
git clone https://github.com/your-user/your-repository.git
cd your-repository
-Install the dependencies:
npm install
-Create a .env file in the root of your project and add your API keys:
.env
API_KEY_OPEN_AI= your_api_key_openai
Api_weather_next= your_api_key_openweather
id_weather_day= your_api_key_id_wather
AMADEUS_CLIENT_ID = your_api_key_Amadeus
AMADEUS_CLIENT_SECRET=your_api_key_secret_Amadeus
-Start the frontend and backend servers in development mode:
we opened 2 terminals
Terminal 1: Start the frontend server with Vite:
npx vite
Terminal 2: Start the backend server with Express.js:
npm i
npm run build
npm run dev
The chatboot will be available at http://localhost:3000 .
URL: /chatboot
Description: Handles the chatbot's interactions with users.
Input:{
"city": "MAD",
"destination": "BAR",
"checkInDate": "2023-01-01",
"checkOutDate": "2023-01-02"
}
Output:
"Here are some flights from BAR to MAD for 2025-02-25:\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-26T13:45:00, Price: 564.78 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-26T19:55:00, Price: 564.78 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-26T13:50:00, Price: 666.12 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-27T08:00:00, Price: 781.22 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-27T08:00:00, Price: 781.22 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-27T08:00:00, Price: 781.22 EUR\n-
Departure: BAR at 2025-02-25T19:25:00, Arrival: MAD at 2025-02-27T08:00:00, Price: 781.22 EUR\n-
...............
hotels
:
"[{"chainCode":"AR","iataCode":"MAD","dupeId":700025872,"name":"AC BY MARRIOTT ALCALA DE HENAR",
"hotelId":"ARMADALC","availability":{"data":[{"type":"hotel-offers","hotel":{"type":"hotel",
"hotelId":"ARMADALC","chainCode":"AR","dupeId":"700025872","name":"AC by Marriott Hotel Alcala de
Henares","cityCode":"MAD","latitude":40.5028,"longitude":-3.36574},"available"
message
:
"Your trip from BAR to MAD from 2025-02-25 to 2025-03-04 has been recorded."
returnFlights
:
"Here are some flights from MAD to BAR for 2025-03-04:\n-
Departure: MAD at 2025-03-04T05:50:00, Arrival: BAR at 2025-03-05T18:35:00, Price: 317.34 EUR\n-
Departure: MAD at 2025-03-04T10:30:00, Arrival: BAR at 2025-03-06T18:35:00, Price: 685.63 EUR\n-
Departure: MAD at 2025-03-04T10:30:00, Arrival: BAR at 2025-03-06T18:35:00, Price: 685.63 EUR\n-
Departure: MAD at 2025-03-04T10:30:00, Arrival: BAR at 2025-03-06T18:35:00, Price: 685.63 EUR\n-
Departure: MAD at 2025-03-04T10:30:00, Arrival: BAR at 2025-03-06T18:35:00, Price: 685.63 EUR\n-
Departure: MAD at 2025-03-04T10:30:00, Arrival: BAR at 2025-03-06T18:35:00, Price: 685.63 EUR\n-
...........................................
weather
:
climate
:
{location: 'Mรกd', temperature: 1.09, description: 'overcast clouds', humidity: 79, wind: 1.39}
listOfItems
:
"Underwear, Socks, Personal hygiene items, Phone charger, Power adapter
(if necessary), Coat, Scarf, Hat, Gloves, Closed shoes"
URL: /test-full-flow
Description: Get combined hotel, flight, and weather information for a specific city and date.
Input:
{
"city": "Paris",
"destination": "Paris",
"checkInDate": "2023-01-01",
"checkOutDate": "2023-01-02"
}
Output:
{
"weather": { ... },
"flights": { ... },
"hotels": { ... }
}
Evidence
You can test the chatbot and the entire flow using cURL or any other API testing tool.
Below are examples of how to test endpoints:
curl -X POST http://localhost:3000/chatboot
-H "Content-Type: application/json"
-d '{"city": "Paris", "destination": "Paris", "checkInDate": "2023-01-01", "checkOutDate": "2023-01-02"}'
Endpoint Test /test-full-flow
curl -X POST http://localhost:3000/test-full-flow \
-H "Content-Type: application/json"
-d '{"city": "Paris", "destination": "Paris", "checkInDate": "2023-01-01", "checkOutDate": "2023-01-02"}'
Contributions
If you would like to contribute to this project, please follow these steps:
Fork the repository.
Create a branch for your contribution (git checkout -b feature/new-feature).
Make your changes and commit (git commit -m "Add new functionality").
Push your changes (git push origin feature/new-feature).
Open a Pull Request on GitHub.
Frontend with Vite
The frontend of this project is developed with Vite, which allows for a fast and efficient development experience.
efficient. The following describes the flow of interaction with the chatbot from the front end:
Data Entry:
The user enters the origin, destination, start date, and return date into the chatbot interface.
This data is sent to the backend via an HTTP request.
Processing in the Backend:
The backend processes the request, queries the corresponding APIs (weather, flights, hotels) and generates a response.
structured.
Results Display:
The frontend receives the response from the backend and displays it to the user in a clear and organized manner.
Weather data, extra tips, round-trip flights, available hotels, and a link to
tourist activities in Civitatis.
Choosing Amadeus over Makcorps
The choice of Amadeus over Makcorps is because Amadeus offers a more complete and robust API for
Flight and hotel searches, with more detailed documentation and broader support. In addition,
Amadeus is one of the leading booking platforms in the travel industry, ensuring
greater accuracy and availability of data.