Skip to content

Dev Hook

Abdi Urgessa edited this page Feb 18, 2024 · 4 revisions

Dev Hook is an innovative feature designed for development purposes, facilitating a seamless testing and interaction experience with your Telegram bot without the need for deploying your code after each change. By leveraging the Dev Hook, developers can simply save their code and interact with their bot, streamlining the development process.

How Dev Hook Works

Dev Hook operates by using webhooks internally, in conjunction with a standard Google Apps Script project. Telesun integrates with middleware servers hosted on platforms such as Vercel, Render, and Google Apps Script to make this possible. Here's a step-by-step breakdown of how it functions:

  1. Set the webhook to one of the supported servers.
  2. The Telegram Bot API server sends a POST request containing updates to the configured server.
  3. The server then calls the doPost function using the Google Apps Script API execution.

Configuration Required

To utilize Dev Hook, follow these steps:

  1. Deploy your project as an "API Executable" within Google Apps Script settings.
  2. Create a standard Google Apps Script project and connect the project ID to your Apps Script project.

Example Usage

function doPost( e ){
  const telesun = new Telesun.connectBot("YOUR_BOT_TOKEN")
                  .devHook(e, { server: "VERCEL" }); // Options: "GAS", "RENDER"
}

Replace "YOUR_BOT_TOKEN" with your actual bot token. The server option specifies which middleware server to use for handling the webhook.

Dev Hook Architecture Diagram

Below is a simplified architecture diagram of the Dev Hook process:

[Telegram Bot API] --(POST request)--> [Middleware Server (e.g., VERCEL)] --(doPost)--> [Google Apps Script]

This diagram represents the flow from setting up the webhook, through the Telegram Bot API sending POST requests, to the middleware server executing the doPost function in your Google Apps Script project.

Clone this wiki locally