This project demonstrates how to transition a traditional chatbot, initially interacted with through Selenium, to a more scalable and robust API-driven model. By leveraging Flask-SocketIO, this transformation enhances the chatbot's responsiveness and allows for real-time interaction without the overhead of a browser interface.
Originally, the chatbot was controlled via a Selenium-driven script that simulated user interactions directly in a web browser. This approach, while straightforward, does not scale well and is limited by the performance of the web browser and the visibility of the web elements. To address these limitations, this project introduces an API layer, enabling direct communication with the chatbot backend without the need for a graphical interface.
- Flask: A lightweight WSGI web application framework in Python, used to create the API.
- Flask-SocketIO: Facilitates real-time bi-directional communications between the clients and the server.
- Selenium: Previously used for automating web browsers, now phased out from direct chatbot interaction but still useful for certain automated tasks in the project.
- JavaScript (with Socket.IO client): Handles real-time communication on the client side, allowing users to interact with the chatbot through a web interface.
Before you can run this project, you will need:
- Python 3.6+
- pip (Python package installer)
-
Clone the Repository:
git clone https://github.com/yourusername/chatbot-api-integration.git cd chatbot-api-integration
-
Set up a Virtual Environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Required Python Packages:
pip install flask flask-socketio
-
Run the Application:
python app.py
This command starts the Flask server with Socket.IO integration.
Once the server is running, you can open a web browser and visit http://localhost:5000
to interact with the chatbot via the provided user interface. The UI allows you to send messages to the chatbot and receive responses in real-time.
- Real-Time Interaction: Users can communicate with the chatbot without delay, as messages are transmitted over WebSockets using Flask-SocketIO.
- API-Driven: Removes the dependency on a physical or simulated browser, enhancing performance and reliability.
- Scalability: Easier to scale the backend for handling multiple simultaneous user sessions.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.