From 88d951441a8d09dbea548c053f772c54daf537ef Mon Sep 17 00:00:00 2001 From: Marc Deniel Date: Fri, 18 Sep 2026 01:23:13 +0800 Subject: [PATCH 1/7] Add files via upload --- README.md | 163 +++++++++++++++++++++++++----------------------------- 1 file changed, 74 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 11e97bc..00123ca 100644 --- a/README.md +++ b/README.md @@ -1,113 +1,98 @@ -# wrappergram +# Telegram-Bot — Production Build -
+A Deno/V8-based Telegram business management, communication, and automation +system, implementing the owner/users/groups model described in the system +overview: publishing, editable buttons, scheduling, destination management, +access control, and group-mention assistance. -[![Bot API](https://img.shields.io/badge/Bot%20API-7.7+-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api) -[![npm](https://img.shields.io/npm/v/wrappergram?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/wrappergram) -[![npm downloads](https://img.shields.io/npm/dw/wrappergram?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/wrappergram) -[![JSR](https://jsr.io/badges/@gramio/wrappergram)](https://jsr.io/@gramio/wrappergram) -[![JSR Score](https://jsr.io/badges/@gramio/wrappergram/score)](https://jsr.io/@gramio/wrappergram) -[![bundlejs]()](https://bundlejs.com/?q=wrappergram&treeshake=%5B*%5D&text=%22const+telegram+%3D+new+Telegram%28process.env.BOT_TOKEN+as+string%29%3B%5Cn%5Cntelegram.api.sendMessage%28%7B%5Cn++++chat_id%3A+617580375%2C%5Cn++++text%3A+%5C%22Hello%21%5C%22%2C%5Cn%7D%29%3B%22) +## Stack -
+- **Runtime:** Deno (webhook server via `Deno.serve`, background jobs via `Deno.cron`) +- **Telegram framework:** [grammY](https://grammy.dev) +- **Storage:** Deno KV (built-in, zero external dependency; swap for Postgres/etc. by reimplementing `src/db.ts` if you outgrow it) +- **Hosting:** Deno Deploy (recommended) or any host that runs Deno with `--unstable-kv --unstable-cron` -Simple and tiny code-generated **Telegram Bot API** wrapper for TypeScript/JavaScript with [file upload](https://core.telegram.org/bots/api#sending-files) support. +## Project layout -🌐 **Multi-runtime** - Works on [Node.js](https://nodejs.org/), [Bun](https://bun.sh/) and [Deno](https://deno.com/) - -āš™ļø **Code-generated** - For example, [code-generated and auto-published Telegram Bot API types](https://github.com/gramiojs/types)) - -šŸ›”ļø **Type-safe** - Written in TypeScript with love ā¤ļø - -šŸ¤ **Tiny** - Simple `sendMessage` call cost some [![bundlejs](https://edge.bundlejs.com/?text=import%20%7B%20Telegram%20%7D%20from%20%22wrappergram%22%3B%0A%0Aconst%20telegram%20%3D%20new%20Telegram%28process.env.BOT_TOKEN%29%3B%0A%0Atelegram.api.sendMessage%28%7B%0A%20%20%20%20chat_id%3A%20617580375%2C%0A%20%20%20%20text%3A%20%22Hello%21%22%2C%0A%7D%29%3B&badge)](https://bundlejs.com/?q=wrappergram&treeshake=%5B*%5D&text=%22const+telegram+%3D+new+Telegram%28process.env.BOT_TOKEN+as+string%29%3B%5Cn%5Cntelegram.api.sendMessage%28%7B%5Cn++++chat_id%3A+617580375%2C%5Cn++++text%3A+%5C%22Hello%21%5C%22%2C%5Cn%7D%29%3B%22) in bundle size. So it is a good choice for browser/serverless environments - -But if you need a more complete framework, then please look to [`GramIO`](https://gramio.dev/). - -### Usage - -```ts -import { Telegram, getUpdates } from "wrappergram"; - -const telegram = new Telegram(process.env.BOT_TOKEN as string); - -telegram.api.sendMessage({ - chat_id: 617580375, - text: "Hello!", -}); - -for await (const update of getUpdates(telegram)) { - console.log(update); - - if (update.message?.from) { - telegram.api.sendMessage({ - chat_id: update.message.from.id, - text: "Hi! Thanks for the message", - }); - } -} +``` +telegram-bot/ +ā”œā”€ā”€ main.ts # webhook server + cron entry point +ā”œā”€ā”€ deno.json # tasks + import map +ā”œā”€ā”€ .env.example # required environment variables +ā”œā”€ā”€ scripts/set_webhook.ts # one-time webhook registration +└── src/ + ā”œā”€ā”€ config.ts # env var loading + ā”œā”€ā”€ types.ts # domain types + ā”œā”€ā”€ db.ts # Deno KV persistence layer + ā”œā”€ā”€ bot.ts # command/message routing + ā”œā”€ā”€ middleware/auth.ts # owner-only / approved-only gates + └── features/ + ā”œā”€ā”€ destinations.ts # connect/list/remove channels & groups + ā”œā”€ā”€ publish.ts # multi-destination publish + wizard + ā”œā”€ā”€ buttons.ts # update a button's URL across old posts + ā”œā”€ā”€ scheduling.ts # /schedule + cron-driven publication + ā”œā”€ā”€ access.ts # request/approve/decline access + ā”œā”€ā”€ groupMention.ts # respond only when @mentioned in groups + └── assistance.ts # simple FAQ-style business assistance ``` -This example on bundlejs cost [![bundlejs](https://deno.bundlejs.com/badge?q=wrappergram&treeshake=[*]&share=MYewdgzgLgBFCmAbeBzATgQwLYwLwzHgHcYAVJVTLACgAc0Rh4IIA6eMAN1YCEB5UgH1SfANIBRAHIBKANwAoeQmTpsrDLQCWrCBwAmAWWYQMKeNQDe8mDZjAAFhiiDNegFwwAbAEYA7AFYADgAGAGYAgBprWwQADygPACIACSREEABCRKiAXzlFADMQNBgMIgxNWGpQSFgAV1o9J3gYEAKYMygAVUbmiGplSmxpaRgrWztwCBBkVnSUagamhHzom012xd6EVixjU3gAflYChixR8YmYilUsdS0dfSMWA8s1q4mHJxd3GCXm3b7MwnM6sVxRD4fOIJGApTQZMiOMAAawgMCKJSg9haexeZmy7wmeQURPkOSAA)](https://bundlejs.com/?q=wrappergram&treeshake=%5B*%5D&share=MYewdgzgLgBFCmAbeBzATgQwLYwLwzHgHcYAVJVTLACgAc0Rh4IIA6eMAN1YCEB5UgH1SfANIBRAHIBKANwAoeQmTpsrDLQCWrCBwAmAWWYQMKeNQDe8mDZjAAFhiiDNegFwwAbAEYA7AFYADgAGAGYAgBprWwQADygPACIACSREEABCRKiAXzlFADMQNBgMIgxNWGpQSFgAV1o9J3gYEAKYMygAVUbmiGplSmxpaRgrWztwCBBkVnSUagamhHzom012xd6EVixjU3gAflYChixR8YmYilUsdS0dfSMWA8s1q4mHJxd3GCXm3b7MwnM6sVxRD4fOIJGApTQZMiOMAAawgMCKJSg9haexeZmy7wmeQURPkOSAA) - -> [!IMPORTANT] -> Use `getUpdates` only **once** in your code otherwise it will cause double calls to [getUpdates](https://core.telegram.org/bots/api#getupdates) +## Setup -### Call api +1. **Create the bot** with [@BotFather](https://t.me/BotFather) and copy the token. +2. **Get your Telegram user id** from [@userinfobot](https://t.me/userinfobot) — this becomes `OWNER_ID`. +3. Copy `.env.example` to `.env` and fill in `BOT_TOKEN`, `OWNER_ID`, a random `WEBHOOK_SECRET`, and `PUBLIC_URL` (set after your first deploy). +4. Install the [Deno CLI](https://deno.com) if running locally. -You can send requests to Telegram Bot API Methods via `telegram.api` with full type-safety! +## Local development (polling is simplest locally, but this build uses webhooks) -```ts -const response = await telegram.api.sendMessage({ - chat_id: "@gramio_forum", - text: "Hello, world!", -}); +For local testing, the quickest path is a tunnel (e.g. `deno task dev` behind `ngrok http 8000`), setting `PUBLIC_URL` to the tunnel's HTTPS URL, then running: -if (!response.ok) console.error("Something went wrong"); -else console.log(`New message id is ${response.result.message_id}`); +``` +deno task setwebhook +deno task dev ``` -### Send keyboards - -For keyboards you need to install [`@gramio/keyboard`](https://www.npmjs.com/package/@gramio/keyboards) library and just use it! +## Deploying to Deno Deploy -```ts -import { Keyboard } from "@gramio/keyboards"; +1. Push this project to a GitHub repo. +2. Create a new Deno Deploy project linked to the repo, entry point `main.ts`. +3. Add the environment variables from `.env.example` in the Deno Deploy dashboard. +4. Set `PUBLIC_URL` to your `*.deno.dev` URL, redeploy, then run `deno task setwebhook` locally (pointing at the same env vars) to register the webhook. -// telegram init -telegram.api.sendMessage({ - chat_id: "@gramio_forum", - text: "Hello, world!", - reply_markup: new InlineKeyboard().url( - "GitHub", - "https://github.com/gramiojs/wrappergram" - ), -}); -``` +## Using the bot -This example cost - [![bundlejs]()](https://bundlejs.com/?q=wrappergram%2C%40gramio%2Fkeyboards&treeshake=%5B*%5D%2C%5B*%5D&text=%22const+telegram+%3D+new+Telegram%28process.env.BOT_TOKEN%29%3B%5Cn%5Cntelegram.api.sendMessage%28%7B%5Cn++chat_id%3A+617580375%2C%5Cn++text%3A+%5C%22Hello%21%5C%22%2C%5Cn++reply_markup%3A+new+InlineKeyboard%28%29.url%28%5C%22GitHub%5C%22%2C+%5C%22https%3A%2F%2Fgithub.com%2Fgramiojs%2Fwrappergram%5C%22%29%5Cn%7D%29%3B%22) +**Owner commands** (only work for the Telegram account matching `OWNER_ID`): -[Read more here](https://gramio.dev/keyboards/overview) +| Command | Purpose | +|---|---| +| `/adddestination