This project is a FastAPI application that integrates with LINE Messaging API, Gemini AI, and Firebase to handle various types of messages and provide intelligent responses.
- Health Check Endpoint: Simple endpoint to check if the service is running.
- LINE Webhook Handler: Handles incoming messages from LINE and responds accordingly.
- Gemini AI Integration: Uses Gemini AI to process and generate responses based on the content of the messages.
- Firebase Integration: Stores and retrieves chat history from Firebase.
- Python 3.7+
- LINE Messaging API account
- Gemini AI API key
- Firebase project
- .env file with the following environment variables:
API_ENV
LINE_CHANNEL_SECRET
LINE_CHANNEL_ACCESS_TOKEN
LOG
FIREBASE_URL
GEMINI_API_KEY
OPEN_API_KEY
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root directory and add the required environment variables.
-
Run the FastAPI application:
uvicorn main:app --host 0.0.0.0 --port 8080 --reload
-
The application will start and listen for incoming requests on the specified port.
- GET /health: Health check endpoint to verify if the service is running.
- POST /webhooks/line: Webhook endpoint to handle incoming messages from LINE.
API_ENV
: Set toproduction
ordevelop
.LINE_CHANNEL_SECRET
: Your LINE channel secret.LINE_CHANNEL_ACCESS_TOKEN
: Your LINE channel access token.LOG
: Logging level (default isWARNING
).FIREBASE_URL
: Your Firebase database URL.GEMINI_API_KEY
: Your Gemini AI API key.OPEN_API_KEY
: Your Open Data API key.
The application uses Python's built-in logging module. The log level can be set using the LOG
environment variable.
This project is licensed under the MIT License.