TGBot
Google Apps Script library for working with the Telegram API.
AI Summary
TGbot
A Google Apps Script library that simplifies working with the Telegram Bot API via Webhook.
Target Users
Intermediate-level GAS developers building spreadsheet-driven Telegram bots or chat automations.
Problems Solved
Using raw HTTP requests to call the Telegram Bot API requires tedious handling of webhooks, payloads, and multipart uploads.
Tags
Main Features
One-call bot initialization
Passing token and WebApp URL to bot() instantly configures webhook, logging, and parse mode.
Comprehensive API wrappers
Provides wrapper functions such as sendMessage, editMessageText, sendMediaGroup, eliminating manual endpoint construction.
Keyboard & inline-calendar helpers
Keyboard.make() and TGbot.calendar() build Reply/Inline keyboards and date pickers with simple arrays.
GAS-friendly file handling
Send Spreadsheet-generated blobs via sendPhoto/sendDocument and save incoming files to Drive with helper utilities.
Usage Examples
Send a message with the least code
/**
* Steps:
* 1. Add library ID 1LyGnq... to your GAS project.
* 2. Deploy the script as a Web App and copy its URL.
*/
const BOT_TOKEN = 'YOUR_BOT_TOKEN'; // from @BotFather
const WEBAPP_URL = 'YOUR_WEBAPP_URL'; // URL of deployed Web App
// Create Bot instance
const Bot = TGbot.bot({ botToken: BOT_TOKEN, webAppUrl: WEBAPP_URL });
function sendHello() {
const chatId = '123456789'; // recipient user ID
// Send a text message (HTML parse mode by default)
const res = Bot.sendMessage({
chat_id: chatId,
text: 'Hello from GAS!'
});
Logger.log(JSON.stringify(res, null, 2)); // inspect response
}
Copy the snippet, add the library, and running sendHello()
immediately delivers a Telegram message. Use Bot.setWebhook()
later to enable webhook handling.