diff --git a/README.md b/README.md index 6d432217a61568fa13f328e214c965bac51d16a8..673dccfe45f8ab1810b574755ea747e8feb8eea2 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Wechaty is a Bot-Enable Framework/Library for Personal Account of Wechat. [![Join the chat at https://gitter.im/zixia/wechaty](https://badges.gitter.im/zixia/wechaty.svg)](https://gitter.im/zixia/wechaty?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![node](https://img.shields.io/node/v/wechaty.svg?maxAge=2592000)](https://nodejs.org/) +[![Repo Size](https://reposs.herokuapp.com/?path=zixia/wechaty)]() [![npm version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty) [![Downloads][downloads-image]][downloads-url] @@ -60,8 +61,8 @@ Plan to glue with Machine Learning/Deep Learning/Neural Network/Natural Language # Installation Use NPM is recommended to install Wechaty for you: -```bash -$ npm install --save wechaty +```shell +npm install --save wechaty ``` ## Start from strach @@ -69,6 +70,7 @@ In case that you do not know anything about nodejs, the follow instructions woul ## 1. Install NodeJS NodeJS Version 6.0 & above is required. + 1. Visit [NodeJS](https://nodejs.org) 1. Download NodeJS Installer(i.e. "v6.2.0 Current") 1. Run Installer to install NodeJS to your machine @@ -76,8 +78,7 @@ NodeJS Version 6.0 & above is required. ## 2. Checkout Wechaty Use `git` to checkout Wechaty source code from [Github.com](https://github.com) ```shell -git clone git@github.com:zixia/wechaty.git -# or use https: git clone https://github.com/zixia/wechaty.git +git clone https://github.com/zixia/wechaty.git ``` ## 3. Install Dependents @@ -89,8 +90,8 @@ npm install ## 4. Run Demo Bot ```shell npm start -# this will run: node example/ding-dong-bot.js ``` +This will run `node example/ding-dong-bot.js` # Trouble Shooting If wechaty is not run as expected, run unit test maybe help to find some useful message. @@ -100,7 +101,7 @@ npm test # Requirement -ECMAScript2015/ES6. I develop and test wechaty under nodejs6.0. +ECMAScript2015(ES6). I develop and test wechaty with Node.js v6.0. # API Refference @@ -278,8 +279,14 @@ Github Issue - https://github.com/zixia/wechaty/issues * Create an issue, fork, then send a pull request(with unit test please). # See Also -* [wxBot](https://github.com/liuwons/wxBot): Wechat Bot API in Python -* [ItChat](https://github.com/littlecodersh/ItChat): Command line talks through Wechat in Python + +## Javascript +1. [Weixinbot](https://github.com/feit/Weixinbot) Nodejs 封装网页版微信的接口,可编程控制微信消息 + +## Python +1. [WeixinBot](https://github.com/Urinx/WeixinBot) *Very well documented* 网页版微信API,包含终端版微信及微信机器人 +1. [wxBot](https://github.com/liuwons/wxBot): Wechat Bot API +1. [ItChat](https://github.com/littlecodersh/ItChat): 微信个人号接口(支持文件、图片上下载)、微信机器人及命令行微信。三十行即可自定义个人号机器人 Author ----------------- diff --git a/example/ding-dong-bot.js b/example/ding-dong-bot.js index 122045531b73db6a8af46bd7e3ff148622d69153..3c041bfbb4ff400d88fb21dcdc3d2b7c3e284cee 100644 --- a/example/ding-dong-bot.js +++ b/example/ding-dong-bot.js @@ -1,8 +1,9 @@ -const Wechaty = require('../src/wechaty') const log = require('npmlog') //log.level = 'verbose' log.level = 'silly' +const Wechaty = require('../src/wechaty') + const welcome = ` | __ __ _ _ | \\ \\ / /__ ___| |__ __ _| |_ _ _ @@ -30,7 +31,8 @@ console.log(welcome) const bot = new Wechaty({head: true}) bot.init() -.then(login) +.then(bot.getLoginQrImgUrl.bind(bot)) +.then(url => console.log(`Scan qrcode in url to login: \n${url}`)) .catch(e => { log.error('Bot', 'init() fail:' + e) bot.quit() @@ -39,10 +41,10 @@ bot.init() bot.on('message', m => { m.ready() - .then(msg => { + .then(msg => { log.info('Bot', 'recv: %s' , msg) }) - .catch(e => log.error('Bot', 'ready: %s' , e)) + .catch(e => log.error('Bot', 'ready: %s' , e)) if (/^(ding|ping|bing)$/i.test(m.get('content'))) { const r = new Wechaty.Message() @@ -53,15 +55,6 @@ bot.on('message', m => { } }) -function login() { - log.info('Bot', 'Welcome to Wechaty') - - bot.puppet - .getLoginQrImgUrl() - .then(url => - console.log(`\n\nAction needed. Scan the belowing QRCode to login:\n\n${url}\n\nTip: You can copy/paste it to a web browser.\n`) - ).catch(e => log.error('Bot', 'promise rejected')) -} +bot.on('login' , () => npm.info('Bot', 'logined')) +bot.on('logout' , () => npm.info('Bot', 'logouted')) -bot.on('login' , e => log.info('Bot', 'logined:' + JSON.stringify(e))) -bot.on('logout' , e => log.info('Bot', 'logouted:' + e)) diff --git a/example/roger-bot.js b/example/roger-bot.js index ce7dceae54b960a3b4a738b6bfbbdcdeaf7ef0fa..6a0a4b5998db0c88bd7de7b57885ab908328538a 100644 --- a/example/roger-bot.js +++ b/example/roger-bot.js @@ -1,5 +1,5 @@ -const Wechaty = require('../src/wechaty') -const bot = new Wechaty() +const log = require('npmlog') +const bot = new Wechaty({head: true}) bot.init() .then(bot.getLoginQrImgUrl.bind(bot)) diff --git a/example/wit-ai-bot.js b/example/wit-ai-bot.js new file mode 100644 index 0000000000000000000000000000000000000000..e99cae2fcf6c6252f2eeea98628a07d608bee691 --- /dev/null +++ b/example/wit-ai-bot.js @@ -0,0 +1,5 @@ +/* +To be writen + +https://wit.ai/ +*/ diff --git a/src/puppet-web.js b/src/puppet-web.js index 19206b77241fbe4ec0708d7111c9796b4cea2502..1309a7d4ba4ebbf6ba03787ae27e6481c0086842 100644 --- a/src/puppet-web.js +++ b/src/puppet-web.js @@ -146,7 +146,10 @@ class PuppetWeb extends Puppet { * Public Methods * */ - getLoginQrImgUrl() { return this.proxyWechaty('getLoginQrImgUrl') } + getLoginQrImgUrl() { + log.silly('PuppetWeb', 'getLoginQrImgUrl()') + return this.proxyWechaty('getLoginQrImgUrl') + } getLoginStatusCode() { return this.proxyWechaty('getLoginStatusCode') } getContact(id) { return this.proxyWechaty('getContact', id) } isLogined() { return !!(this.logined) } diff --git a/test/webdriver-spec.js b/test/webdriver-spec.js index 690206646a30efa608103775c7944ecdfe7c6b1f..c87a0f72b9ffd7b3f756a0df99bffe97ab65a27a 100644 --- a/test/webdriver-spec.js +++ b/test/webdriver-spec.js @@ -1,4 +1,5 @@ const path = require('path') +const co = require('co') const test = require('tape') const log = require('npmlog') //log.level = 'silly' @@ -14,31 +15,28 @@ test('WebDriver smoke testing', function(t) { const wb = new PuppetWebBrowser({port: PORT}) const driver = wb.getDriver() - const injectio = PuppetWebBrowser.getInjectio() - - driver.get('https://wx.qq.com/') - .then(() => { - Promise.all([ - execute('return 1+1') // ret_add - , execute(injectio, 8788) // ret_inject - ]).then(([ - retAdd - , retInject - ]) => { - t.equal(retAdd , 2 , 'execute js in browser') - t.equal(retInject, 'Wechaty' , 'injected wechaty') - - t.end() - driver.quit() - }).catch(e => { - t.ok(false, 'promise rejected. e:' + e) - t.end() - driver.quit() - })/* .finally(() => { - console.log('final') - }) - */ + co(function* () { + const injectio = PuppetWebBrowser.getInjectio() + yield driver.get('https://wx.qq.com/') + + const retAdd = yield execute('return 1+1') + t.equal(retAdd, 2, 'execute js in browser') + + const retInject = yield execute(injectio, 8788) + t.equal(retInject, 'Wechaty', 'injected wechaty') + + }) + .catch(e => { // REJECTED + t.ok(false, 'promise rejected. e:' + e) }) + .then(() => { // FINALLY + t.end() + driver.quit() + }) + + return + + ////////////////////////////////// function execute() { return driver.executeScript.apply(driver, arguments)