forked from eagle/intergram-js
GramJS Telegram relay for OpenClaw inject
- JavaScript 100%
- config.yaml as single config source (per-bot settings, message_delay_second) - Daemon-mode auth guard: process.exit(1) on auth error (prevents memory leak) - Slash command escape for bot messages (fullwidth slash, unified regex) - Health check endpoint (configurable health_port) - Memory cap via --max-old-space-size=1024 - npm start integration (removed run.sh) - Removed .env fallback - Removed unused botNameMap Co-authored-by: 拍拍 <eagle@baldbot.dev> Co-authored-by: 踏踏 <tata@mingtsay.tw> |
||
|---|---|---|
| src | ||
| .gitignore | ||
| CLAUDE.md | ||
| config.yaml.example | ||
| 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. 之後以 daemon 模式啟動
bash run.sh
設定檔 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,關閉) |
啟動模式
Daemon 模式(推薦)
bash run.sh
- 自動加
--max-old-space-size防止記憶體暴衝 - 可用
INTERGRAM_MAX_OLD_SPACE_SIZE環境變數調整(預設 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 調整。
檔案結構
config.yaml # 設定檔(不進 git)
config.yaml.example # 設定範例
*.session # Telegram session(不進 git)
main.js # 入口
run.sh # 啟動腳本
src/
config.js # 設定載入
relay.js # 主要邏輯
formatter.js # 訊息格式化