fix: registerCommand uses 'name' not 'command', fix handler signature, add missing clearState import
- OpenClaw SDK expects 'name' field in OpenClawPluginCommandDefinition, not 'command'
(caused TypeError: Cannot read properties of undefined reading 'trim')
- Handler receives { config } not { cfg, reply }, returns ReplyPayload
- Add missing clearState import for /wechat-logout command
- Bump version to 1.0.2
This commit is contained in:
21
index.ts
21
index.ts
@@ -3,7 +3,7 @@ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|||||||
import { WechatAccessWebSocketClient, handlePrompt, handleCancel } from "./websocket/index.js";
|
import { WechatAccessWebSocketClient, handlePrompt, handleCancel } from "./websocket/index.js";
|
||||||
// import { handleSimpleWecomWebhook } from "./http/webhook.js";
|
// import { handleSimpleWecomWebhook } from "./http/webhook.js";
|
||||||
import { setWecomRuntime } from "./common/runtime.js";
|
import { setWecomRuntime } from "./common/runtime.js";
|
||||||
import { performLogin, loadState, getDeviceGuid, getEnvironment } from "./auth/index.js";
|
import { performLogin, loadState, clearState, getDeviceGuid, getEnvironment } from "./auth/index.js";
|
||||||
|
|
||||||
// 类型定义
|
// 类型定义
|
||||||
type NormalizedChatType = "direct" | "group" | "channel";
|
type NormalizedChatType = "direct" | "group" | "channel";
|
||||||
@@ -228,10 +228,10 @@ const index = {
|
|||||||
|
|
||||||
// 3. 注册 /wechat-login 命令(手动触发扫码登录)
|
// 3. 注册 /wechat-login 命令(手动触发扫码登录)
|
||||||
api.registerCommand?.({
|
api.registerCommand?.({
|
||||||
command: "wechat-login",
|
name: "wechat-login",
|
||||||
description: "手动执行微信扫码登录,获取 channel token",
|
description: "手动执行微信扫码登录,获取 channel token",
|
||||||
handler: async ({ cfg, reply }) => {
|
handler: async ({ config }) => {
|
||||||
const channelCfg = cfg?.channels?.["wechat-access-unqclawed"];
|
const channelCfg = config?.channels?.["wechat-access-unqclawed"];
|
||||||
const bypassInvite = channelCfg?.bypassInvite === true;
|
const bypassInvite = channelCfg?.bypassInvite === true;
|
||||||
const authStatePath = channelCfg?.authStatePath
|
const authStatePath = channelCfg?.authStatePath
|
||||||
? String(channelCfg.authStatePath)
|
? String(channelCfg.authStatePath)
|
||||||
@@ -244,31 +244,30 @@ const index = {
|
|||||||
const guid = getDeviceGuid();
|
const guid = getDeviceGuid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reply("正在启动微信扫码登录,请查看终端...");
|
|
||||||
const credentials = await performLogin({
|
const credentials = await performLogin({
|
||||||
guid,
|
guid,
|
||||||
env,
|
env,
|
||||||
bypassInvite,
|
bypassInvite,
|
||||||
authStatePath,
|
authStatePath,
|
||||||
});
|
});
|
||||||
reply(`登录成功! token: ${credentials.channelToken.substring(0, 6)}... (已保存,重启 Gateway 生效)`);
|
return { text: `登录成功! token: ${credentials.channelToken.substring(0, 6)}... (已保存,重启 Gateway 生效)` };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reply(`登录失败: ${err instanceof Error ? err.message : String(err)}`);
|
return { text: `登录失败: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. 注册 /wechat-logout 命令(清除已保存的登录态)
|
// 4. 注册 /wechat-logout 命令(清除已保存的登录态)
|
||||||
api.registerCommand?.({
|
api.registerCommand?.({
|
||||||
command: "wechat-logout",
|
name: "wechat-logout",
|
||||||
description: "清除已保存的微信登录态",
|
description: "清除已保存的微信登录态",
|
||||||
handler: async ({ cfg, reply }) => {
|
handler: async ({ config }) => {
|
||||||
const channelCfg = cfg?.channels?.["wechat-access-unqclawed"];
|
const channelCfg = config?.channels?.["wechat-access-unqclawed"];
|
||||||
const authStatePath = channelCfg?.authStatePath
|
const authStatePath = channelCfg?.authStatePath
|
||||||
? String(channelCfg.authStatePath)
|
? String(channelCfg.authStatePath)
|
||||||
: undefined;
|
: undefined;
|
||||||
clearState(authStatePath);
|
clearState(authStatePath);
|
||||||
reply("已清除登录态,下次启动将重新扫码登录。");
|
return { text: "已清除登录态,下次启动将重新扫码登录。" };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@henryxiaoyang/wechat-access-unqclawed",
|
"name": "@henryxiaoyang/wechat-access-unqclawed",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "OpenClaw 微信通路插件 — 扫码登录 + AGP WebSocket 双向通信",
|
"description": "OpenClaw 微信通路插件 — 扫码登录 + AGP WebSocket 双向通信",
|
||||||
"author": "HenryXiaoYang",
|
"author": "HenryXiaoYang",
|
||||||
|
|||||||
Reference in New Issue
Block a user