GramJS Telegram relay for OpenClaw inject
- JavaScript 100%
- 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 |
||
|---|---|---|
| src | ||
| .gitignore | ||
| CLAUDE.md | ||
| config.yaml.example | ||
| fwd-doc.md | ||
| main.js | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
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 # 訊息格式化