メインコンテンツにスキップ

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.

Script ID

  1. In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
  2. "TGBot" will appear in the search results
  3. Select the latest version (highest number) from "Version" dropdown
  4. Click "Add"

Tags

Main Features
1
One-call bot initialization

Passing token and WebApp URL to bot() instantly configures webhook, logging, and parse mode.

2
Comprehensive API wrappers

Provides wrapper functions such as sendMessage, editMessageText, sendMediaGroup, eliminating manual endpoint construction.

3
Keyboard & inline-calendar helpers

Keyboard.make() and TGbot.calendar() build Reply/Inline keyboards and date pickers with simple arrays.

4
GAS-friendly file handling

Send Spreadsheet-generated blobs via sendPhoto/sendDocument and save incoming files to Drive with helper utilities.

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.

Sample Code

Post a Sample

No sample codes for this library yet

Be the first to post a sample!

Post a Sample