Apps Script Telegram Bot: Real Time Sheet and Form Alerts

Introduction

In today’s fast‑paced digital environment, receiving real‑time alerts from your Google workspace can dramatically improve decision‑making and workflow efficiency. One of the most versatile ways to achieve instant notifications is by connecting Google Apps Script with a custom Telegram bot. This article walks you through every step required to create a Telegram bot, link it to Google Apps Script, and automatically push messages from Google Sheets, Google Forms, or any other Google app straight to a Telegram chat. By the end of the guide you will understand the bot creation process, how to secure the communication channel, and how to write reusable scripts that turn ordinary spreadsheet rows or form submissions into actionable alerts for you or your team.

Setting Up Your Telegram Bot

Start by opening the Telegram app and searching for the @BotFather account. Send the command /newbot and follow the prompts to name your bot and assign a unique username. BotFather will return a token – a string that authenticates your bot with Telegram’s API. Keep this token safe; it will be used in the Apps Script project to send messages. Optionally, configure a short description and a profile picture for a more professional appearance. Once the bot is created, you can test it by sending a simple message to its chat handle; the bot will echo the text if you later add an echo handler in your script.

Connecting Google Apps Script to Telegram

Open the Google Sheet (or Form) that will trigger notifications and navigate to Extensions → Apps Script. In the script editor, create a function that builds the HTTP POST request required by Telegram’s sendMessage endpoint:

  • Define the bot token and the target chat ID (you can obtain the chat ID by sending a message to the bot and checking the getUpdates response).
  • Compose the payload with chat_id, text, and optional parameters such as parse_mode for markdown or HTML formatting.
  • Use UrlFetchApp.fetch() to POST the JSON payload to https://api.telegram.org/bot{TOKEN}/sendMessage.

Encapsulate this logic in a reusable function, for example sendTelegramMessage(message), so you can call it from any trigger or custom menu.

Automating Notifications from Google Sheets

To turn spreadsheet events into alerts, add an onEdit or onChange trigger. Within the trigger function, inspect the edited range to decide whether a notification is warranted – for instance, when a status column changes to “Approved”. Build a concise message that includes the row number, key fields, and a direct link to the sheet using SpreadsheetApp.getActiveSpreadsheet().getUrl(). Then invoke sendTelegramMessage() with the crafted text. Remember to set the trigger as an installable trigger (via the Apps Script UI) so it runs with the necessary permissions.

Extending Alerts to Google Forms and Other Apps

Google Forms submissions generate a Form Submit event that can be captured with an installable trigger. In the handler, extract the response object, format the answers into a readable summary, and forward it through the same sendTelegramMessage() function. The same pattern applies to other Google apps – Docs, Slides, or even Calendar events – by creating appropriate triggers (e.g., CalendarApp watch for new events). By centralizing the Telegram‑sending logic, you maintain a single point of maintenance while expanding notification coverage across your entire Google ecosystem.

Conclusion

Creating a Telegram bot and linking it with Google Apps Script unlocks a powerful, low‑cost notification system that works across Sheets, Forms, and virtually any Google service. You start by registering a bot with BotFather, securing its token, and building a reusable sendTelegramMessage function in Apps Script. From there, installable triggers turn data changes—whether a spreadsheet row update or a form submission—into instant Telegram alerts, keeping teams informed without manual effort. By following the step‑by‑step workflow outlined above, you can scale this solution to suit personal projects or enterprise‑level monitoring, ensuring that critical information always reaches the right people at the right time.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Digital Malayali