āļĢāļąāļāđāļāļĨāđāļāļēāļ LINE āļāļąāļāđāļŦāļĨāļāļŠāļđāđ Google Drive āļāļąāļāđāļāļĄāļąāļāļī
This workflow automatically saves files received via LINE Messaging API into Google Drive and logs the file details into a Google Sheet. It checks the file type against allowed types, organizes files into date-based folders and (optionally) file typeâspecific subfolders, and sends a reply message back to the LINE user with the file URL or an error message if the file type is not permitted.
What Problem Does This Workflow Solve?
Automated File Organization: Files received from LINE are automatically checked for allowed file types, then stored in a structured folder hierarchy in Google Drive (by date and/or file type).
Data Logging: Each file upload is recorded in a Google Sheet, providing an audit trail with file names, upload dates, URLs, and types.
Instant Feedback: Users receive an immediate reply via LINE confirming the file upload, or an error message if the file type is not allowed.
What This Workflow Does
1. Receives Incoming Requests:
- A webhook node (âLINE Webhook Listenerâ) listens for POST requests from LINE, capturing file upload events and associated metadata.
2. Configuration Loading:
- A Google Sheets node (âGet Configâ) reads configuration data (e.g., parent folder ID, allowed file types, folder organization settings, and credentials) from a pre-defined sheet.
Data Merging & Processing:
-
The âMerge Event and Config Dataâ and âProcess Event and Config Dataâ nodes merge and structure the event data with configuration settings.
-
A âDetermine Folder Infoâ node calculates folder names based on the configuration. If Store by Date is enabled, it uses the current date (or a specified date) as the folder name. If Store by File Type is also enabled, it uses the fileâs type (e.g., image) for a subfolder.
4. Folder Search & Creation:
-
The workflow searches for an existing date folder (âSearch Date Folderâ).
-
If the date folder is not found, an IF node (âCheck Existing Date Folderâ) routes to a âCreate Date Folderâ node.
-
Similarly, for file type organization, the workflow uses a âSearch FileType Folderâ node (with appropriate conditions) to look for a subfolder, or creates it if not found.
-
The âSet Date Folder IDâ and âSet Image Folder IDâ nodes capture and merge the resulting folder IDs.
-
Finally, the âConfig final ParentIdâ node sets the final target folder ID based on the configuration conditions:
-
Store by Date: TRUE, Store by File Type: TRUE: Use the file type folder (inside the date folder).
-
Store by Date: TRUE, Store by File Type: FALSE: Use the date folder.
-
Store by Date: FALSE, Store by File Type: TRUE: Use the file type folder.
-
Store by Date: FALSE, Store by File Type: FALSE: Use the Parent Folder ID from the configuration.
-
5. File Retrieval and Validation:
-
A HTTP Request node (âGet File Binary Contentâ) fetches the fileâs binary data from the LINE API.
-
A Function node (âValidate File Typeâ) checks if the fileâs MIME type is included in the allowed list (e.g., âaudio|image|videoâ). If not, it throws an error that is captured for the reply.
6. File Upload and Logging:
-
The âUpload File to Google Driveâ node uploads the validated binary file to the final target folder.
-
After a successful upload, the âLog File Details to Google Sheetâ node logs details such as file name, upload date, Google Drive URL, and file type into a designated Google Sheet.
7. User Feedback:
-
The âCheck Reply Enabled Flagâ node checks if the reply feature is enabled.
-
Finally, the âSend LINE Reply Messageâ node sends a reply message back to the LINE user with either the file URL (if the upload was successful) or an error message (if the file type was not allowed).
Setup Instructions
1. Google Sheets Setup:
-
Create a Google Sheet with two sheets:
-
config: Include columns for Parent Folder Path, Parent Folder ID, Store by Date (boolean), Store by File Type (boolean), Allow File Types (e.g., âaudio|image|videoâ), CurrentDate, Reply Enabled, and CHANNEL ACCESS TOKEN.
-
fileList: Create headers for File Name, Date Uploaded, Google Drive URL, and File Type.
-
For an example of the required format, check this Google Sheets template: Google Sheet Template
2. Google Drive Credentials:
- Set up and authorize your Google Drive credentials in n8n.
3. LINE Messaging API:
-
Configure your LINE Developer Console webhook to point to the n8n Webhook URL (âLine Chat Botâ node).
-
Ensure you have the proper Channel Access Token stored in your Google Sheet.
4. n8n Workflow Import:
-
Import the provided JSON file into your n8n instance.
-
Verify node connections and update any credential references as needed.
5. Test the Workflow:
- Send a test message via LINE to confirm that files are properly validated, uploaded, logged, and that reply messages are sent.
How to Customize This Workflow
-
Allowed File Types: Adjust the âValidate File Typeâ field in your config sheet to control which file types are accepted.
-
Folder Structure: Modify the logic in the âDetermine Folder Infoâ and subsequent folder nodes to change how folders are structured (e.g., use different date formats or add additional categorization).
-
Logging: Update the âLog File Details to Google Sheetâ node if you wish to log additional file metadata.
-
Reply Messages: Customize the reply text in the âSend LINE Reply Messageâ node to include more detailed information or instructions.
