openclaw-imessage-photon-cli 0.1.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 +27 -0
- package/cli.mjs +135 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# openclaw-imessage-photon-cli
|
|
2
|
+
|
|
3
|
+
一键安装 [openclaw-imessage-photon](https://github.com/ethanjtch/openclaw-imessage-photon)(OpenClaw 的 iMessage / Photon 渠道插件)。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y openclaw-imessage-photon-cli@latest install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
它会:
|
|
12
|
+
1. 检测本机 `openclaw`
|
|
13
|
+
2. 调用 `openclaw plugins install npm:openclaw-imessage-photon`
|
|
14
|
+
3. 引导填写 Photon 项目凭据并写入 `openclaw.json` 的 `channels.imessage-photon`
|
|
15
|
+
|
|
16
|
+
## 手动安装(不想要 CLI)
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
openclaw plugins install npm:openclaw-imessage-photon
|
|
20
|
+
openclaw gateway restart
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
详见主仓库 README。
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* openclaw-imessage-photon-cli
|
|
4
|
+
*
|
|
5
|
+
* Lightweight installer for the OpenClaw iMessage (Photon) channel plugin.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx -y openclaw-imessage-photon-cli@latest install
|
|
9
|
+
*/
|
|
10
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
11
|
+
|
|
12
|
+
const PLUGIN_SPEC = "npm:openclaw-imessage-photon";
|
|
13
|
+
const CHANNEL_ID = "imessage-photon";
|
|
14
|
+
|
|
15
|
+
function log(msg) {
|
|
16
|
+
console.log(`\x1b[36m[imessage-photon]\x1b[0m ${msg}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function error(msg) {
|
|
20
|
+
console.error(`\x1b[31m[imessage-photon]\x1b[0m ${msg}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function run(cmd, { silent = true } = {}) {
|
|
24
|
+
const stdio = silent ? ["pipe", "pipe", "pipe"] : "inherit";
|
|
25
|
+
const result = spawnSync(cmd, { shell: true, stdio });
|
|
26
|
+
if (result.status !== 0) {
|
|
27
|
+
throw new Error(`Command failed (${result.status}): ${cmd}`);
|
|
28
|
+
}
|
|
29
|
+
return silent ? (result.stdout || "").toString().trim() : "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function which(bin) {
|
|
33
|
+
try {
|
|
34
|
+
return execSync(`which ${bin}`, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
35
|
+
} catch {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getOpenclawVersion() {
|
|
41
|
+
try {
|
|
42
|
+
return run("openclaw --version").trim();
|
|
43
|
+
} catch {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Open the gateway systemd env file and append DEEPGRAM/etc? No — this CLI only
|
|
50
|
+
* installs the channel. Credentials are set via `openclaw onboard` or by
|
|
51
|
+
* editing channels.imessage-photon in openclaw.json (prompted below).
|
|
52
|
+
*/
|
|
53
|
+
function prompt(label) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
process.stdout.write(`\x1b[36m[imessage-photon]\x1b[0m ${label}: `);
|
|
56
|
+
process.stdin.once("data", (buf) => resolve(buf.toString().trim()));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function install() {
|
|
61
|
+
// 1. Check openclaw
|
|
62
|
+
if (!which("openclaw")) {
|
|
63
|
+
error("未找到 openclaw。请先安装:");
|
|
64
|
+
console.log(" npm install -g openclaw");
|
|
65
|
+
console.log(" 详见 https://docs.openclaw.ai/install");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
const version = getOpenclawVersion();
|
|
69
|
+
log(`检测到 OpenClaw: ${version || "(未知版本)"}`);
|
|
70
|
+
|
|
71
|
+
// 2. Install the channel plugin via OpenClaw's package manager
|
|
72
|
+
log(`安装渠道插件 ${PLUGIN_SPEC} ...`);
|
|
73
|
+
try {
|
|
74
|
+
run(`openclaw plugins install "${PLUGIN_SPEC}"`);
|
|
75
|
+
log("渠道插件安装完成。");
|
|
76
|
+
} catch (err) {
|
|
77
|
+
error("安装失败,请尝试手动执行:");
|
|
78
|
+
console.log(` openclaw plugins install "${PLUGIN_SPEC}"`);
|
|
79
|
+
console.error(String(err.message || err));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 3. Prompt for credentials if the channel isn't configured yet
|
|
84
|
+
log("现在需要配置 Photon 项目凭据。");
|
|
85
|
+
log("(也可先跳过,稍后用 `openclaw onboard` 或编辑 openclaw.json 配置)");
|
|
86
|
+
|
|
87
|
+
const skip = (await prompt("已注册 https://photon.codes 并创建项目?[y/N]")).toLowerCase();
|
|
88
|
+
if (skip !== "y" && skip !== "yes") {
|
|
89
|
+
log("跳过凭据配置。稍后配置:编辑 openclaw.json 的 channels.imessage-photon 或运行 openclaw onboard。");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const projectId = await prompt("Photon Project ID");
|
|
94
|
+
const projectSecret = await prompt("Photon Project Secret(不会显示)");
|
|
95
|
+
|
|
96
|
+
// 4. Write channels.imessage-photon into openclaw.json (best-effort, non-destructive)
|
|
97
|
+
const configPath = `${process.env.HOME || "/root"}/.openclaw/openclaw.json`;
|
|
98
|
+
try {
|
|
99
|
+
const fs = await import("node:fs");
|
|
100
|
+
const raw = fs.readFileSync(configPath, "utf8");
|
|
101
|
+
const cfg = JSON.parse(raw);
|
|
102
|
+
cfg.channels = cfg.channels || {};
|
|
103
|
+
cfg.channels[CHANNEL_ID] = {
|
|
104
|
+
...(cfg.channels[CHANNEL_ID] || {}),
|
|
105
|
+
enabled: true,
|
|
106
|
+
projectId,
|
|
107
|
+
projectSecret,
|
|
108
|
+
};
|
|
109
|
+
fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2));
|
|
110
|
+
log(`已写入配置:${configPath} 的 channels.${CHANNEL_ID}`);
|
|
111
|
+
log("重启 gateway 生效:openclaw gateway restart");
|
|
112
|
+
} catch (err) {
|
|
113
|
+
error("写入 openclaw.json 失败,请手动编辑:");
|
|
114
|
+
console.log(` channels.${CHANNEL_ID}: { enabled: true, projectId: "...", projectSecret: "..." }`);
|
|
115
|
+
console.error(String(err.message || err));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
log("完成!已将凭据写入配置。如果目标是 iMessage,请确保 allowFrom 包含你的号码。");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const command = process.argv[2] || "install";
|
|
122
|
+
switch (command) {
|
|
123
|
+
case "install":
|
|
124
|
+
case "config":
|
|
125
|
+
install().catch((err) => {
|
|
126
|
+
error(String(err.message || err));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
case "--help":
|
|
131
|
+
case "help":
|
|
132
|
+
default:
|
|
133
|
+
console.log(`用法: npx openclaw-imessage-photon-cli install`);
|
|
134
|
+
break;
|
|
135
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openclaw-imessage-photon-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightweight installer for the OpenClaw iMessage (Photon) channel plugin — npx install + credential setup.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": ["openclaw", "imessage", "photon", "spectrum", "installer", "cli"],
|
|
8
|
+
"author": "ethanjtch",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ethanjtch/openclaw-imessage-photon.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/ethanjtch/openclaw-imessage-photon#readme",
|
|
14
|
+
"bin": {
|
|
15
|
+
"imessage-photon-installer": "cli.mjs"
|
|
16
|
+
},
|
|
17
|
+
"files": ["cli.mjs", "README.md"],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {},
|
|
22
|
+
"scripts": {}
|
|
23
|
+
}
|