@fontdo/5g-message 1.0.6 → 1.0.8

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.
Files changed (3) hide show
  1. package/README.md +5 -5
  2. package/cli.ts +168 -0
  3. package/package.json +8 -2
package/README.md CHANGED
@@ -14,16 +14,16 @@ OpenClaw 通道插件,用于连接 Fontdo 5G 消息平台。
14
14
 
15
15
  ```bash
16
16
  # 将插件复制到 OpenClaw 扩展目录
17
- cp -r . ~/.openclaw/extensions/fontdo-5g-message
17
+ cp -r . ~/.openclaw/extensions/5g-message
18
18
 
19
19
  # 或者使用链接方式(开发模式)
20
- openclaw plugins install -l /path/to/fontdo-5g-message
20
+ openclaw plugins install -l /path/to/5g-message
21
21
  ```
22
22
 
23
23
  ### 方法 2: NPM 安装
24
24
 
25
25
  ```bash
26
- openclaw plugins install @openclaw/fontdo-5g-message
26
+ openclaw plugins install @fontdo/5g-message
27
27
  ```
28
28
 
29
29
  ## 配置
@@ -33,7 +33,7 @@ openclaw plugins install @openclaw/fontdo-5g-message
33
33
  ```json
34
34
  {
35
35
  "channels": {
36
- "fontdo-5g-message": {
36
+ "5g-message": {
37
37
  "enabled": true,
38
38
  "accounts": {
39
39
  "default": {
@@ -66,7 +66,7 @@ openclaw plugins install @openclaw/fontdo-5g-message
66
66
  ```json
67
67
  {
68
68
  "channels": {
69
- "fontdo-5g-message": {
69
+ "5g-message": {
70
70
  "defaultAccount": "prod",
71
71
  "accounts": {
72
72
  "prod": {
package/cli.ts ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ import inquirer from 'inquirer';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import chalk from 'chalk';
6
+ import { execSync } from 'child_process';
7
+
8
+ // 配置文件路径
9
+ const CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || '', '.openclaw');
10
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'openclaw.json');
11
+
12
+ async function install() {
13
+ console.log(chalk.cyan('📱 Fontdo 5G Message 插件安装向导'));
14
+ console.log(chalk.gray('=================================='));
15
+ console.log('');
16
+
17
+ try {
18
+ // 安装插件到 OpenClaw
19
+ console.log(chalk.blue('正在安装插件到 OpenClaw...'));
20
+ execSync('openclaw plugins install @fontdo/5g-message', { stdio: 'inherit' });
21
+ console.log(chalk.green('✅ 插件安装成功!'));
22
+ console.log('');
23
+
24
+ // 执行配置
25
+ await configure();
26
+ } catch (error) {
27
+ console.error(chalk.red('安装失败:', error.message));
28
+ process.exit(1);
29
+ }
30
+ }
31
+
32
+ async function configure() {
33
+ console.log(chalk.cyan('📱 Fontdo 5G Message 插件配置向导'));
34
+ console.log(chalk.gray('=================================='));
35
+ console.log('');
36
+
37
+ // 读取现有配置
38
+ let config = {};
39
+ if (await fs.exists(CONFIG_FILE)) {
40
+ try {
41
+ config = await fs.readJSON(CONFIG_FILE);
42
+ console.log(chalk.yellow('检测到现有配置,将在其基础上更新'));
43
+ } catch (error) {
44
+ console.log(chalk.red('读取配置文件失败,将创建新配置'));
45
+ }
46
+ }
47
+
48
+ // 初始化 5g-message 通道配置
49
+ config.channels = config.channels || {};
50
+ config.channels['5g-message'] = config.channels['5g-message'] || {};
51
+
52
+ let continueAdding = true;
53
+
54
+ while (continueAdding) {
55
+ console.log('');
56
+ console.log(chalk.blue('🔧 账号配置'));
57
+ console.log(chalk.gray('-----------------'));
58
+
59
+ // 收集账号配置信息
60
+ const accountAnswers = await inquirer.prompt([
61
+ {
62
+ type: 'input',
63
+ name: 'accountId',
64
+ message: '账号 ID (例如: default, test, prod):',
65
+ default: 'default',
66
+ validate: (input) => input ? true : '账号 ID 不能为空'
67
+ },
68
+ {
69
+ type: 'input',
70
+ name: 'host',
71
+ message: 'Fontdo 5G 消息平台地址(不含协议前缀):',
72
+ validate: (input) => input ? true : '服务器地址不能为空'
73
+ },
74
+ {
75
+ type: 'input',
76
+ name: 'appId',
77
+ message: '应用 ID:',
78
+ validate: (input) => input ? true : '应用 ID 不能为空'
79
+ },
80
+ {
81
+ type: 'input',
82
+ name: 'appKey',
83
+ message: '应用密钥:',
84
+ validate: (input) => input ? true : '应用密钥不能为空'
85
+ },
86
+ {
87
+ type: 'input',
88
+ name: 'botName',
89
+ message: '机器人名称:',
90
+ default: 'Fontdo Bot'
91
+ },
92
+ {
93
+ type: 'confirm',
94
+ name: 'enabled',
95
+ message: '是否启用该账号:',
96
+ default: true
97
+ }
98
+ ]);
99
+
100
+ // 初始化 accounts 对象
101
+ config.channels['5g-message'].accounts = config.channels['5g-message'].accounts || {};
102
+
103
+ // 保存账号配置
104
+ config.channels['5g-message'].accounts[accountAnswers.accountId] = {
105
+ host: accountAnswers.host,
106
+ appId: accountAnswers.appId,
107
+ appKey: accountAnswers.appKey,
108
+ botName: accountAnswers.botName,
109
+ enabled: accountAnswers.enabled
110
+ };
111
+
112
+ // 询问是否继续添加账号
113
+ const addMore = await inquirer.prompt([
114
+ {
115
+ type: 'confirm',
116
+ name: 'addAnother',
117
+ message: '是否继续添加其他账号?',
118
+ default: false
119
+ }
120
+ ]);
121
+
122
+ continueAdding = addMore.addAnother;
123
+ }
124
+
125
+ // 确保配置目录存在
126
+ await fs.ensureDir(CONFIG_DIR);
127
+
128
+ // 写入配置文件
129
+ await fs.writeJSON(CONFIG_FILE, config, { spaces: 2 });
130
+
131
+ console.log('');
132
+ console.log(chalk.green('✅ 配置已保存!'));
133
+ console.log(chalk.gray(`配置文件路径: ${CONFIG_FILE}`));
134
+ console.log('');
135
+
136
+ // 显示当前配置的账号列表
137
+ const accounts = config.channels['5g-message'].accounts || {};
138
+ const accountIds = Object.keys(accounts);
139
+
140
+ if (accountIds.length > 0) {
141
+ console.log(chalk.blue('📋 已配置账号:'));
142
+ accountIds.forEach((id) => {
143
+ const account = accounts[id];
144
+ const status = account.enabled ? chalk.green('启用') : chalk.red('禁用');
145
+ console.log(` - ${id}: ${status} (${account.host})`);
146
+ });
147
+ console.log('');
148
+ }
149
+
150
+ console.log(chalk.blue('下一步:重启 OpenClaw 服务以应用配置'));
151
+ console.log(chalk.gray('命令: openclaw restart'));
152
+ }
153
+
154
+ // 主函数
155
+ async function main() {
156
+ const args = process.argv.slice(2);
157
+
158
+ if (args.includes('install')) {
159
+ await install();
160
+ } else {
161
+ await configure();
162
+ }
163
+ }
164
+
165
+ main().catch((error) => {
166
+ console.error(chalk.red('操作失败:', error.message));
167
+ process.exit(1);
168
+ });
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@fontdo/5g-message",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "OpenClaw 通道插件,用于连接 Fontdo 5G 消息平台",
5
5
  "main": "index.ts",
6
+ "bin": {
7
+ "fontdo-5g-message": "./cli.ts"
8
+ },
6
9
  "scripts": {
7
10
  "build": "tsc",
8
11
  "test": "vitest"
9
12
  },
10
13
  "dependencies": {
11
- "ws": "^8.16.0"
14
+ "ws": "^8.16.0",
15
+ "inquirer": "^8.2.7",
16
+ "fs-extra": "^11.3.3",
17
+ "chalk": "^4.1.2"
12
18
  },
13
19
  "devDependencies": {
14
20
  "@types/node": "^20.11.0",