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

add howto install wechaty instruction

上级 9dc5f4f0
......@@ -58,12 +58,46 @@ To Be Written.
Plan to glue with Machine Learning/Deep Learning/Neural Network/Natural Language Processing.
# Installation
The recommended installation method is a local NPM install for your project:
# Installation & Usage
Use NPM is recommended to install Wechaty for you:
```bash
$ npm install --save wechaty
```
## Start from strach
In case that you do not know anything about nodejs, the follow instructions would help you to run Wechaty bot on your machine.
## 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
## 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
# git clone https://github.com/zixia/wechaty.git
```
## 3. Install Dependents
```shell
cd wechaty
npm install
```
## 4. Run Demo Bot
```shell
npm start
# 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.
```shell
npm test
```
# Requirement
ECMAScript2015/ES6. I develop and test wechaty under nodejs6.0.
......@@ -112,7 +146,7 @@ To-Be-Supported
All messages will be encaped in Message.
### Message.ready()
A message may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
A message may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
......@@ -123,7 +157,7 @@ message.ready()
})
```
### Message.get(prop)
Get prop from a message.
Get prop from a message.
Supported prop list:
......@@ -149,7 +183,7 @@ message.set('content', 'Hello, World!')
## Class Contact
### Contact.ready()
A Contact may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
A Contact may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
......@@ -160,7 +194,7 @@ contact.ready()
})
```
### Contact.get(prop)
Get prop from a contact.
Get prop from a contact.
Supported prop list:
......@@ -180,7 +214,7 @@ contact.get('name')
## Class Group
### Group.ready()
A group may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
A group may be not fully initialized yet. Call `ready()` to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
......@@ -192,7 +226,7 @@ group.ready()
```
### Group.get(prop)
Get prop from a group.
Get prop from a group.
Supported prop list:
......@@ -219,7 +253,7 @@ Know more about tape: [Why I use Tape Instead of Mocha & So Should You](https://
# Version History
## v0.0.5 (2016/5/11)
1. Receive & send message
1. Receive & send message
1. Show contacts info
1. Show groups info
1. 1st usable version
......
/**
*
* Wechaty bot use a Tuling123.com brain
*
* Apply your own tuling123.com API_KEY
* at: http://www.tuling123.com/html/doc/api.html
*
* Enjoy!
*
* Wechaty - https://github.com/zixia/wechaty
*
*/
const log = require('npmlog')
const co = require('co')
const Tuling123 = require('tuling123-client')
const Wechaty = require('../src/wechaty')
//log.level = 'verbose'
log.level = 'silly'
const TULING123_API_KEY = '18f25157e0446df58ade098479f74b21'
const brain = new Tuling123(TULING123_API_KEY)
const bot = new Wechaty({head: true})
console.log(`
Welcome to Tuling Wechaty Bot.
Tuling API: http://www.tuling123.com/html/doc/api.html
Loading...
`)
bot.init()
.then(bot.getLoginQrImgUrl.bind(bot))
.then(url => console.log(`Scan to login:\n${url}`))
.catch(e => {
log.error('Bot', 'init() fail:' + e)
bot.quit()
process.exit(-1)
})
bot.on('message', m => {
co(function* () {
const msg = yield m.ready()
log.info('Bot', 'recv: %s' , msg)
if (!m.inGroup()) {
const r = new Wechaty.Message()
.set('to', m.get('from'))
const answer = brain.ask(m.get('content'))
r.set('content', answer)
yield bot.send(r)
log.info('Bot', `REPLY: ${answer}`)
}
})
.catch(e => log.error('Bot', 'on message rejected: %s' , e))
})
bot.on('login' , e => log.info('Bot', 'bot login.'))
bot.on('logout' , e => log.info('Bot', 'bot logout.'))
......@@ -33,12 +33,13 @@
"homepage": "https://github.com/zixia/wechaty#readme",
"dependencies": {
"body-parser": "^1.15.0",
"socket.io": "^1.4.5",
"chromedriver": "^2.21.2",
"co": "^4.6.0",
"express": "^4.13.4",
"selenium-webdriver": "",
"npmlog": "^2.0.3",
"phantomjs-prebuilt": "^2.1.7",
"chromedriver": "^2.21.2",
"npmlog": "^2.0.3"
"selenium-webdriver": "",
"socket.io": "^1.4.5"
},
"eslintConfig": {
"env": {
......@@ -51,8 +52,8 @@
"node": ">= 6.0.0"
},
"devDependencies": {
"co": "^4.6.0",
"eslint": "^2.9.0",
"tape": "^4.5.1"
"tape": "^4.5.1",
"tuling123-client": "0.0.1"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册