GramJS Telegram relay for OpenClaw inject
  • JavaScript 100%
Find a file
Eagle 744b292abb fix: use Asia/Taipei timezone for log rotation and timestamps
- ts() now outputs +08:00 instead of UTC ISO
- getLogDate() uses Intl.DateTimeFormat with Asia/Taipei
- logRelay() reuses ts() for consistent timezone
- README.md: fix startup command (npm start, not bash run.sh)
- CLAUDE.md: add timezone info and correct startup command
2026-03-23 04:06:26 +08:00
src fix: use Asia/Taipei timezone for log rotation and timestamps 2026-03-23 04:06:26 +08:00
.gitignore fix: remove debug log truncation, add file/ to gitignore 2026-03-20 18:51:49 +00:00
CLAUDE.md fix: use Asia/Taipei timezone for log rotation and timestamps 2026-03-23 04:06:26 +08:00
config.yaml.example feat: PID管理, 檔案logging, health bind設定, dice relay支援 2026-03-20 19:57:06 +08:00
fwd-doc.md feat: forward_origin support (Bot API 7.x format) 2026-03-20 19:38:13 +00:00
main.js feat: initial commit — GramJS Telegram relay for OpenClaw inject 2026-02-10 20:09:08 +08:00
package-lock.json feat: multi-bot config.yaml, daemon auth guard, slash escape, health check 2026-03-20 13:57:30 +08:00
package.json feat: multi-bot config.yaml, daemon auth guard, slash escape, health check 2026-03-20 13:57:30 +08:00
README.md fix: use Asia/Taipei timezone for log rotation and timestamps 2026-03-23 04:06:26 +08:00

intergram-js

GramJS-based Telegram relay — 監聽群組中 bot 的訊息,透過 webhook inject 到 OpenClaw gateway。

架構

Telegram Group
  ↓ (GramJS MTProto)
intergram-js
  ↓ (HTTP POST webhook)
OpenClaw Gateway (inject endpoint)

快速開始

# 1. 安裝依賴
npm install

# 2. 設定
cp config.yaml.example config.yaml
# 編輯 config.yaml 填入實際值

# 3. 首次登入(需要互動式輸入手機號碼)
INTERGRAM_ALLOW_INTERACTIVE_AUTH=1 node main.js

# 4. 之後啟動
npm start

設定檔 config.yaml

# Telegram MTProto 認證
telegram:
  api_id: 12345678
  api_hash: "your_api_hash"
  session_name: "intergram-js"

# 全域設定
settings:
  max_media_size: 52428800    # 媒體大小上限 bytes預設 50MB
  health_port: 19200          # Health check port預設 19200

# Bot endpoints一個或多個
bots:
  - name: tata
    webhook_url: "http://127.0.0.1:18789/telegram/inject"
    inject_token: "your_inject_token"
    account_id: ""
    source_chats:
      - -1001068509881
    bot_exclude:
      - "@mtsClawdBot"
    # message_delay_second: 0  # 選填,預設 0關閉

  - name: eagle
    webhook_url: "http://127.0.0.1:18788/telegram/inject"
    inject_token: "eagle_token"
    source_chats:
      - -1001068509881
    bot_exclude:
      - "@BaldEagleBot"
    message_delay_second: 2

設定欄位說明

欄位 必填 說明
telegram.api_id Telegram API ID
telegram.api_hash Telegram API Hash
telegram.session_name Session 檔名前綴(預設 intergram-js
settings.max_media_size 媒體大小上限 bytes預設 50MB
settings.health_port Health check port預設 19200
bots[].name Bot 識別名稱
bots[].webhook_url OpenClaw inject endpoint URL
bots[].inject_token Bearer token
bots[].source_chats 監聽的 chat ID 列表
bots[].bot_exclude 排除的 bot@username 或數字 ID
bots[].account_id 帳號 ID
bots[].message_delay_second Relay 延遲秒數(預設 0關閉

啟動模式

正常啟動(推薦)

npm start
  • 等同 node --max-old-space-size=1024 main.js
  • 自動限制記憶體上限(預設 1024MB防止記憶體暴衝
  • Auth 失敗時直接退出,不會無限 retry

互動式登入

首次使用或 session 過期時:

INTERGRAM_ALLOW_INTERACTIVE_AUTH=1 node main.js

Health Check

curl http://127.0.0.1:19200/health
# {"status":"ok","connected":true,"endpoints":3,"chats":1,"uptime":3600}

Port 可在 settings.health_port 調整。

時區

Log 檔案名稱(log/YYMMDD.log)及時間戳記均使用 Asia/Taipei (UTC+8) 時區。

檔案結構

config.yaml             # 設定檔(不進 git
config.yaml.example     # 設定範例
*.session               # Telegram session不進 git
main.js                 # 入口
src/
  config.js             # 設定載入
  relay.js              # 主要邏輯
  formatter.js          # 訊息格式化