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 
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
[![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 (李卓桓) 已提交
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
doc  
Huan (李卓桓) 已提交
32
The shortest wechat bot code in the world: 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
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
38
.on('scan', (url, code) => console.log(`Scan QR Code to login: ${code}\n${url}`))
39 40
.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
Huan (李卓桓) 已提交
48 49 50
# 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 (李卓桓) 已提交
51

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

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

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
67 68 69
# 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 (李卓桓) 已提交
70

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
73 74
```shell
npm install --save wechaty
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
75 76 77 78
```

# Requirement

79 80 81 82
1. Javascript ES6(ECMAScript2015)
1. Node.js v6+
1. Docker(optional)
1. TypeScript(optional)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
83

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
84
# API Reference
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
85

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
88 89 90 91
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)
92

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

95 96 97 98 99 100 101 102 103
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)
104

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

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

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

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

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

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

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

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

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
124 125 126
# 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 (李卓桓) 已提交
127

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
130
To test Wechaty, run:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
131 132
```shell
npm test
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
133 134
```

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
137
# Release Notes
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
138

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
143
# Todo List
144

Huan (李卓桓)'s avatar
todo  
Huan (李卓桓) 已提交
145
- [ ] Events
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
146
    - [ ] Use EventEmitter2 to emit message events so that we can use wildcard
147 148 149 150 151 152 153 154
        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 (李卓桓) 已提交
155
- [ ] Message
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
156 157 158
    - [ ] Send/Reply image/video/attachment message
    - [ ] Save video message to file
    - [x] Save image message to file
159

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
160 161 162
# Badge

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

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

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

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
188
My Story
189 190
----------------
My daily life/work depends on too much chat on wechat.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
191
* I almost have 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
192 193 194 195
* 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 (李卓桓) 已提交
196
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). ;-)
197 198 199

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
200 201 202 203 204
Author
-----------------
Zhuohuan LI <zixia@zixia.net> (http://linkedin.com/in/zixia)

<a href="http://stackoverflow.com/users/1123955/zixia">
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
205
  <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 (李卓桓) 已提交
206 207 208 209 210 211 212
</a>

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

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