How telegrambotindonesia/gas-lib-v3 works
Project type and purpose
• This is an open-source Google Apps Script (GAS) library (“GAS Lib v3”) for building Telegram bots.
• Its purpose is to provide a modular, promise-based wrapper around the Telegram Bot API, exposing an easy DSL (bot.cmd, bot.hears, ctx.reply, etc.) that runs inside a GAS WebApp.
File structure
• Top-level:
• core/ – the library modules broken into single-responsibility files (version, helper, markup, event pipeline, context, composer, client, telegram API wrapper, HTTP fetch, user database, main entry).
• core/appsscript.json – GAS manifest (WebApp entry points, scopes).
• examples/ – sample user scripts demonstrating how to import the library and define bot behaviors.
• docs/ – markdown docs for deeper reference.
• deploy.md, package.json – build/deployment instructions via clasp and npm tooling.
README for additional insights
• Explains how to initialize the bot (lumpia.init(token)), wire up doPost(e) as the webhook handler, then register handlers via .start, .cmd, .hears.
• Mentions that the library handles parsing update payloads, matching patterns, and sending messages back via Telegram API.
Components
a. Main components
1. Telegram Bot API (external service)
2. GAS WebApp server (the hosted script)
3. lumpia core modules (inside core/)
• HTTP Entry (doPost)
• Event dispatcher & pipeline (event.js, composer.js)
• Context manager (context.js)
• Command/hears matcher
• Telegram client & fetch wrapper (telegram.js, fetch.js, client.js)
• Utilities (helper.js, markup.js, version.js)
• User state storage (userdb.js)
4. User’s bot script (examples/*.js) that imports lumpia, calls init() and registers handlers
5. Optional external storage (PropertiesService, Google Sheets via GAS)
b. Relationships and data flow
1. Telegram sends an HTTPS POST (update JSON) → GAS WebApp doPost(e) entry
2. doPost calls lumpia.main → core.event triggers pipeline
3. Pipeline builds a Context object → composer invokes matching handlers (.start, .cmd, .hears) defined by user script
4. Handlers call ctx.reply or ctx.replyIt → core.client & fetch wrap UrlFetchApp → send HTTPS requests to Telegram API
5. For stateful bots, userdb.js reads/writes from GAS storage (PropertiesService or Spreadsheet)
c. Architectural patterns/design principles
• Modular single‐responsibility files (each core file handles one concern)
• Middleware/event‐pipeline pattern for update processing
• Dependency inversion: user script only depends on the lumpia API, not on underlying fetch or storage details
• Extension points: users add handlers; library core remains untouched
d. Key technologies/frameworks
• Google Apps Script WebApp environment
• UrlFetchApp for HTTP requests
• Clasp CLI for deployment
• Telegram Bot HTTP API