提交 54770643 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

merge

...@@ -8,6 +8,7 @@ Wechaty is a Bot-Enable Framework/Library for Personal Account of Wechat. ...@@ -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) [![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/) [![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) [![npm version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty)
[![Downloads][downloads-image]][downloads-url] [![Downloads][downloads-image]][downloads-url]
...@@ -60,8 +61,8 @@ Plan to glue with Machine Learning/Deep Learning/Neural Network/Natural Language ...@@ -60,8 +61,8 @@ Plan to glue with Machine Learning/Deep Learning/Neural Network/Natural Language
# Installation # Installation
Use NPM is recommended to install Wechaty for you: Use NPM is recommended to install Wechaty for you:
```bash ```shell
$ npm install --save wechaty npm install --save wechaty
``` ```
## Start from strach ## Start from strach
...@@ -69,6 +70,7 @@ In case that you do not know anything about nodejs, the follow instructions woul ...@@ -69,6 +70,7 @@ In case that you do not know anything about nodejs, the follow instructions woul
## 1. Install NodeJS ## 1. Install NodeJS
NodeJS Version 6.0 & above is required. NodeJS Version 6.0 & above is required.
1. Visit [NodeJS](https://nodejs.org) 1. Visit [NodeJS](https://nodejs.org)
1. Download NodeJS Installer(i.e. "v6.2.0 Current") 1. Download NodeJS Installer(i.e. "v6.2.0 Current")
1. Run Installer to install NodeJS to your machine 1. Run Installer to install NodeJS to your machine
...@@ -76,8 +78,7 @@ NodeJS Version 6.0 & above is required. ...@@ -76,8 +78,7 @@ NodeJS Version 6.0 & above is required.
## 2. Checkout Wechaty ## 2. Checkout Wechaty
Use `git` to checkout Wechaty source code from [Github.com](https://github.com) Use `git` to checkout Wechaty source code from [Github.com](https://github.com)
```shell ```shell
git clone git@github.com:zixia/wechaty.git git clone https://github.com/zixia/wechaty.git
# or use https: git clone https://github.com/zixia/wechaty.git
``` ```
## 3. Install Dependents ## 3. Install Dependents
...@@ -89,8 +90,8 @@ npm install ...@@ -89,8 +90,8 @@ npm install
## 4. Run Demo Bot ## 4. Run Demo Bot
```shell ```shell
npm start npm start
# this will run: node example/ding-dong-bot.js
``` ```
This will run `node example/ding-dong-bot.js`
# Trouble Shooting # Trouble Shooting
If wechaty is not run as expected, run unit test maybe help to find some useful message. If wechaty is not run as expected, run unit test maybe help to find some useful message.
...@@ -100,7 +101,7 @@ npm test ...@@ -100,7 +101,7 @@ npm test
# Requirement # 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 # API Refference
...@@ -278,8 +279,14 @@ Github Issue - https://github.com/zixia/wechaty/issues ...@@ -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). * Create an issue, fork, then send a pull request(with unit test please).
# See Also # 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 Author
----------------- -----------------
......
const Wechaty = require('../src/wechaty')
const log = require('npmlog') const log = require('npmlog')
//log.level = 'verbose' //log.level = 'verbose'
log.level = 'silly' log.level = 'silly'
const Wechaty = require('../src/wechaty')
const welcome = ` const welcome = `
| __ __ _ _ | __ __ _ _
| \\ \\ / /__ ___| |__ __ _| |_ _ _ | \\ \\ / /__ ___| |__ __ _| |_ _ _
...@@ -30,7 +31,8 @@ console.log(welcome) ...@@ -30,7 +31,8 @@ console.log(welcome)
const bot = new Wechaty({head: true}) const bot = new Wechaty({head: true})
bot.init() bot.init()
.then(login) .then(bot.getLoginQrImgUrl.bind(bot))
.then(url => console.log(`Scan qrcode in url to login: \n${url}`))
.catch(e => { .catch(e => {
log.error('Bot', 'init() fail:' + e) log.error('Bot', 'init() fail:' + e)
bot.quit() bot.quit()
...@@ -39,10 +41,10 @@ bot.init() ...@@ -39,10 +41,10 @@ bot.init()
bot.on('message', m => { bot.on('message', m => {
m.ready() m.ready()
.then(msg => { .then(msg => {
log.info('Bot', 'recv: %s' , 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'))) { if (/^(ding|ping|bing)$/i.test(m.get('content'))) {
const r = new Wechaty.Message() const r = new Wechaty.Message()
...@@ -53,15 +55,6 @@ bot.on('message', m => { ...@@ -53,15 +55,6 @@ bot.on('message', m => {
} }
}) })
function login() { bot.on('login' , () => npm.info('Bot', 'logined'))
log.info('Bot', 'Welcome to Wechaty') bot.on('logout' , () => npm.info('Bot', 'logouted'))
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' , e => log.info('Bot', 'logined:' + JSON.stringify(e)))
bot.on('logout' , e => log.info('Bot', 'logouted:' + e))
const Wechaty = require('../src/wechaty') const log = require('npmlog')
const bot = new Wechaty() const bot = new Wechaty({head: true})
bot.init() bot.init()
.then(bot.getLoginQrImgUrl.bind(bot)) .then(bot.getLoginQrImgUrl.bind(bot))
......
/*
To be writen
https://wit.ai/
*/
...@@ -146,7 +146,10 @@ class PuppetWeb extends Puppet { ...@@ -146,7 +146,10 @@ class PuppetWeb extends Puppet {
* Public Methods * Public Methods
* *
*/ */
getLoginQrImgUrl() { return this.proxyWechaty('getLoginQrImgUrl') } getLoginQrImgUrl() {
log.silly('PuppetWeb', 'getLoginQrImgUrl()')
return this.proxyWechaty('getLoginQrImgUrl')
}
getLoginStatusCode() { return this.proxyWechaty('getLoginStatusCode') } getLoginStatusCode() { return this.proxyWechaty('getLoginStatusCode') }
getContact(id) { return this.proxyWechaty('getContact', id) } getContact(id) { return this.proxyWechaty('getContact', id) }
isLogined() { return !!(this.logined) } isLogined() { return !!(this.logined) }
......
const path = require('path') const path = require('path')
const co = require('co')
const test = require('tape') const test = require('tape')
const log = require('npmlog') const log = require('npmlog')
//log.level = 'silly' //log.level = 'silly'
...@@ -14,31 +15,28 @@ test('WebDriver smoke testing', function(t) { ...@@ -14,31 +15,28 @@ test('WebDriver smoke testing', function(t) {
const wb = new PuppetWebBrowser({port: PORT}) const wb = new PuppetWebBrowser({port: PORT})
const driver = wb.getDriver() const driver = wb.getDriver()
const injectio = PuppetWebBrowser.getInjectio() co(function* () {
const injectio = PuppetWebBrowser.getInjectio()
driver.get('https://wx.qq.com/') yield driver.get('https://wx.qq.com/')
.then(() => {
Promise.all([ const retAdd = yield execute('return 1+1')
execute('return 1+1') // ret_add t.equal(retAdd, 2, 'execute js in browser')
, execute(injectio, 8788) // ret_inject
]).then(([ const retInject = yield execute(injectio, 8788)
retAdd t.equal(retInject, 'Wechaty', 'injected wechaty')
, retInject
]) => { })
t.equal(retAdd , 2 , 'execute js in browser') .catch(e => { // REJECTED
t.equal(retInject, 'Wechaty' , 'injected wechaty') t.ok(false, 'promise rejected. e:' + e)
t.end()
driver.quit()
}).catch(e => {
t.ok(false, 'promise rejected. e:' + e)
t.end()
driver.quit()
})/* .finally(() => {
console.log('final')
})
*/
}) })
.then(() => { // FINALLY
t.end()
driver.quit()
})
return
//////////////////////////////////
function execute() { function execute() {
return driver.executeScript.apply(driver, arguments) return driver.executeScript.apply(driver, arguments)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册