Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test code for wechat and wework #18

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

## 面板主要功能

* 定时提醒
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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": {
Expand Down
19 changes: 0 additions & 19 deletions test/index.js

This file was deleted.

36 changes: 36 additions & 0 deletions test/wechat.js
Original file line number Diff line number Diff line change
@@ -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));
27 changes: 27 additions & 0 deletions test/wework.js
Original file line number Diff line number Diff line change
@@ -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));