Development

Huan LI edited this page Aug 12, 2018 · 1 revision

DEVELOPMENT

A Wechaty Puppet is a node package published on NPM that follow a defined convention.

How to implement a wechaty puppet

related tutorial: How to implement a wechaty-puppet

Structure

package.json

The package.json is a manifest format for describing Node.js modules. Wechaty Puppets are built on top of Node modules. It declares dependencies, version, ownership, and other information required to run a plugin in Wechaty. This document describes the schema in detail.

A plugin manifest package.json can also contain details about the required configuration. The configuration schema is defined in the wechaty field of the package.json (This field follow the JSON-Schema guidelines):

{
    "name": "wechaty-puppet-mytest",
    "version": "0.0.1",
    "description": "This is my first Wechaty Puppet",
    "engines": {
        "wechaty": ">=0.16.x"
    },
    "wechaty": {
        "properties": {
            "myConfigKey": {
                "type": "string",
                "default": "it's the default value",
                "description": "It defines my awesome config!"
            }
        }
    }
}

You can learn more about package.json from the NPM documentation.

The package name must begin with wechaty-puppet- and the package engines should contain wechaty.

index.js

The index.js is the main entry point of your puppet implementation:

import { Puppet } from 'wechaty'

export class PuppetMyTest extends Puppet {
  // ... implenmentation here ...
}

export default PuppetMyTest

Publish Your Puppet

Wechaty Puppet can be published on NPM.

To publish a new Puppet, you need to create an account on npmjs.com then publish it from the command line:

$ npm publish
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.