README.md 8.8 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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
3
# 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 (李卓桓) 已提交
4

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

7
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).
8

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
16 17 18 19 20 21 22 23 24 25 26
> @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 (李卓桓) 已提交
27

28
# Example
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
29

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
30
The shortest wechat bot code in the world: 6 lines JavaScript
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
31

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
32
```javascript
33
const { Wechaty } = require('wechaty')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
34

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
42
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 (李卓桓) 已提交
43

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
44
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 (李卓桓) 已提交
45

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
46
# 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 (李卓桓) 已提交
47

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

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

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
61
Get to know more about Wechaty Docker from [here](https://github.com/wechaty/wechaty/wiki/Docker).
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
62

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
63
# 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 (李卓桓) 已提交
64

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

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

# Requirement

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
78
# API Reference
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
79

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
82 83 84 85
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)
86

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

89 90 91 92 93 94 95 96 97
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)
98

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

101
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
102

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

105
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
106

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

109
TBW
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
110

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

113
TBW
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
114

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
118
# 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)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
119

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
120
Wechaty use [AVA](https://github.com/avajs/ava) for unit testing
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
121

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
122
To test Wechaty, run:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
123 124
```shell
npm test
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
125 126
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
127
Get to know more about test from [here](https://github.com/wechaty/wechaty/wiki/Test)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
128

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
129
# Release Notes
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
130

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
135
# Todo List
136

Huan (李卓桓)'s avatar
todo  
Huan (李卓桓) 已提交
137
- [ ] Events
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
138
    - [ ] Use EventEmitter2 to emit message events so that we can use wildcard
139 140 141 142 143 144 145 146
        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 (李卓桓) 已提交
147
- [ ] Message
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
148 149 150
    - [ ] Send/Reply image/video/attachment message
    - [ ] Save video message to file
    - [x] Save image message to file
151

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
# 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 (李卓桓) 已提交
170
# Contributing
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
171

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

174
# See Also
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
175

176
* [RelatedProject](https://github.com/wechaty/wechaty/wiki/RelatedProject)
177

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
178
My Story
179 180
----------------
My daily life/work depends on too much chat on wechat.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
181
* I almost have 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
182 183 184 185
* 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 (李卓桓) 已提交
186
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). ;-)
187 188 189

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
190 191 192 193 194
Author
-----------------
Zhuohuan LI <zixia@zixia.net> (http://linkedin.com/in/zixia)

<a href="http://stackoverflow.com/users/1123955/zixia">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
195
  <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 (李卓桓) 已提交
196 197 198 199 200 201 202
</a>

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

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