Currently, there are many frameworks related to Agents, but Google recently announced a rather interesting transmission protocol, Agent Payments Protocol (AP2), which is a set of agent frameworks for inventory management and payment.
Sample Code
https://github.com/kkdai/linebot-ap2
Stars and sharing are welcome. If you find it useful, you are also welcome to contribute and add new features.
✨ Main Feature Introduction
This LINE bot, built with Golang, provides the following super practical features:
- Multimedia File Backup: Supports backing up images, videos, audio, and general files from LINE chats to Google Drive.
- Smart Folder Organization: Automatically creates a
LINE Bot Uploadsfolder in Google Drive and crea…
Currently, there are many frameworks related to Agents, but Google recently announced a rather interesting transmission protocol, Agent Payments Protocol (AP2), which is a set of agent frameworks for inventory management and payment.
Sample Code
https://github.com/kkdai/linebot-ap2
Stars and sharing are welcome. If you find it useful, you are also welcome to contribute and add new features.
✨ Main Feature Introduction
This LINE bot, built with Golang, provides the following super practical features:
- Multimedia File Backup: Supports backing up images, videos, audio, and general files from LINE chats to Google Drive.
- Smart Folder Organization: Automatically creates a
LINE Bot Uploadsfolder in Google Drive and creates subfolders by year and month (YYYY-MM), keeping your cloud drive clean and tidy. - Secure Account Linking: Uses Google OAuth 2.0 authorization to ensure secure and reliable connections.
- Quick File Query: Enter the
/recent_filescommand to quickly view the 5 most recently uploaded files. - Flexible Connection Control: Disconnect from Google Drive and revoke authorization at any time via the
/disconnect_drivecommand.
Comparison of Two Upload Methods for LINE Bot File Backup to Google Drive
This LINE file backup bot, written in Golang, allows users to easily back up files from chat rooms to Google Drive. The project supports two methods for uploading to Google Drive: Google Cloud Service Account and Google OAuth 2.0. Below is a comparison table that details the operation, advantages, and disadvantages of these two methods to help developers choose the most suitable implementation method.
Comparison Table
| Item | Google Cloud Service Account | Google OAuth 2.0 |
|---|---|---|
| Operation | Uses the service account credentials (JSON file) from the Google Cloud project, representing the application directly accessing the Google Drive API, without the need for user manual authorization. | Users authorize through the OAuth 2.0 process, allowing the bot to access their Google Drive account on their behalf. |
| Configuration Complexity | Medium: Requires creating a service account in the Google Cloud Console, generating credentials, and sharing specific Google Drive folders with the service account. | Higher: Requires setting up an OAuth consent screen, creating a Web application credential, and handling callback URLs and token management. |
| User Experience | No user intervention required, files are directly uploaded to the default Google Drive folder (usually owned or shared by the service account). | Users need to manually click the authorization link to complete the OAuth process; after authorization, files are uploaded to the user’s own Google Drive. |
| Permission Control | The service account has fixed access permissions; you need to manually share folders with the service account; permission management is more centralized. | Users can control the authorization scope (e.g., only allowing access to specific folders) and can revoke permissions at any time (/disconnect_drive). |
| Main Advantages | - High degree of automation, no need for user manual authorization. - Suitable for centralized file management (e.g., enterprise scenarios). - Almost no user interaction required after deployment. | - Users have complete control over files, meeting personalization needs. - Supports dynamic permission management, higher security. - Suitable for multi-user scenarios, each person backs up to their own Google Drive. |
| Main Disadvantages | - Files are stored in the service account’s Google Drive or shared folders; individual users may not be able to manage them directly. - Requires additional folder sharing setup, increasing initial configuration complexity. - Not suitable for multi-user scenarios (unless setting up independent folders for each user). | - Users need to complete the OAuth authorization process, affecting the initial experience. - Requires token update management (refresh token), more complex code. - Requires handling callback URLs during deployment, increasing setup steps. |
| Suitable Scenarios | Enterprises or centralized applications where administrators want to centrally manage all backup files. | Personalized applications where users want files stored in their own Google Drive and retain complete control. |
| Code Implementation Example | (Here you can paste a Golang code snippet using Google Cloud Service Account, such as the logic for initializing the service account and uploading files.) | (Here you can paste a Golang code snippet using Google OAuth 2.0, such as handling the OAuth process and uploading files.) |
Detailed Explanation of the Two Methods
Google Cloud Service Account
-
How it works: A service account is a non-human account provided by Google Cloud, which authenticates through a JSON credential file. Your LINE bot uses the service account’s credentials to directly call the Google Drive API and upload files to the specified folder. This folder can be the service account’s own Google Drive, or a folder shared with the service account by the administrator.
-
Advantages:
-
No user intervention required, suitable for fully automated processes.
-
Suitable for enterprise scenarios, such as backing up all employees’ LINE chat files to a company-managed Google Drive.
-
Relatively simple code, just initialize the service account and set up API calls.
-
Disadvantages:
-
Files are stored in the service account’s Google Drive or shared folders, and users cannot manage them directly (unless through shared permissions).
-
If each user needs an independent folder, additional program logic is required to dynamically manage folder sharing.
-
Initial setup requires manually sharing the Google Drive folder with the service account’s email address.
(You can paste the Golang code for the service account here, such as using the google.golang.org/api/drive/v3 package to initialize the service account and upload file snippets.)
Google OAuth 2.0
-
How it works: Users click the
/connect_drivecommand in the LINE bot, triggering the OAuth 2.0 authorization process, allowing the bot to access their Google Drive. The bot obtains an access token and a refresh token to represent the user and upload files to their personal Google Drive. -
Advantages:
-
Users have complete control over the files, and the files are stored directly in their own Google Drive.
-
Supports dynamic permission management; users can revoke authorization at any time (via
/disconnect_drive). -
Suitable for personalized applications, especially multi-user scenarios, where each person backs up to their own Google Drive.
-
Disadvantages:
-
Users need to manually complete the OAuth authorization process, which may affect the initial experience.
-
The code needs to handle token management (e.g., updating expired access tokens), increasing development complexity.
-
Requires setting up a callback URL (redirect URI) during deployment and ensuring it is consistent with the Cloud Run URL.
(You can paste the OAuth Golang code here, such as using the golang.org/x/oauth2 package to handle the authorization process and file upload snippets.)
🚀 Deploying on Google Cloud Platform
This project is developed using Golang and has been containerized (including Dockerfile), making it very suitable for deployment on Google Cloud Run. Cloud Run provides a fully managed serverless environment, and automatic scaling is super convenient! Here are the complete deployment steps.
Prerequisites
Before you start, please make sure you have prepared:
- A Google Cloud account.
- Google Cloud SDK (gcloud CLI) installed and configured.
- A LINE Bot channel and obtain the Channel Secret and Channel Access Token.
Deployment Steps
1. Enable Required APIs
To ensure the bot works correctly, you need to enable the following services in your Google Cloud project:
- Cloud Run API
- Cloud Build API (used to automatically build container images)
- Firestore API (used to store user authorization data)
Run the following command in the terminal to quickly enable:
gcloud services enable run.googleapis.com cloudbuild.googleapis.com firestore.googleapis.com
2. Create a Firestore Database
- Go to the Firestore page in the Google Cloud Console.
- Select "Native mode".
- Choose the region closest to your users, and then create a database.
3. Obtain Google OAuth Credentials
This is a key step for the bot to access Google Drive:
-
Go to Google Cloud Console > APIs & Services > Credentials. (Google Auth Platform)
-
Click + CREATE CREDENTIALS and select OAuth client ID.
-
Select Web application in Application type, and name it (e.g., "LINE Bot File Uploader").
-
Do not fill in Authorized redirect URIs in this step; wait until Cloud Run is deployed and then come back to set it up.
-
After creation, you will get a set of Client ID and Client Secret, please keep them safe, they will be used later.
Results Display
-
If not authenticated, a prompt to authenticate will appear.
-
Click the URL to authenticate Google Drive upload permissions.
-
If you don’t want to use it, you can also use
/disconnect_driveto revoke the relevant authorization. -
Uploading files is also simple, supporting two formats.
-
Directly upload images, which will be uploaded to Google Drive for saving.
-
Through iOS / AOS, paste PDF or any file format into the chat window. You can also accurately upload to Google Drive. Files can also exceed 50MB
-
To view files, click "Query Recent Files," which will open the Google Drive webpage to view the file list.
Future Prospects
This LINE file backup bot, developed with Golang, opens up many interesting application scenarios:
- Automated File Management: Automatically organize your LINE chat files to Google Drive, saving time and effort.
- Team Collaboration: Quickly back up and share files in group chats, improving work efficiency.
- Personalized Features: Expand features according to needs, such as customizing folder structures or file naming rules.
- Data Analysis: Analyze the types and frequencies of uploaded files to optimize bot functions or provide usage statistics.
(If you have other Golang code snippets, such as handling Google Drive API or Firestore, you can paste them here to further demonstrate the application of Golang in this project.)
These applications can not only improve the file management experience for individuals and teams but also bring more creative application inspiration to developers. Quickly deploy your LINE file backup bot and experience the convenience of Golang and cloud integration!