@grinev/opencode-telegram-bot 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example CHANGED
@@ -4,6 +4,14 @@ TELEGRAM_BOT_TOKEN=
4
4
  # Allowed Telegram User ID (from @userinfobot)
5
5
  TELEGRAM_ALLOWED_USER_ID=
6
6
 
7
+ # Telegram Proxy URL (optional)
8
+ # Supports socks5://, socks4://, http://, https:// protocols
9
+ # Examples:
10
+ # TELEGRAM_PROXY_URL=socks5://proxy.example.com:1080
11
+ # TELEGRAM_PROXY_URL=socks5://user:password@proxy.example.com:1080
12
+ # TELEGRAM_PROXY_URL=http://proxy.example.com:8080
13
+ # TELEGRAM_PROXY_URL=
14
+
7
15
  # OpenCode API URL (optional, default: http://localhost:4096)
8
16
  # OPENCODE_API_URL=http://localhost:4096
9
17
 
package/README.md CHANGED
@@ -117,6 +117,7 @@ When installed via npm, the configuration wizard handles the initial setup. The
117
117
  | -------------------------- | -------------------------------------------- | :------: | ----------------------- |
118
118
  | `TELEGRAM_BOT_TOKEN` | Bot token from @BotFather | Yes | — |
119
119
  | `TELEGRAM_ALLOWED_USER_ID` | Your numeric Telegram user ID | Yes | — |
120
+ | `TELEGRAM_PROXY_URL` | Proxy URL for Telegram API (SOCKS5/HTTP) | No | — |
120
121
  | `OPENCODE_API_URL` | OpenCode server URL | No | `http://localhost:4096` |
121
122
  | `OPENCODE_SERVER_USERNAME` | Server auth username | No | `opencode` |
122
123
  | `OPENCODE_SERVER_PASSWORD` | Server auth password | No | — |
package/dist/bot/index.js CHANGED
@@ -2,6 +2,8 @@ import { Bot, InputFile } from "grammy";
2
2
  import { promises as fs } from "fs";
3
3
  import * as path from "path";
4
4
  import { fileURLToPath } from "url";
5
+ import { SocksProxyAgent } from "socks-proxy-agent";
6
+ import { HttpsProxyAgent } from "https-proxy-agent";
5
7
  import { config } from "../config.js";
6
8
  import { authMiddleware } from "./middleware/auth.js";
7
9
  import { BOT_COMMANDS } from "./commands/definitions.js";
@@ -310,7 +312,26 @@ async function resetMismatchedSessionContext() {
310
312
  }
311
313
  }
312
314
  export function createBot() {
313
- const bot = new Bot(config.telegram.token);
315
+ const botOptions = {};
316
+ if (config.telegram.proxyUrl) {
317
+ const proxyUrl = config.telegram.proxyUrl;
318
+ let agent;
319
+ if (proxyUrl.startsWith("socks")) {
320
+ agent = new SocksProxyAgent(proxyUrl);
321
+ logger.info(`[Bot] Using SOCKS proxy: ${proxyUrl.replace(/\/\/.*@/, "//***@")}`);
322
+ }
323
+ else {
324
+ agent = new HttpsProxyAgent(proxyUrl);
325
+ logger.info(`[Bot] Using HTTP/HTTPS proxy: ${proxyUrl.replace(/\/\/.*@/, "//***@")}`);
326
+ }
327
+ botOptions.client = {
328
+ baseFetchConfig: {
329
+ agent,
330
+ compress: true,
331
+ },
332
+ };
333
+ }
334
+ const bot = new Bot(config.telegram.token, botOptions);
314
335
  // Heartbeat for diagnostics: verify the event loop is not blocked
315
336
  let heartbeatCounter = 0;
316
337
  setInterval(() => {
package/dist/config.js CHANGED
@@ -38,6 +38,7 @@ export const config = {
38
38
  telegram: {
39
39
  token: getEnvVar("TELEGRAM_BOT_TOKEN"),
40
40
  allowedUserId: parseInt(getEnvVar("TELEGRAM_ALLOWED_USER_ID"), 10),
41
+ proxyUrl: getEnvVar("TELEGRAM_PROXY_URL", false),
41
42
  },
42
43
  opencode: {
43
44
  apiUrl: getEnvVar("OPENCODE_API_URL", false) || "http://localhost:4096",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grinev/opencode-telegram-bot",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Telegram bot client for OpenCode to run and monitor coding tasks from chat.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,7 +55,9 @@
55
55
  "@opencode-ai/sdk": "^1.1.21",
56
56
  "better-sqlite3": "^12.6.2",
57
57
  "dotenv": "^17.2.3",
58
- "grammy": "^1.39.2"
58
+ "grammy": "^1.39.2",
59
+ "https-proxy-agent": "^7.0.6",
60
+ "socks-proxy-agent": "^8.0.5"
59
61
  },
60
62
  "devDependencies": {
61
63
  "@types/better-sqlite3": "^7.6.13",