From 4bd8843f9a33c16bfebe725709a056f6c2237315 Mon Sep 17 00:00:00 2001 From: Han Fangyuan Date: Mon, 3 Jun 2024 22:18:25 +0800 Subject: [PATCH 1/2] fix: test code for wechat and wework --- package.json | 14 ++++++++++++-- test/index.js | 19 ------------------- test/wechat.js | 36 ++++++++++++++++++++++++++++++++++++ test/wework.js | 27 +++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 21 deletions(-) delete mode 100644 test/index.js create mode 100644 test/wechat.js create mode 100644 test/wework.js diff --git a/package.json b/package.json index 107609b..21d49c6 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "clean": "shx rm -fr dist/*", "dist": "npm-run-all clean build dist:commonjs", "dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json", - "test": "node test/index.js", + "test:wechat": "node test/wechat.js", + "test:wework": "node test/wework.js", "release": "verpub publish", "release:dry": "verpub --dry-run" }, @@ -55,7 +56,16 @@ "eslint-config-prettier": "^6.11.0", "eslint-plugin-prettier": "^3.1.4", "npm-run-all": "^4.1.5", - "prettier": "^2.0.5" + "prettier": "^2.0.5", + "@juzi/wechaty": "^1.0.87", + "@grpc/grpc-js": "1.9.14", + "@juzi/wechaty-puppet": "^1.0.78", + "@juzi/wechaty-puppet-service": "^1.0.87", + "wechaty": "^1.20.2", + "wechaty-puppet-service": "^1.18.2", + "wechaty-puppet-wechat4u": "^1.14.12", + "wechaty-puppet-padlocal": "^1.20.1", + "wechaty-puppet": "^1.21.1" }, "readme": "README.md", "engines": { diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 6adf896..0000000 --- a/test/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import { WechatyBuilder } from 'wechaty' -import WechatyWebPanelPlugin from '../src/index.js' - -const name = 'wechat-assistant' - -const bot = WechatyBuilder.build({ - name, // generate xxxx.memory-card.json and save login data for the next login - puppet: 'wechaty-puppet-wechat', - puppetOptions: { - uos: true - }, -}) -bot - .use(WechatyWebPanelPlugin({ - apiKey: '', - apiSecret: '' - })) -bot.start() - .catch((e) => console.error(e)) diff --git a/test/wechat.js b/test/wechat.js new file mode 100644 index 0000000..4d0aa53 --- /dev/null +++ b/test/wechat.js @@ -0,0 +1,36 @@ +import {WechatyBuilder} from 'wechaty' +import {WechatyWebPanelPlugin, WechatyMessageRecordPlugin} from '../src/index.js' + +const name = 'wechat-assistant-pro'; +let bot = ''; +let padLocalToken = '' // 如果申请了ipadlocal的token,可以直接填入 + +if (process.env['PAD_LOCAL_TOKEN']) { + console.log('读取到环境变量中的ipadLocalToken') + padLocalToken = process.env['PAD_LOCAL_TOKEN'] +} + +if (padLocalToken) { + console.log('读取到环境变量中的ipad token 使用ipad协议启动') + bot = WechatyBuilder.build({ + name, // generate xxxx.memory-card.json and save login data for the next login + puppetOptions: { + token: padLocalToken + }, puppet: 'wechaty-puppet-padlocal', + }); + +} else { + console.log('默认使用wechat4u协议启动') + bot = WechatyBuilder.build({ + name, // generate xxxx.memory-card.json and save login data for the next login + puppet: 'wechaty-puppet-wechat4u', + }); +} + + +bot.use(WechatyWebPanelPlugin({ + apiKey: '***', apiSecret: '***', +})) +bot.use(WechatyMessageRecordPlugin()) +bot.start() + .catch((e) => console.error(e)); diff --git a/test/wework.js b/test/wework.js new file mode 100644 index 0000000..b77f1cc --- /dev/null +++ b/test/wework.js @@ -0,0 +1,27 @@ +import {WechatyBuilder} from '@juzi/wechaty' +import {WechatyWebPanelPlugin, WechatyMessageRecordPlugin} from '../src/index.js' + +const name = 'worker-assistant'; +let bot = ''; +let workProToken = '' // 如果申请了企业微信的token 可以直接填入 + +if (process.env['WORK_PRO_TOKEN']) { + console.log('读取到环境变量中的企微token') + workProToken = process.env['WORK_PRO_TOKEN'] +} +bot = WechatyBuilder.build({ + name, // generate xxxx.memory-card.json and save login data for the next login + puppet: '@juzi/wechaty-puppet-service', + puppetOptions: { + authority: 'token-service-discovery-test.juzibot.com', + tls: { disable: true }, + token: workProToken + }, +}); + +bot.use(WechatyWebPanelPlugin({ + apiKey: '***', apiSecret: '***', +})) +bot.use(WechatyMessageRecordPlugin()) +bot.start() + .catch((e) => console.error(e)); From f43afdb5fb007eeda06386d01afba1124701e059 Mon Sep 17 00:00:00 2001 From: Han Fangyuan Date: Mon, 3 Jun 2024 22:30:04 +0800 Subject: [PATCH 2/2] doc: update readme for test --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index fe63f67..a32d73b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,29 @@ Wechaty Web Panel 插件,让你的 Wechaty 机器人快速接入 web 控制面 本项目为插件源码,非直接运行的项目。如需可直接运行的项目,请直接拉取 [https://github.com/leochen-g/wechat-assistant-pro](https://github.com/leochen-g/wechat-assistant-pro) 即可 +## 快速测试 + +### 下载源码并安装依赖 + +```sh +git clone https://github.com/leochen-g/wechaty-web-panel.git +cd wechaty-web-panel +npm install # 可指定淘宝镜像源加速: --registry=https://registry.npmmirror.com +``` + +### 测试微信 + +在 test/wechat.js文件中填入apiKey与apiSecret,运行如下命令 +```sh +npm run test:wechat +``` + +### 测试企业微信 +需要有企业微信token,在test/wework.js填入workProToken、apiKey与apiSecret,运行如下命令 +```sh +npm run test:wework +``` + ## 面板主要功能 * 定时提醒