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

merge

......@@ -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
-----------------
......
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))
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))
......
/*
To be writen
https://wit.ai/
*/
......@@ -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) }
......
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册