#!/usr/bin/env node
import { execSync, spawnSync } from "node:child_process";
const PLUGIN_SPEC = "@tencent-weixin/openclaw-weixin";
const CHANNEL_ID = "openclaw-weixin";
// ── helpers ──────────────────────────────────────────────────────────────────
function log(msg) {
console.log(x1b[36m[openclaw-weixin]x1b[0m ${msg});
}
function error(msg) {
console.error(x1b[31m[openclaw-weixin]x1b[0m ${msg});
}
function run(cmd, { silent = true } = {}) {
const stdio = silent ? ["pipe", "pipe", "pipe"] : "inherit";
const result = spawnSync(cmd, { shell: true, stdio });
if (result.status !== 0) {
const err = new Error(Command failed with exit code ${result.status}: ${cmd});
err.stderr = silent ? (result.stderr || "").toString() : "";
throw err;
}
return silent ? (result.stdout || "").toString().trim() : "";
}
function which(bin) {
try {
return execSync(which ${bin}, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
} catch {
return null;
}
}
// ── commands ─────────────────────────────────────────────────────────────────
function install() {
// 1. Check openclaw is installed
//if (!which("openclaw")) {
// error("未找到 openclaw,请先安装:");
// console.log(" npm install -g openclaw");
// console.log(" 详见 https://docs.openclaw.ai/install");
// process.exit(1);
//}
log("已找到本地安装的 openclaw");
// 2. Install plugin via openclaw
log("正在安装插件…");
try {
const installOut = run(openclaw plugins install "${PLUGIN_SPEC}");
if (installOut) log(installOut);
} catch (installErr) {
if (installErr.stderr && installErr.stderr.includes("already exists")) {
log("检测到本地已安装,正在更新…");
try {
const updateOut = run(openclaw plugins update "${CHANNEL_ID}");
if (updateOut) log(updateOut);
} catch (updateErr) {
error("插件更新失败,请手动执行:");
if (updateErr.stderr) console.error(updateErr.stderr);
console.log( openclaw plugins update "${CHANNEL_ID}");
process.exit(1);
}
} else {
error("插件安装失败,请手动执行:");
if (installErr.stderr) console.error(installErr.stderr);
console.log( openclaw plugins install "${PLUGIN_SPEC}");
process.exit(1);
}
}
// 3. Login (interactive QR scan)
log("插件就绪,开始首次连接…");
try {
run(openclaw channels login --channel ${CHANNEL_ID}, { silent: false });
} catch {
console.log();
error("首次连接未完成,可稍后手动重试:");
console.log( openclaw channels login --channel ${CHANNEL_ID});
}
// 4. Restart gateway so it picks up the new account
log("正在重启 OpenClaw Gateway…");
try {
run(openclaw gateway restart, { silent: false });
} catch {
error("重启失败,可手动执行:");
console.log( openclaw gateway restart);
}
}
function help() {
console.log();
用法: npx -y @tencent-weixin/openclaw-weixin-cli <命令>
命令:
install 安装微信插件并扫码连接
help 显示帮助信息
}
// ── main ─────────────────────────────────────────────────────────────────────
const command = process.argv[2];
switch (command) {
case "install":
install();
break;
case "help":
case "–help":
case "-h":
help();
break;
default:
if (command) {
error(未知命令: ${command});
}
help();
process.exit(command ? 1 : 0);
}
OpenClaw 接入微信
OpenClaw 接入微信usr bin env node import execSync spawnSync from node child process const PLUGIN SPEC tencent weixin openclaw weixin const CHANNEL ID
大家好,我是讯享网,很高兴认识大家。这里提供最前沿的Ai技术和互联网信息。
2026年017:DeepSeek如何精确实现潜在注意力(MLA + RoPE)
上一篇
2026-03-28 16:19
V观财报丨博彦科技:暂未开展面向个人或单一用户的OpenClaw安装部署服务
下一篇
2026-03-28 16:17
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/247756.html