botium-connector-wechat

0.0.1 • Public • Published

Botium Connector for Wechat

NPM

Codeship Status for codeforequity-at/botium-connector-wechat npm version license

This is a Botium connector for testing your Wechat chatbot.

Did you read the Botium in a Nutshell articles? Be warned, without prior knowledge of Botium you won't be able to properly use this library!

How it works

  • Does not use the Wechat API, just the webservice behind it.
  • Does not support async communication. (Because async communication means call from webservice to Wechat API)
  • Just for text messages (booth directions)
  • Provides a valid signature, token validation is possible
  • Able to emulate sessions (via WECHAT_GENERATE_FROM_USERNAME capability)

It can be used as any other Botium connector with all Botium Stack components:

Requirements

  • Node.js and NPM
  • a Wechat-capable webservice. It must not bound to Wechat. Its URL must not be public.
  • a project directory on your workstation to hold test cases and Botium configuration

Install Botium and Wechat Connector

When using Botium CLI:

> npm install -g botium-cli
> npm install -g botium-connector-wechat
> botium-cli init
> botium-cli run

When using Botium Bindings:

> npm install -g botium-bindings
> npm install -g botium-connector-wechat
> botium-bindings init mocha
> npm install && npm run mocha

When using Botium Box:

Already integrated into Botium Box, no setup required

Connecting Wechat to Botium

Create a botium.json with te URL, and Token of your service

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "<whatever>",
      "CONTAINERMODE": "wechat",
      "WECHAT_WEBHOOK_URL": "...",
      "WECHAT_TOKEN": "..."
    }
  }
}

To check the configuration, run the emulator (Botium CLI required) to bring up a chat interface in your terminal window:

> botium-cli emulator

Botium setup is ready, you can begin to write your BotiumScript files.

How to start sample

There is a small demo in samples/techdemo with Botium Bindings.

It contains a Wechat capable Chatbot, and its Test. They are already configured (see Chatbot, and Test).

The code is separated into Chatbot, and Test project just for better understanding, don't follow this.

Starting:

  • Run the Chatbot
> cd ./samples/techdemo/chatbot
> npm install && npm start
  • Run the Test
> cd ./samples/techdemo/test
> npm install && npm test

Supported Capabilities

Set the capability CONTAINERMODE to wechat to activate this connector.

WECHAT_WEBHOOK_URL

The URL to the webservice.

WECHAT_TOKEN

Wechat token. (Used to register the webhook in Wechat portal)

WECHAT_TO_USERNAME

Optional

Wechat ID of the chatbot. If it is omitted, then Connector generates one

WECHAT_GENERATE_FROM_USERNAME

Optional

Wechat Open ID of the sender. If it is omitted, then Connector generates one for each test. Good to emulate sessions.

Roadmap

  • Support for async messages (Communicating direct with Wechat API)
  • Rich component support in Wechat responses (links, images...)
  • Simulate user interaction (If Wechat supports it)
  • Add some technical checks
    • Signature (Token) validation
    • Get endpoint (Availability, response, token validation)

Readme

Keywords

none

Package Sidebar

Install

npm i botium-connector-wechat

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

38.4 kB

Total Files

20

Last publish

Collaborators

  • ftreml