Installations
npm install wechaty-puppet-mock-koa
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.15.1
NPM Version
6.14.8
Score
53.1
Supply Chain
57.4
Quality
69.8
Maintenance
50
Vulnerability
95.8
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
moderncrazy
Download Statistics
Total Downloads
3,544
Last Day
1
Last Week
32
Last Month
58
Last Year
336
GitHub Statistics
36 Commits
1 Watching
1 Branches
2 Contributors
Package Meta Information
Latest Version
0.2.3
Package Id
wechaty-puppet-mock-koa@0.2.3
Unpacked Size
108.72 kB
Size
18.10 kB
File Count
34
NPM Version
6.14.8
Node Version
14.15.1
Total Downloads
Cumulative downloads
Total Downloads
3,544
Last day
0%
1
Compared to previous day
Last week
39.1%
32
Compared to previous week
Last month
728.6%
58
Compared to previous month
Last year
-24.2%
336
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
wechaty-puppet-mock-koa
packaging with koa based on wechaty-puppet-mock, It is convenient to test wechaty with restful interface.
Install
1$ npm install wechaty-puppet-mock-koa --save-dev
Usage
PuppetKoa
Class
-
constructor([options])
- new classPuppetKoa
instanceoptions.port
- http listen port, default to3000
.options.prefix
- http request prefix, default to/mock
.options.loginData
- information used to simulate login.options.loginData.id
- login bot id, default tobot_id
.options.loginData.status
- login bot status, default to0
.options.loginData.qrcode
- login bot qrcode, default tohttps://not-exist.com
.
options.initFile
- initial importedlogin
,contact
,room
data, is a JSON file path, default tonull
.
NOTE:
loginData
not required ifinitFile
exists
Example
index.js
1const {PuppetPadplus} = require('wechaty-puppet-padplus'); 2 3let puppet = null; 4 5if (process.env.NODE_ENV != 'dev') { 6 // use ipad puppet 7 puppet = new PuppetPadplus({token: 'xxx'}); 8} else { 9 // use mock puppet 10 const {PuppetKoa} = require('wechaty-puppet-mock-koa'); 11 puppet = new PuppetKoa({port:3001,prefix:'/api',initFile:'./initFile.json'}); 12} 13 14// create bot 15const bot = new Wechaty({name: config.botName, puppet}); 16 17... 18 19// receive message 20bot.on('message', async (msg) => { 21 console.log(msg.from().name(),msg.text()); 22}); 23 24...
initFile.json
login
configuration is required.- the configuration of
login
andcontact
is consistent with the parameters ofcreate contact ([PUT] /mock/contact)
interface - people in
roomMemberList
are better existing in thecontactList
- the configuration of
room
is consistent with the parameters ofcreate room ([PUT] /mock/room)
interface
1// /doc/mock.json 2{ 3 "login": { 4 "id": "bot_id", 5 "name": "bot_name", 6 "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4", 7 "type": 1, 8 "gender": 1, 9 "city": "shanghai", 10 "alias": "bot_alias", 11 "star": false, 12 "weixin": "weixin", 13 "friend": true, 14 "address": "shanghai", 15 "province": "shanghai" 16 }, 17 "contactList": [ 18 { 19 "id": "friend_1", 20 "name": "friend_1_name", 21 "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4", 22 "type": 1, 23 "gender": 1, 24 "city": "shanghai", 25 "alias": "friend_1_alias", 26 "star": false, 27 "weixin": "weixin", 28 "friend": true, 29 "address": "shanghai", 30 "province": "shanghai" 31 } 32 ], 33 "roomMemberList": [ 34 { 35 "id": "friend_1", 36 "roomAlias": "friend_1_alias", 37 "inviterId": "bot_id" 38 } 39 ], 40 "roomList": [ 41 { 42 "id": "room_1", 43 "topic": "room_topic", 44 "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4", 45 "ownerId": "bot_id", 46 "adminIdList": [ 47 "bot_id" 48 ], 49 "memberIdList": [ 50 "bot_id", 51 "friend_1" 52 ] 53 } 54 ] 55}
API sample
-
send message
1// request 2curl -X POST \ 3 http://localhost:3000/mock/message/single \ 4 -H 'Cache-Control: no-cache' \ 5 -H 'Content-Type: application/json' \ 6 -H 'Postman-Token: f7f34936-8a75-41f3-b008-7c48992bceca' \ 7 -d '{ 8 "type": 7, 9 "text": "hello", 10 "toId": "bot_id", 11 "fromId": "friend_1", 12 "filename": "/path/test.json" 13}' 14 15// response 16{"state":200,"message":"Request success!"} 17 18// console 19friend_1_name hello
Reference resources
- API Specification:/doc/api_specification.md
- Postman Script: /doc/wechaty-puppet-mock-koa.postman_collection.json
Note
- Run with wechaty 0.46.x+
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More