FastHook 教程示範如何按寄件者及日期將 Gmail 附件存入 Google Drive 並通知 Telegram
Automate Gmail Attachments: Organize Files in Google Drive and Notify Telegram
Andrew Lencmanis 的 FastHook 教程示範以 AI Builder 建立流程,將 Gmail 附件按寄件者及收件日期存入 Google Drive,再經 Telegram 傳送連結。
An attachment arrives in Gmail. You download it, find the right folder in Drive, upload it, copy the link, and send it to a chat. The individual steps are small; remembering to do all of them is the tedious part.
This tutorial turns that routine into one workflow: receive an attachment, organize it by sender and date, save the file, and send a Telegram notification with its link.
Disclosure: I build FastHook, the automation platform used in this walkthrough. My earlier posts covered its webhook infrastructure. Here I’m showing the application-to-application workflows the product now supports.
Watch the walkthrough
The video shows the build, field mappings, test email, and results in Drive and Telegram. The written steps below let you follow along without repeatedly pausing it.
What we are building
The workflow has six stages:
- Gmail: receive a new attachment.
- Formatter: turn the email’s received date into a date folder name.
- Google Drive: find or create the folder path.
- Google Drive: upload the attachment into that folder.
- Google Drive: set the file’s viewing permission.
- Telegram: send a message containing the uploaded file’s link.
For example, a file could end up at:
Gmail attachments/
sender@example.com/
2026-10-26/
example-attachment.txt
That path is an illustration. The sender, date, and filename come from the actual email.
The workflow during setup. The status in this capture is not evidence of a completed delivery; we verify that separately below.
Before you start
Connect Gmail and Google Drive to FastHook. Connect the Telegram bot you will use, add it to the destination channel with permission to post, and have that channel’s Chat ID ready.
The bot connection and Chat ID serve different purposes: the connection determines which bot sends the message; the Chat ID determines where it goes. You do not need to paste a bot token into the message mapping.
Start with a harmless test attachment. This demonstration includes an explicit sharing step that lets anyone with the link view the uploaded file. If your attachments need restricted access, choose an appropriate Drive sharing setup instead. Sending a link to Telegram does not itself grant Drive access.
Before activating against a real inbox, restrict the Gmail trigger to the messages you intend to process using its search query. The recording includes a setup with an empty query; do not use that as the default for a personal mailbox.
1. Describe the process to AI Builder
Create a new workflow and open Build with AI. Describe both the desired result and the data each step needs.
Here is an English prompt adapted from the demonstrated process:
Create a draft workflow for new Gmail attachments.
Use the connected Gmail account. I will configure the Gmail search
query before activation to limit which messages are processed.
For each attachment event:
1. Format the email's Received Date as YYYY-MM-DD.
2. Find or create this Google Drive folder path:
Gmail attachments / Sender Email / formatted date.
3. Upload the attachment File into the final folder.
4. For this non-sensitive demonstration, share only the uploaded
file with permission type anyone and role reader.
5. Use the connected Telegram bot to send a message to a channel
whose Chat ID I will supply. Include the sender email, formatted
date, attachment filename, and the uploaded file's Web View Link.
Use dynamic outputs from earlier steps. Leave the workflow as a
draft so I can review the connections and mappings before activation.
Review the proposed steps, then choose Create draft. Treat the proposal as a starting point: check the selected accounts, action settings, and field mappings before turning it on.
2. Set up the Gmail trigger and date
Select New Attachment Received and the intended Gmail connection. Configure the search query for your test messages.
The recorded trigger uses polling at roughly five-minute intervals. It is not an instant push notification, so allow for a delay when testing. Check the interval shown in your own workflow.
Next, map Received Date from Gmail into the Formatter and format it as YYYY-MM-DD. The Formatter’s Output becomes the date segment of the folder path.
Using the email’s received date keeps the folder tied to the message rather than the time you happen to inspect the workflow.
3. Build the folder path from dynamic fields
In Find or Create Folder, combine a fixed parent folder with two dynamic values:
Gmail attachments / [Gmail: Sender Email] / [Formatter: Output]
Insert the dynamic values using the field picker. The bracketed names above describe those selections; they are not literal folder names to paste.
The action reuses an existing folder path or creates the missing folders. Its returned ID identifies the final date folder, which the upload step needs next.
4. Upload the actual attachment
The two mappings that matter here are:
| Upload File input | Value from an earlier step |
|---|---|
| File | Gmail trigger → File |
| Destination folder | Find or Create Folder → ID |
Map the attachment’s File, not its name or the email body. A filename tells the next step what a file is called; it does not supply the file’s contents.
The upload produces a new file ID and Web View Link. Keep those outputs distinct: the sharing step uses the ID, while the Telegram message uses the link.
5. Set sharing and compose the notification
For the demonstration’s Share File action, use:
- File: the ID returned by Upload File.
-
Permission type:
anyone. -
Role:
reader.
This applies to that uploaded file, not the whole folder. A reader can view it without receiving editing permission.
In Telegram’s Send Message action, select your bot connection and supply the destination channel’s Chat ID. Build the message with dynamic fields:
New Gmail attachment saved to Google Drive
Sender: [Gmail: Sender Email]
Received date: [Formatter: Output]
Attachment: [Gmail: File → Name]
Link: [Upload File: Web View Link]
Again, use field selections for the values in brackets. A URL copied from a previous test would keep pointing to the old file; mapping Web View Link makes each notification refer to its own upload.
6. Test the complete route
Review the configuration, activate the workflow, and wait for ACTIVE before sending a new test email with a harmless attachment. Then allow time for Gmail polling.
Verify the result in three places:
- FastHook Run History: inspect the run and each action’s result. Configuration checks alone do not prove that a file was uploaded or a message delivered.
- Google Drive: open the parent folder, sender folder, and date folder. Confirm that the expected attachment is there.
- Telegram: check the notification, open its link, and confirm that it opens the same file with the intended access.
The video shows this sequence with a test text attachment, and the polling wait is shortened in the recording. The demonstration workflow was paused after testing.
This walkthrough verifies a single-attachment example. If your real emails have several attachments, test that case separately and check the number of files and notifications before relying on it.
When the result is not what you expect
| Symptom | First thing to inspect |
|---|---|
| No run appears | Activation status, Gmail connection, search query, and polling delay |
| File lands in the wrong folder | Sender/date mapping and the destination folder ID |
| Upload fails | Whether File contains the attachment rather than a filename or email text |
| Telegram shows an old file | Whether the message maps the current upload’s Web View Link |
| Recipient cannot open the link | The uploaded file’s Drive permission |
| No Telegram message arrives | Bot connection, channel Chat ID, posting permissions, and the action result |
The useful part of this workflow is the handoff between applications: email metadata determines the folder, the folder ID determines the upload location, and the upload’s link becomes the notification. AI Builder helps assemble the steps; checking those handoffs makes the automation understandable and testable.
What would you add to this process for your own work: filtering attachments, a different folder structure, or a different notification destination?
來源:DEV Community · dev.to


