README.md 9.6 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
[![Wechaty](https://raw.githubusercontent.com/wechaty/wechaty/master/image/wechaty-logo-en.png)](https://github.com/wechaty/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2 3 4 5

# Wechaty [![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=wechaty/wechaty)](https://github.com/wechaty/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
7
## Connecting ChatBots.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
8

9
Wechaty is a Bot Framework for Wechat **Personal** Account that helps you easy creating bot in 6 lines of javascript, with cross-platform support include [Linux](https://travis-ci.org/wechaty/wechaty), [Win32](https://ci.appveyor.com/project/zixia/wechaty), [Darwin(OSX/Mac)](https://travis-ci.org/wechaty/wechaty) and [Docker](https://circleci.com/gh/wechaty/wechaty).
10

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
11 12 13
:octocat: <https://github.com/wechaty/wechaty>  
:beetle: <https://github.com/wechaty/wechaty/issues>  
:book: <https://github.com/wechaty/wechaty/wiki>  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
14
:whale: <https://hub.docker.com/r/zixia/wechaty>  
15 16

## Voice of the Developer
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
17

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
18 19 20 21 22 23 24 25 26 27 28
> @JasLin: it may be the best wechat SDK I have seen in Github! [link](https://github.com/wechaty/wechaty/issues/8#issuecomment-228971491)

> @ccaapton: wechaty library fantastic! [link](https://github.com/wechaty/wechaty/issues/9)

> @ak5: Thanks for this it's quite cool! [link](https://github.com/wechaty/wechaty/issues/4)

> @Samurais: wechaty is great.  [link](https://github.com/wechaty/wechaty/issues/36#issuecomment-251708382)

> @Jarvis: 目前用过的最好的微信开发库 [link](http://weibo.com/3296245513/Ec4iNp9Ld?type=comment)

> @naishstar: thanks for great SDK [link](https://github.com/wechaty/wechaty/issues/57)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
29

30
# Example
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
31

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
32
Your first Wechaty Bot with only 6 lines JavaScript:
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
33

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
34
```javascript
35
const Wechaty = require('wechaty')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
36

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
37
Wechaty.instance() // Singleton
38 39 40
.on('scan', (url, code) => console.log(`Scan QrCode to login: ${code}\n${url}`))
.on('login',       user => console.log(`User ${user} logined`))
.on('message',  message => console.log(`Message: ${message}`))
41
.init()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
42 43
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
44
This bot can log all message to console. Source code(TypeScript version) at [here](https://github.com/wechaty/wechaty/blob/master/example/roger-bot.ts).
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
45

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
46
You can find more example from [Wiki](https://github.com/wechaty/wechaty/wiki/Example) and [Example Directory](https://github.com/wechaty/wechaty/blob/master/example/).
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
47

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
48
# Run [![Docker Pulls](https://img.shields.io/docker/pulls/zixia/wechaty.svg?maxAge=2592000)](https://hub.docker.com/r/zixia/wechaty/) [![Docker Stars](https://img.shields.io/docker/stars/zixia/wechaty.svg?maxAge=2592000)](https://hub.docker.com/r/zixia/wechaty/) [![Docker Layers](https://images.microbadger.com/badges/image/zixia/wechaty.svg)](https://microbadger.com/#/images/zixia/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
49

50
Run the above example bot code(`mybot.js` in this example):
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
51

52
```shell
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
53 54 55 56 57 58 59
$ alias wechaty='docker run \
    -t -i --rm \
    --volume="$(pwd)":/bot \
    --name=wechaty \
    zixia/wechaty \
'

60
$ wechaty mybot.js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
61 62
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
63
Know more about Docker for Wechaty at [here](https://github.com/wechaty/wechaty/wiki/Docker).
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
64

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
65
# NPM [![NPM Version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty) [![Downloads][downloads-image]][downloads-url]
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
66

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
67
Install Wechaty by NPM:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
68

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
69 70
```shell
npm install --save wechaty
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
71 72 73 74
```

# Requirement

75 76 77 78
1. Javascript ES6(ECMAScript2015)
1. Node.js v6+
1. Docker(optional)
1. TypeScript(optional)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
79

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
80
# API Reference
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
81

82
## [Wechaty](https://github.com/wechaty/wechaty/wiki/API#class-wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
83

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
84 85 86 87
1. [init(): Promise&lt;void&gt;](https://github.com/wechaty/wechaty/wiki/API#wechaty-init-promise-void)
1. [instance(setting: PuppetSetting): Promise&lt;Wechaty&gt;](https://github.com/wechaty/wechaty/wiki/API#wechaty-instance-setting-puppetsetting-promise-wechaty)
1. [send(message: Message): Promise&lt;void&gt;](https://github.com/wechaty/wechaty/wiki/API#wechaty-send-message-message-promise-void)
1. [say(content: string): Promise&lt;void&gt;](https://github.com/wechaty/wechaty/wiki/API#wechaty-say-content-string-promise-void)
88

89
### [Wechaty Event](https://github.com/wechaty/wechaty/wiki/API#wechaty-event)
90

91 92 93 94 95 96 97 98 99
1. [error](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-error)
1. [friend](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-friend)
1. [login](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-login)
1. [logout](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-logout)
1. [message](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-message)
1. [room-join](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-room-join)
1. [room-leave](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-room-leave)
1. [room-topic](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-room-topic)
1. [scan](https://github.com/wechaty/wechaty/wiki/API#wechaty-event-scan)
100

101
## [Contact](https://github.com/wechaty/wechaty/wiki/API#class-contact)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
102

103
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
104

105
## [FriendRequest](https://github.com/wechaty/wechaty/wiki/API#class-friendrequest)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
106

107
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
108

109
## [Message](https://github.com/wechaty/wechaty/wiki/API#class-message)
110

111
TBW
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
112

113
## [Room](https://github.com/wechaty/wechaty/wiki/API#class-room)
Huan (李卓桓)'s avatar
doc #44  
Huan (李卓桓) 已提交
114

115
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
116

117
### [Room Event](https://github.com/wechaty/wechaty/wiki/API#room-event)
118

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
119

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
120 121 122
# Test [![Linux/Mac Build Status](https://img.shields.io/travis/wechaty/wechaty.svg?label=Linux/Mac)](https://travis-ci.org/wechaty/wechaty) [![Win32 Build status](https://img.shields.io/appveyor/ci/zixia/wechaty/master.svg?label=Windows)](https://ci.appveyor.com/project/zixia/wechaty) [![Docker CircleCI](https://img.shields.io/circleci/project/github/wechaty/wechaty.svg?label=Docker)](https://circleci.com/gh/wechaty/wechaty)

[![Coverage Status](https://coveralls.io/repos/github/wechaty/wechaty/badge.svg?branch=master)](https://coveralls.io/github/wechaty/wechaty?branch=master) [![Code Climate](https://codeclimate.com/github/wechaty/wechaty/badges/gpa.svg)](https://codeclimate.com/github/wechaty/wechaty) [![Issue Count](https://codeclimate.com/github/wechaty/wechaty/badges/issue_count.svg)](https://codeclimate.com/github/wechaty/wechaty) [![Test Coverage](https://codeclimate.com/github/wechaty/wechaty/badges/coverage.svg)](https://codeclimate.com/github/wechaty/wechaty/coverage)
123

Huan (李卓桓)'s avatar
doc ava  
Huan (李卓桓) 已提交
124
Wechaty use ~~[TAP protocol](http://testanything.org/)~~ [AVA](https://github.com/avajs/ava) to test itself ~~by [tap](http://www.node-tap.org/)~~.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
125

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
126
To test Wechaty, run:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
127 128
```shell
npm test
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
129 130
```

131 132 133 134 135 136 137 138
To test with full log messages

```shell
$ WECHATY_LOG=silly npm test
```

See more about:
* [Details about unit testing](https://github.com/wechaty/wechaty/tree/master/test)
Huan (李卓桓)'s avatar
doc ava  
Huan (李卓桓) 已提交
139
* Know more about TAP: [Why I use Tape Instead of Mocha & So Should You](https://medium.com/javascript-scene/why-i-use-tape-instead-of-mocha-so-should-you-6aa105d8eaf4)
140 141
* [Log](https://github.com/wechaty/wechaty/wiki/Log)
* [Debug](https://github.com/wechaty/wechaty/wiki/Debug)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
142

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
143
# Release Notes
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
144

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
145
[Latest Release](https://github.com/wechaty/wechaty/releases/latest)(All releases [here](https://github.com/wechaty/wechaty/releases))
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
146

147
[CHANGELOG](https://github.com/wechaty/wechaty/blob/master/CHANGELOG)
Huan (李卓桓)'s avatar
readme  
Huan (李卓桓) 已提交
148

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
149
# Todo List
150

Huan (李卓桓)'s avatar
todo  
Huan (李卓桓) 已提交
151
- [ ] Events
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
152
    - [ ] Use EventEmitter2 to emit message events so that we can use wildcard
153 154 155 156 157 158 159 160
        1. `message`
        2. `message.recv`
        3. `message.sent`
        4. `message.recv.image`
        5. `message.sent.image`
        6. `message.recv.sys`
        1. `message.**.image`
        1. `message.recv.*`
Huan (李卓桓)'s avatar
todo  
Huan (李卓桓) 已提交
161
- [ ] Message
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
162 163 164
    - [ ] Send/Reply image/video/attachment message
    - [ ] Save video message to file
    - [x] Save image message to file
165

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
# Badge [![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-green.svg)](https://github.com/wechaty/wechaty)

Here's how to show the Wechaty Badge on your page: in case you are interested, or you'd like to support Wechaty by show the badge. Appreciate!

## Markdown

```markdown
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-green.svg)](https://github.com/wechaty/wechaty)
```

## Html

```html
<a href="https://github.com/wechaty/wechaty" target="_blank">
  <img src="https://img.shields.io/badge/Powered%20By-Wechaty-green.svg" alt="Powered by Wechaty" border="0">
</a>
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
184
# Contributing
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
185

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
186
Welcome to be a Wechaty Contributer: [CONTRIBUTING](https://github.com/wechaty/wechaty/blob/master/CONTRIBUTING.md)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
187

188
# See Also
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
189

190
* [RelatedProject](https://github.com/wechaty/wechaty/wiki/RelatedProject)
191

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
192
My Story
193 194
----------------
My daily life/work depends on too much chat on wechat.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
195
* I almost have 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
196 197 198 199
* I almost have 400 wechat rooms that most of them have more than 400 members.

Can you image that? I'm dying...

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
200
So a tireless bot working for me 24x7 on wechat, monitoring/filtering the most important message is badly needed. For example highlights discussion which contains the KEYWORDS which I want to follow up(especially in a noisy room). ;-)
201 202 203

At last, It's built for my personal study purpose of Automatically Testing.

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
204 205 206 207 208
Author
-----------------
Zhuohuan LI <zixia@zixia.net> (http://linkedin.com/in/zixia)

<a href="http://stackoverflow.com/users/1123955/zixia">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
209
  <img src="http://stackoverflow.com/users/flair/1123955.png" width="208" height="58" alt="profile for zixia at Stack Overflow, Q&amp;A for professional and enthusiast programmers" title="profile for zixia at Stack Overflow, Q&amp;A for professional and enthusiast programmers">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
210 211 212 213 214 215 216
</a>

Copyright & License
-------------------
* Code & Docs 2016© zixia
* Code released under the ISC license
* Docs released under Creative Commons
217

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
218
[downloads-image]: http://img.shields.io/npm/dm/wechaty.svg?style=flat-square
219
[downloads-url]: https://npmjs.org/package/wechaty