npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wechaty-puppet-mock-koa

v0.2.3

Published

It is convenient to test wechaty with restful interface

Readme

wechaty-puppet-mock-koa

packaging with koa based on wechaty-puppet-mock, It is convenient to test wechaty with restful interface.

Install

$ npm install wechaty-puppet-mock-koa --save-dev

Usage

PuppetKoa Class

  • constructor([options]) - new class PuppetKoa instance

    • options.port - http listen port, default to 3000.
    • options.prefix - http request prefix, default to /mock.
    • options.loginData - information used to simulate login.
      • options.loginData.id - login bot id, default to bot_id.
      • options.loginData.status - login bot status, default to 0.
      • options.loginData.qrcode - login bot qrcode, default to https://not-exist.com.
    • options.initFile - initial imported login, contact, room data, is a JSON file path, default to null.

    NOTE:loginData not required if initFile exists

Example

index.js

const {PuppetPadplus} = require('wechaty-puppet-padplus');

let puppet = null;

if (process.env.NODE_ENV != 'dev') {
  // use ipad puppet
  puppet = new PuppetPadplus({token: 'xxx'});
} else {
  // use mock puppet
  const {PuppetKoa} = require('wechaty-puppet-mock-koa');
  puppet = new PuppetKoa({port:3001,prefix:'/api',initFile:'./initFile.json'});
}

// create bot
const bot = new Wechaty({name: config.botName, puppet});

...

// receive message
bot.on('message', async (msg) => {
  console.log(msg.from().name(),msg.text());
});

...

initFile.json

  • login configuration is required.
  • the configuration of login and contact is consistent with the parameters of create contact ([PUT] /mock/contact) interface
  • people in roomMemberList are better existing in the contactList
  • the configuration of room is consistent with the parameters of create room ([PUT] /mock/room) interface
// /doc/mock.json
{
  "login": {
    "id": "bot_id",
    "name": "bot_name",
    "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4",
    "type": 1,
    "gender": 1,
    "city": "shanghai",
    "alias": "bot_alias",
    "star": false,
    "weixin": "weixin",
    "friend": true,
    "address": "shanghai",
    "province": "shanghai"
  },
  "contactList": [
    {
      "id": "friend_1",
      "name": "friend_1_name",
      "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4",
      "type": 1,
      "gender": 1,
      "city": "shanghai",
      "alias": "friend_1_alias",
      "star": false,
      "weixin": "weixin",
      "friend": true,
      "address": "shanghai",
      "province": "shanghai"
    }
  ],
  "roomMemberList": [
    {
      "id": "friend_1",
      "roomAlias": "friend_1_alias",
      "inviterId": "bot_id"
    }
  ],
  "roomList": [
    {
      "id": "room_1",
      "topic": "room_topic",
      "avatar": "https://avatars0.githubusercontent.com/u/21285357?s=200&v=4",
      "ownerId": "bot_id",
      "adminIdList": [
        "bot_id"
      ],
      "memberIdList": [
        "bot_id",
        "friend_1"
      ]
    }
  ]
}

API sample

  • send message

    // request
    curl -X POST \
      http://localhost:3000/mock/message/single \
      -H 'Cache-Control: no-cache' \
      -H 'Content-Type: application/json' \
      -H 'Postman-Token: f7f34936-8a75-41f3-b008-7c48992bceca' \
      -d '{
    	"type": 7,
    	"text": "hello",
    	"toId": "bot_id",
    	"fromId": "friend_1",
    	"filename": "/path/test.json"
    }'
      
    // response
    {"state":200,"message":"Request success!"}
      
    // console
    friend_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+