@wu529778790/open-im 0.3.11 → 0.4.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/README.md CHANGED
@@ -49,11 +49,43 @@ npx @wu529778790/open-im init
49
49
  "allowedUserIds": ["你的Telegram用户ID"],
50
50
  "claudeWorkDir": "/path/to/your/work/dir",
51
51
  "claudeSkipPermissions": true,
52
- "aiCommand": "claude"
52
+ "aiCommand": "claude",
53
+ "platforms": {
54
+ "telegram": {
55
+ "proxy": "http://127.0.0.1:7890"
56
+ }
57
+ }
53
58
  }
54
59
  ```
55
60
 
56
- 获取 Telegram Bot Token:
61
+ ### 🌐 代理配置
62
+
63
+ 如果你的网络环境无法直接访问 Telegram,需要配置代理。代理配置按平台独立设置,互不影响。
64
+
65
+ **配置方式:**
66
+
67
+ 在 JSON 配置文件中添加:
68
+ ```json
69
+ {
70
+ "platforms": {
71
+ "telegram": {
72
+ "proxy": "http://127.0.0.1:7890"
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ **支持的代理类型:**
79
+ - HTTP 代理:`http://127.0.0.1:7890`
80
+ - HTTPS 代理:`https://127.0.0.1:7890`
81
+ - SOCKS5 代理:`socks5://127.0.0.1:1080`
82
+
83
+ **注意:**
84
+ - 代理仅用于访问 Telegram API,不会影响 AI 工具(Claude/Codex/Cursor)的网络请求
85
+ - 飞书等其他国内 IM 平台无需配置代理
86
+ - 如果你的网络能直接访问 Telegram,则无需配置代理
87
+
88
+ ### 获取 Telegram Bot Token
57
89
  1. 在 Telegram 中搜索 @BotFather
58
90
  2. 发送 `/newbot` 创建新机器人
59
91
  3. 按提示设置机器人名称
@@ -65,14 +97,6 @@ npx @wu529778790/open-im init
65
97
  3. 机器人会返回你的用户 ID
66
98
  4. 如不设置,则所有人都可以使用你的机器人
67
99
 
68
- **或者通过环境变量配置:**
69
-
70
- ```bash
71
- export TELEGRAM_BOT_TOKEN="你的Bot Token"
72
- export ALLOWED_USER_IDS="用户ID1,用户ID2"
73
- open-im run
74
- ```
75
-
76
100
  ## 📖 常用命令
77
101
 
78
102
  | 命令 | 说明 |
@@ -143,6 +167,11 @@ pnpm i @wu529778790/open-im -g
143
167
  {
144
168
  "telegramBotToken": "你的Bot Token",
145
169
  "allowedUserIds": ["你的Telegram用户ID"],
170
+ "platforms": {
171
+ "telegram": {
172
+ "proxy": "http://127.0.0.1:7890"
173
+ }
174
+ },
146
175
  "claudeWorkDir": "$(pwd)",
147
176
  "claudeSkipPermissions": true,
148
177
  "aiCommand": "claude"
@@ -175,3 +204,39 @@ npx @wu529778790/open-im run
175
204
  1. 在 Telegram 中搜索 @userinfobot
176
205
  2. 点击"START"或发送任意消息
177
206
  3. 机器人会返回你的用户 ID(数字)
207
+
208
+ ### Q: 如何配置代理?
209
+
210
+ 如果你的网络环境无法直接访问 Telegram,需要在配置文件中添加代理设置:
211
+
212
+ ```json
213
+ {
214
+ "platforms": {
215
+ "telegram": {
216
+ "proxy": "http://127.0.0.1:7890"
217
+ }
218
+ }
219
+ }
220
+ ```
221
+
222
+ 支持的代理格式:
223
+ - HTTP:`http://127.0.0.1:7890`
224
+ - HTTPS:`https://127.0.0.1:7890`
225
+ - SOCKS5:`socks5://127.0.0.1:1080`
226
+
227
+ 注意:代理仅用于访问 Telegram API,不影响 AI 工具的网络请求。
228
+
229
+ ### Q: Telegram 机器人无响应?
230
+
231
+ 可能原因及解决方法:
232
+
233
+ 1. **网络问题 - Telegram 被阻断**
234
+ - 配置代理(见上方"如何配置代理")
235
+ - 测试代理是否可用:`curl -x http://127.0.0.1:7890 https://api.telegram.org`
236
+
237
+ 2. **Token 错误**
238
+ - 重新获取 Token:在 @BotFather 中使用 `/revoke` 命令
239
+
240
+ 3. **用户 ID 白名单问题**
241
+ - 检查配置文件中的 `allowedUserIds` 是否包含你的用户 ID
242
+ - 或留空允许所有人访问(仅开发环境建议)
package/dist/config.d.ts CHANGED
@@ -14,6 +14,11 @@ export interface Config {
14
14
  claudeModel?: string;
15
15
  logDir: string;
16
16
  logLevel: LogLevel;
17
+ platforms: {
18
+ telegram?: {
19
+ proxy?: string;
20
+ };
21
+ };
17
22
  }
18
23
  /** 检测是否需要交互式配置(无 token 且无环境变量) */
19
24
  export declare function needsSetup(): boolean;
package/dist/config.js CHANGED
@@ -91,6 +91,12 @@ export function loadConfig() {
91
91
  }
92
92
  const logDir = process.env.LOG_DIR ?? file.logDir ?? join(APP_HOME, 'logs');
93
93
  const logLevel = (process.env.LOG_LEVEL?.toUpperCase() ?? file.logLevel ?? 'INFO');
94
+ // Platform-specific proxy configuration
95
+ const platforms = {
96
+ telegram: {
97
+ proxy: process.env.TELEGRAM_PROXY ?? file?.platforms?.telegram?.proxy,
98
+ },
99
+ };
94
100
  return {
95
101
  enabledPlatforms,
96
102
  telegramBotToken,
@@ -104,5 +110,6 @@ export function loadConfig() {
104
110
  claudeModel: process.env.CLAUDE_MODEL ?? file.claudeModel,
105
111
  logDir,
106
112
  logLevel,
113
+ platforms,
107
114
  };
108
115
  }
package/dist/setup.js CHANGED
@@ -17,6 +17,11 @@ function printManualInstructions(configPath) {
17
17
  console.log(`{
18
18
  "telegramBotToken": "你的Bot Token",
19
19
  "allowedUserIds": ["你的Telegram用户ID"],
20
+ "platforms": {
21
+ "telegram": {
22
+ "proxy": "http://127.0.0.1:7890"
23
+ }
24
+ },
20
25
  "claudeWorkDir": "${process.cwd().replace(/\\/g, '/')}",
21
26
  "claudeSkipPermissions": true,
22
27
  "aiCommand": "claude"
@@ -52,6 +57,12 @@ export async function runInteractiveSetup() {
52
57
  message: '白名单用户 ID(可选,逗号分隔,留空=所有人可访问)',
53
58
  initial: '',
54
59
  },
60
+ {
61
+ type: 'text',
62
+ name: 'telegramProxy',
63
+ message: 'Telegram 代理地址(可选,如: http://127.0.0.1:7890 或 socks5://127.0.0.1:1080)',
64
+ initial: '',
65
+ },
55
66
  {
56
67
  type: 'select',
57
68
  name: 'aiCommand',
@@ -82,6 +93,11 @@ export async function runInteractiveSetup() {
82
93
  .map((s) => s.trim())
83
94
  .filter(Boolean)
84
95
  : [],
96
+ platforms: {
97
+ telegram: response.telegramProxy
98
+ ? { proxy: response.telegramProxy.trim() }
99
+ : undefined,
100
+ },
85
101
  claudeWorkDir: (response.workDir || process.cwd()).trim(),
86
102
  claudeSkipPermissions: true,
87
103
  aiCommand: response.aiCommand ?? 'claude',
@@ -1,5 +1,6 @@
1
1
  import { Telegraf } from 'telegraf';
2
2
  import { createLogger } from '../logger.js';
3
+ import { HttpsProxyAgent } from 'https-proxy-agent';
3
4
  const log = createLogger('Telegram');
4
5
  let bot;
5
6
  let botUsername;
@@ -12,7 +13,22 @@ export function getBotUsername() {
12
13
  return botUsername;
13
14
  }
14
15
  export async function initTelegram(config, setupHandlers) {
15
- bot = new Telegraf(config.telegramBotToken);
16
+ const telegrafOptions = {};
17
+ // 配置平台特定代理
18
+ const proxy = config.platforms?.telegram?.proxy;
19
+ if (proxy) {
20
+ try {
21
+ const agent = new HttpsProxyAgent(proxy);
22
+ telegrafOptions.telegram = {
23
+ agent,
24
+ };
25
+ log.info(`Using proxy: ${proxy}`);
26
+ }
27
+ catch (err) {
28
+ log.warn(`Failed to create proxy agent: ${err}. Continuing without proxy.`);
29
+ }
30
+ }
31
+ bot = new Telegraf(config.telegramBotToken, telegrafOptions);
16
32
  setupHandlers(bot);
17
33
  const me = (await bot.telegram.getMe());
18
34
  botUsername = me.username;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "0.3.11",
3
+ "version": "0.4.0",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -41,6 +41,7 @@
41
41
  "url": "https://github.com/wu529778790/open-im/issues"
42
42
  },
43
43
  "dependencies": {
44
+ "https-proxy-agent": "^7.0.6",
44
45
  "prompts": "^2.4.2",
45
46
  "telegraf": "^4.16.3"
46
47
  },
package/.env.example DELETED
@@ -1,16 +0,0 @@
1
- # Telegram Bot Token (from @BotFather)
2
- TELEGRAM_BOT_TOKEN=
3
-
4
- # Allowed user IDs (comma-separated, empty = allow all in dev)
5
- ALLOWED_USER_IDS=
6
-
7
- # AI tool: claude | codex | cursor
8
- AI_COMMAND=claude
9
-
10
- # Claude CLI (when AI_COMMAND=claude)
11
- CLAUDE_CLI_PATH=claude
12
- CLAUDE_WORK_DIR=.
13
- CLAUDE_SKIP_PERMISSIONS=true
14
- CLAUDE_TIMEOUT_MS=600000
15
- CLAUDE_MODEL=
16
- ALLOWED_BASE_DIRS=