This project is a LINE bot that uses Google ADK (Agent SDK) and Google Gemini models to generate responses to text inputs. The bot can answer questions in Traditional Chinese and provide helpful information.
- Text message processing using AI models (Google ADK or Google Gemini)
- Support for function calling with custom tools
- Integration with LINE Messaging API
- Built with FastAPI for high-performance async processing
- Containerized with Docker for easy deployment
- Python 3.9+
- FastAPI
- LINE Messaging API
- Google ADK (Agent SDK)
- Google Gemini API
- Docker
- Google Cloud Run (for deployment)
-
Clone the repository to your local machine.
-
Set the following environment variables:
ChannelSecret
: Your LINE channel secretChannelAccessToken
: Your LINE channel access tokenGEMINI_API_KEY
: Your Google Gemini API key
-
Install the required dependencies:
pip install -r requirements.txt
-
Start the FastAPI server:
uvicorn main:app --reload
-
Set up your LINE bot webhook URL to point to your server's endpoint.
Send any text message to the LINE bot, and it will use the configured AI model to generate a response. The bot is optimized for Traditional Chinese responses.
The bot can be configured with various function tools such as:
- Weather information retrieval
- Translation services
- Data lookup capabilities
- Custom tools based on your specific needs
Use ngrok or similar tools to expose your local server to the internet for webhook access:
ngrok http 8000
You can use the included Dockerfile to build and deploy the application:
docker build -t linebot-adk .
docker run -p 8000:8000 \
-e ChannelSecret=YOUR_SECRET \
-e ChannelAccessToken=YOUR_TOKEN \
-e GEMINI_API_KEY=YOUR_GEMINI_KEY \
linebot-adk
- Install the Google Cloud SDK
- Create a Google Cloud project and enable the following APIs:
- Cloud Run API
- Container Registry API or Artifact Registry API
- Cloud Build API
-
Authenticate with Google Cloud:
gcloud auth login
-
Set your Google Cloud project:
gcloud config set project YOUR_PROJECT_ID
-
Build and push the Docker image to Google Container Registry:
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/linebot-adk
-
Deploy to Cloud Run:
gcloud run deploy linebot-adk \ --image gcr.io/YOUR_PROJECT_ID/linebot-adk \ --platform managed \ --region asia-east1 \ --allow-unauthenticated \ --set-env-vars ChannelSecret=YOUR_SECRET,ChannelAccessToken=YOUR_TOKEN,GEMINI_API_KEY=YOUR_GEMINI_KEY
Note: For production, it's recommended to use Secret Manager for storing sensitive environment variables.
-
Get the service URL:
gcloud run services describe linebot-adk --platform managed --region asia-east1 --format 'value(status.url)'
-
Set the service URL as your LINE Bot webhook URL in the LINE Developer Console.
For better security, store your API keys as secrets:
-
Create secrets for your sensitive values:
echo -n "YOUR_SECRET" | gcloud secrets create line-channel-secret --data-file=- echo -n "YOUR_TOKEN" | gcloud secrets create line-channel-token --data-file=- echo -n "YOUR_GEMINI_KEY" | gcloud secrets create gemini-api-key --data-file=-
-
Give the Cloud Run service access to these secrets:
gcloud secrets add-iam-policy-binding line-channel-secret --member=serviceAccount:YOUR_PROJECT_NUMBER-compute@developer.gserviceaccount.com --role=roles/secretmanager.secretAccessor gcloud secrets add-iam-policy-binding line-channel-token --member=serviceAccount:YOUR_PROJECT_NUMBER-compute@developer.gserviceaccount.com --role=roles/secretmanager.secretAccessor gcloud secrets add-iam-policy-binding gemini-api-key --member=serviceAccount:YOUR_PROJECT_NUMBER-compute@developer.gserviceaccount.com --role=roles/secretmanager.secretAccessor
-
Deploy with secrets:
gcloud run deploy linebot-adk \ --image gcr.io/YOUR_PROJECT_ID/linebot-adk \ --platform managed \ --region asia-east1 \ --allow-unauthenticated \ --update-secrets=ChannelSecret=line-channel-secret:latest,ChannelAccessToken=line-channel-token:latest,GEMINI_API_KEY=gemini-api-key:latest
After deployment, you can monitor your service through the Google Cloud Console:
- View logs:
gcloud logging read "resource.type=cloud_run_revision AND resource.labels.service_name=linebot-adk"
- Check service metrics: Access the Cloud Run dashboard in Google Cloud Console
- Set up alerts for error rates or high latency in Cloud Monitoring