README.md 12.1 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
# WECHATY
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
3 4
[![Wechaty](https://chatie.io/wechaty/images/wechaty-logo-en.png)](https://github.com/chatie/wechaty)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5
## CONNECTING CHATBOTS
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6

7
Wechaty is a Bot SDK for Wechat **Personal** Account which can help you create a bot in 6 lines of javascript, with cross-platform support include [Linux](https://travis-ci.com/chatie/wechaty), [Windows](https://ci.appveyor.com/project/chatie/wechaty), [Darwin(OSX/Mac)](https://travis-ci.com/chatie/wechaty) and [Docker](https://app.shippable.com/github/Chatie/wechaty).
8

9 10
[![NPM Version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty)
[![Docker Pulls](https://img.shields.io/docker/pulls/zixia/wechaty.svg?maxAge=2592000)](https://hub.docker.com/r/zixia/wechaty/)
11
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](https://www.typescriptlang.org/)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
12

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
18
## VOICE OF THE DEVELOPER
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
19

20
> "Wechaty is a great solution, I believe there would be much more users recognize it." [link](https://github.com/chatie/wechaty/pull/310#issuecomment-285574472)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21
> -- @Gcaufy, Tencent Engineer, Author of [WePY](https://github.com/Tencent/wepy)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
22

23
> "太好用,好用的想哭"  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
24
> -- @xinbenlv, Google Engineer, Founder of HaoShiYou.org
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
25

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
26
> "最好的微信开发库" [link](http://weibo.com/3296245513/Ec4iNp9Ld?type=comment)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
27
> -- @Jarvis, Baidu Engineer
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
28

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
29
> "Wechaty让运营人员更多的时间思考如何进行活动策划、留存用户,商业变现" [link](http://mp.weixin.qq.com/s/dWHAj8XtiKG-1fIS5Og79g)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
30
> -- @lijiarui, CEO of BotOrange.
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
31

32
> "If you know js ... try Chatie/wechaty, it's easy to use."  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
33
> -- @Urinx Uri Lee, Author of [WeixinBot(Python)](https://github.com/Urinx/WeixinBot)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
34

35
See more at [Wiki:VoiceOfDeveloper](https://github.com/Chatie/wechaty/wiki/VoiceOfDeveloper)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
36

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
37
## The World's Shortest ChatBot Code: 6 lines of JavaScript
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
38

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
39
```javascript
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
40

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
41
const { Wechaty } = require('wechaty') // import { Wechaty } from 'wechaty'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
42

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
43 44 45 46
Wechaty.instance() // Global Instance
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\n${qrcode}`))
.on('login',            user => console.log(`User ${user} logined`))
.on('message',       message => console.log(`Message: ${message}`))
47
.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
48
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
49

50
> **Notice: Wechaty requires Node.js version >= 8.5**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
51

52
This bot can log all messages to the console.
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
53

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
56
## GETTING STARTED
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
57

58 59 60
[![node](https://img.shields.io/node/v/wechaty.svg?maxAge=604800)](https://nodejs.org/)
[![Repo Size](https://reposs.herokuapp.com/?path=Chatie/wechaty)](https://github.com/chatie/wechaty)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
61
### A Great Live Coding Tutorial
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
62 63

<div align="center">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
64
<a target="_blank" href="https://blog.chatie.io/guide/2017/01/01/getting-started-wechaty.html"><img src="http://blog.chatie.io/download/2017/lijiarui-wechaty-quick-start-guide-video.jpg" border=0 width="60%"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
65 66
</div>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
67
The above 15 minute video tutorial is a good start point if you are new to Wechaty.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
68

69
> Source code in the video can be found at: [Wechaty Starter Repository](https://github.com/lijiarui/wechaty-getting-started)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
70

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
71
### Run
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
72

73
Let's say, you have saved the above six line javascript example to `mybot.js`.
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
74 75 76 77 78

We have two options to run wechaty:

1. Docker
1. NPM
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
79

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
80
Notice: The published versions have always passed the CI tests. We highly recommend running wechaty with the versions installed by docker or npm instead of the latest master branch unless you are prepared to deal with the broken code problems.
李文成 已提交
81

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
82
#### Docker
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
83

84 85 86
[![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 (李卓桓) 已提交
87

88
The **best practice** to use Wechaty is running with docker, because it's not only the most easy way to get started, but also protects you from the troubles of dependency problems. 
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
89

90 91 92 93 94 95
> Wechaty Docker supports both JavaScript and TypeScript. To use TypeScript just write in TypeScript and save with extension name `.ts`.

Get to know more about Wechaty Docker at [Wiki:Docker](https://github.com/chatie/wechaty/wiki/Docker).

1. Run JavaScript

96
```shell
97
$ docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.js # for JavaScript
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
98
...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
99 100
```

101
1. Run TypeScript
102

103 104
```shell
$ docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.ts # for TypeScript
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
105
...
106
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
107

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
108
#### NPM
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
109

Huan (李卓桓)'s avatar
merge  
Huan (李卓桓) 已提交
110 111 112
[![NPM Version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty)
[![Downloads][downloads-image]][downloads-url]
[![Greenkeeper badge](https://badges.greenkeeper.io/Chatie/wechaty.svg)](https://greenkeeper.io/)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
113

114
```shell
115
$ npm init
116 117 118 119 120 121 122 123 124 125 126
$ npm install wechaty

$ cat > mybot.js <<'_EOF_'
const { Wechaty } = require('wechaty')
const bot = Wechaty.instance()
console.log(bot.version())
_EOF_

$ node mybot.js
```

127
Get to know more about NPM at [Wiki:NPM](https://github.com/chatie/wechaty/wiki/NPM)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
128

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

131
[![Linux/Mac Build Status](https://travis-ci.com/Chatie/wechaty.svg?branch=master)](https://travis-ci.com/Chatie/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
132 133
[![Windows Build Status](https://img.shields.io/appveyor/ci/chatie/wechaty/master.svg?label=Windows)](https://ci.appveyor.com/project/chatie/wechaty)
[![Docker Build Status](https://img.shields.io/shippable/5aaf8667ec373f17004dcb66.svg?label=Docker&color=brightgreen)](https://app.shippable.com/github/Chatie/wechaty)
134

Huan (李卓桓)'s avatar
merge  
Huan (李卓桓) 已提交
135 136
[![Coverage Status](https://coveralls.io/repos/github/Chatie/wechaty/badge.svg?branch=master)](https://coveralls.io/github/Chatie/wechaty?branch=master)
[![Known Vulnerabilities](https://snyk.io/test/github/chatie/wechaty/badge.svg)](https://snyk.io/test/github/chatie/wechaty)
137

Huan (李卓桓)'s avatar
fix doc  
Huan (李卓桓) 已提交
138
Wechaty is fully automatically tested by unit and integration tests, with Continious Integration & Continious Deliver(CI/CD) support powered by CI like Travis, Shippable and Appveyor.
139

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
140
To test Wechaty, run:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
141

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
142 143 144
```shell
npm test
```
145

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
146
Get to know more about the tests from [Wiki:Tests](https://github.com/chatie/wechaty/wiki/Tests)
147

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
148
## DOCUMATAION
149

150
In order to sync the doc with the lastest code, we are using [jsdoc](http://usejsdoc.org/) to describe the API, and use [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown/wiki) to generate markdown format documents to the [docs](docs/index.md) directory.
151

152
See: [Official API Reference](https://chatie.github.io/wechaty/)
H
HelenYin 已提交
153

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
154
## RELEASE NOTES
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
155

156 157
* [Latest Release](https://github.com/chatie/wechaty/releases/latest)(All releases [here](https://github.com/chatie/wechaty/releases))
* [Changelog](https://github.com/chatie/wechaty/blob/master/CHANGELOG.md)
Huan (李卓桓)'s avatar
readme  
Huan (李卓桓) 已提交
158

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
159
## POWERED BY WECHATY
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
160

161
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-green.svg)](https://github.com/chatie/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
162
[![Donate Wechaty](https://img.shields.io/badge/Donate-Wechaty%20$-green.svg)](https://salt.bountysource.com/checkout/amount?team=chatie)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
163

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
164
### Wechaty Badge
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
165

166
Get embed html/markdown code from [Wiki:PoweredByWechaty](https://github.com/chatie/wechaty/wiki/PoweredByWechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
167

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
168
### Projects Using Wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
169

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
170
1. [一个用CNN深度神剧网络给图片评分的wechaty项目](https://github.com/huyingxi/wechaty_selfie)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
171 172
1. [Relay between Telegram and WeChat](https://github.com/Firaenix/TeleChatRelay)
1. [A chat bot managing the HaoShiYou wechat groups run by volunteers of haoshiyou.org](https://github.com/xinbenlv/haoshiyou-bot)
173
1. [An interactive chat bot to manage a TODO list](https://github.com/coderbunker/candobot)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
174
1. [Forward WeChat messages to telegram](https://github.com/luosheng/Wegram)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
175

176
Learn more about Projects Using Wechaty at [Wiki:PoweredByWechaty](https://github.com/chatie/wechaty/wiki/PoweredByWechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
177

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
178
## FIND A GOOD SERVER
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
179

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
180
The best practice for running Wechaty Docker/NPM is using a VPS(Virtual Private Server) outside of China, which can save you hours of time because `npm install` and `docker pull` will run smoothly without any problem.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
181

182
The following VPS providers are used by the Wechaty team, and they worked perfectly in production. You can use the following link to get one in minutes. Also, doing this can support Wechaty because you are referred by us.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
183 184 185 186 187 188 189

| Location  | Price | Ram     | Payment           | Provider |
| ---       | ---   | ---     | ---               | ---      |
| Singapore | $5    | 512MB   | Paypal            | [DigitalOcean](https://m.do.co/c/01a54778df5c) |
| Japan     | $5    | 1GB     | Paypal            | [Linode](https://www.linode.com/?r=5fd2b713d711746bb5451111df0f2b6d863e9f63) |
| Korea     | $10   | 1GB     | Alipay, Paypal    | [Netdedi](https://www.netdedi.com/?affid=35) |

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
191
## SEE ALSO
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
192 193 194

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
195
## CONTRIBUTING
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
196

Huan (李卓桓)'s avatar
merge  
Huan (李卓桓) 已提交
197 198 199
[![Issue Stats](http://issuestats.com/github/chatie/wechaty/badge/pr)](http://issuestats.com/github/chatie/wechaty)
[![Issue Stats](http://issuestats.com/github/chatie/wechaty/badge/issue)](http://issuestats.com/github/chatie/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)
200

201
Howto [contribute](https://github.com/chatie/wechaty/blob/master/CONTRIBUTING.md)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
202

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
203 204
Contributions in any form are highly encouraged and welcome! Be it new or improved presets, optimized streaming code or just some cleanup. So start forking!

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
205
### Contributors List
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
206

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
207
<https://github.com/Chatie/wechaty/wiki/Contributors>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
208

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
209
### Code Contributions
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
210 211 212 213 214 215 216

If you want to add new features or change the API, please submit an issue first to make sure no one else is already working on the same thing and discuss the implementation and API details with maintainers and users by creating an issue. When everything is settled down, you can submit a pull request.

When fixing bugs, you can directly submit a pull request.

Make sure to add tests for your features and bugfixes and update the documentation (see below) before submitting your code!

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
217
### Documentation Contributions
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
218 219 220

You can directly submit pull requests for documentation changes.

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
221
### Join Us
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
222

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
223
Wechaty is used in many ChatBot projects by hundreds of developers. If you want to talk with other developers, just scan the following QR Code in WeChat with secret code _wechaty_, join our **Wechaty Developers' Home**.
ruiruibupt's avatar
ruiruibupt 已提交
224

225
![Wechaty Developers' Home](https://chatie.io/wechaty/images/bot-qr-code.png)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
226

227
Scan now, because other Wechaty developers want to talk with you too! (secret code: _wechaty_)
ruiruibupt's avatar
ruiruibupt 已提交
228

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
229
## FUTURE IMPROVEMENTS
230

231 232
Wechaty is far from perfect. The following things should be addressed in the future:

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
233
* [Create New Puppets for Wechaty #1167](https://github.com/Chatie/wechaty/issues/1167)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
234

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
235
## AUTHOR
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
236

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
237
[Huan LI](http://linkedin.com/in/zixia) \<zixia@zixia.net\>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
238

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
239 240
<a href="https://stackexchange.com/users/265499">
  <img src="https://stackexchange.com/users/flair/265499.png" width="208" height="58" alt="profile for zixia on Stack Exchange, a network of free, community-driven Q&amp;A sites" title="profile for zixia on Stack Exchange, a network of free, community-driven Q&amp;A sites">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
241 242 243 244
</a>

## My Story

245
My daily life/work depends on too much chat on wechat.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
246

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
247
* I almost have 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
248
* I almost have 400 wechat rooms, and most of them have more than 400 members.
249

250
Can you imagine that? I'm dying...
251

252
So a tireless bot working for me 24x7 on wechat, monitoring/filtering the most important message is badly needed. For example, it highlights discussion which contains the KEYWORDS which I want to follow up(especially in a noisy room). ;-)
253 254 255

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
256 257
## COPYRIGHT & LICENSE

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
258
* Code & Docs © 2016-2018 Huan LI \<zixia@zixia.net\>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
259
* Code released under the Apache-2.0 License
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
260
* Docs released under Creative Commons
261

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