How I automated Gmail for Telegram notifications using AI and Google Apps Script
If you’re like me, your Gmail inbox gets many new emails every day – but only a few of those are truly important. I found myself constantly refreshing my inbox, endlessly checking for the one reply I was waiting on. Instead, I wanted a smart way to be alerted only to those important emails. That’s why I decided to automate Gmail notifications. The whole process, including figuring out what tools to use and testing it out, took me about two hours.
Automating with AI, Telegram, and Google Apps Script
With the help of AI tools (Windsurf with OpenAI o3 model), brainstorming and researching the solution took about 15 minutes. I needed something easy, with no costs or monthly fees, and I wanted to run it on my own Google account, instead of dealing with third-party servers or subscriptions. Also, I needed to forward these messages to some app that I use during the day – I chose Telegram.
To make it work, I went with Google Apps Script for automation, since it’s free and runs right inside your Google account, which made the process much quicker – generating scripts for checking Gmail and sending Telegram messages.
Creating a Telegram bot was straightforward: with the @BotFather in Telegram, I got my bot token and chat ID, then plugged those into my script.
My script ran this procedure: check Gmail for new, unread emails with a specific subject or from certain key senders, send the details and a direct link as a Telegram message, and then label and mark those emails as read so I wouldn’t get duplicate alerts.
Getting the right search filters in place was easy and customizable if my needs change. It runs as a Google Apps Script and is set to run every five minutes using time-based triggers.
Testing was as easy as sending myself some emails matching the right criteria, and the Telegram alerts popped up just as planned – sender, subject, preview, and a link. What really works for me is that I can set Telegram notifications just for the chat with the bot, so I don’t get distracted by every single thing, but never miss something urgent.
Why this setup works – and how AI helped me build it faster
If you want a simple, zero-cost fix to avoid getting lost in email noise, this combo of Google Apps Script and Telegram (with some help from AI) is perfect for solving your daily problems.
Working with an AI tool like Windsurf is really for solving technical problems such as automating Gmail notifications to Telegram. You simply state your problem, and the AI helps organize your ideas, lay out a step-by-step plan, write down requirements, and build your task list. I was able to quickly decide on the right tools, map out my workflow, generate an automation script, and adjust every part of the process without getting bogged down in technical details. This approach kept me focused, allowed me to solve issues faster, and reach a working solution much more quickly than if I’d done it manually. Plus, AI can guide you through even the most difficult tasks you can imagine.
Setting up a Telegram bot is easy:
- In the Telegram app, search for [@BotFather](Bots: An introduction for developers ).
- Start a chat with BotFather and use the `/newbot` command to create a new bot. Follow the prompts to give your bot a name and username.
- After setup, you’ll get a bot token. Copy and save this somewhere safe – you’ll use it in your script.
- To get your chat ID, send a message to your new bot, then check updates via the Telegram API. This lets your script know where to send the alerts.
Here’s how to make it work for you:
- Paste the script into Google Apps Script (open [Apps Script | Google for Developers ](Apps Script | Google for Developers ) from Google Drive).
- Enter your bot token and chat ID at the top of the script.
- Edit the query rules – change the subject or email addresses to whatever is important to you.
- Save and run the script once manually to give it permission to access your Gmail and send the Telegram message.
- Set up a trigger in Google Apps Script to run the function `checkMail()` at whatever interval suits you (e.g. every 5 minutes).
You can try it out yourself here.