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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
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), [Windows](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
[![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=604800)](https://nodejs.org/) [![Repo Size](https://reposs.herokuapp.com/?path=wechaty/wechaty)](https://github.com/wechaty/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
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
doc  
Huan (李卓桓) 已提交
18 19 20
> @JasLin: the best wechat SDK I have seen in Github! [link](https://github.com/wechaty/wechaty/issues/8#issuecomment-228971491)

> @Jarvis: 最好的微信开发库 [link](http://weibo.com/3296245513/Ec4iNp9Ld?type=comment)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21 22 23

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
24
> @ak5: it's quite cool! [link](https://github.com/wechaty/wechaty/issues/4)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
25 26 27 28

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

> @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
doc  
Huan (李卓桓) 已提交
44
This bot can log all message to console.
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
# Run

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
50 51 52 53 54 55
Let's say, you have saved the above six lines javascript example to `mybot.js`.

We have two options to run wechaty:

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
57 58 59
## Docker

[![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 (李卓桓) 已提交
60

61
```shell
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
62 63 64 65 66 67
$ docker run \
  -t -i --rm \
  --volume="$(pwd)":/bot \
  --name=wechaty \
  zixia/wechaty \
  mybot.js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
68 69
```

70 71
* Wechaty Docker has native support for TypeScript as well: just write in TypeScript and save to `mybot.ts`, then run `wechaty mybot.ts`.

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
74
## NPM
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
75 76

[![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 (李卓桓) 已提交
77

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
78
```shell
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
79
$ npm install --save wechaty
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
80

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
81 82
$ node mybot.js
```
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
83

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
84
You might be asked for install the `chromedriver`, depends on which platform you are.
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
85

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
88
# API Reference
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
89

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
92 93 94 95
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)
96

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

99 100 101 102 103 104 105 106 107
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)
108

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

ruiruibupt's avatar
ruiruibupt 已提交
111 112 113 114 115 116
1. [id:string](https://github.com/wechaty/wechaty/wiki/API#contactid-string)
1. [name():string](https://github.com/wechaty/wechaty/wiki/API#contactname-string)
1. [remark():string](https://github.com/wechaty/wechaty/wiki/API#contactremark-string)
1. [remark(remark:string):Promise](https://github.com/wechaty/wechaty/wiki/API#contactremarkremark-string-promise)
1. [ready():Promise](https://github.com/wechaty/wechaty/wiki/API#contactready-promise)
1. [say(content:string):Promise](https://github.com/wechaty/wechaty/wiki/API#contactsaycontent-string-promise)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
117

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

ruiruibupt's avatar
ruiruibupt 已提交
120 121 122
1. [hello:string](https://github.com/wechaty/wechaty/wiki/API#friendrequesthello-string)
1. [accept():void](https://github.com/wechaty/wechaty/wiki/API#friendrequestaccept-void)
1. [send(contact:Contact,hello:string):void](https://github.com/wechaty/wechaty/wiki/API#friendrequestsendcontact-contact-hello-string-void)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
123

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

ruiruibupt's avatar
ruiruibupt 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138
1. [from():Contact](https://github.com/wechaty/wechaty/wiki/API#1-messagefrom-contact)
1. [from(contact:Contact):void](https://github.com/wechaty/wechaty/wiki/API#2-messagefromcontact-contact-void)
1. [from(contactId:string):void](https://github.com/wechaty/wechaty/wiki/API#3-messagefromcontactid-string-void)
1. [to():Contact|Room](https://github.com/wechaty/wechaty/wiki/API#1-messageto-contactroom)
1. [to(contact:Contact):void](https://github.com/wechaty/wechaty/wiki/API#2-messagetocontact-contact-void)
1. [to(room:Room):void](https://github.com/wechaty/wechaty/wiki/API#3-messagetoroom-room-void)
1. [to(contactOrRoomId:string):void](https://github.com/wechaty/wechaty/wiki/API#4-messagetocontactorroomid-string-void)
1. [room():Room|null](https://github.com/wechaty/wechaty/wiki/API#1-messageroom-room--null)
1. [room(room:Room):void](https://github.com/wechaty/wechaty/wiki/API#2-messageroomroom-room-void)
1. [room(roomId:string):void](https://github.com/wechaty/wechaty/wiki/API#3-messageroomroomid-string-void)
1. [say(content:string):Promise](https://github.com/wechaty/wechaty/wiki/API#messagesaycontent-string-promise)
1. [ready():Promise](https://github.com/wechaty/wechaty/wiki/API#messageready-promise)
1. [self(message:Message):boolean](https://github.com/wechaty/wechaty/wiki/API#messageselfmessage-message-boolean)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
139

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

ruiruibupt's avatar
ruiruibupt 已提交
142 143 144
1. [say(content:string,replyTo:Contact|ContactArray):Promise](https://github.com/wechaty/wechaty/wiki/API#roomsaycontent-string-replyto-contactcontact-promise)
1. [ready():Promise](https://github.com/wechaty/wechaty/wiki/API#roomready-promise)
1. [refresh():Promise](https://github.com/wechaty/wechaty/wiki/API#roomrefresh-promise)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
145

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

ruiruibupt's avatar
ruiruibupt 已提交
148 149 150
1. [join](https://github.com/wechaty/wechaty/wiki/API#event-join)
1. [leave](https://github.com/wechaty/wechaty/wiki/API#event-leave)
1. [topic](https://github.com/wechaty/wechaty/wiki/API#event-topic)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
151

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
152 153
# Test

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
154
[![Linux/Mac Build Status](https://img.shields.io/travis/wechaty/wechaty.svg?label=Linux/Mac)](https://travis-ci.org/wechaty/wechaty) [![Windows 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) [![Known Vulnerabilities](https://snyk.io/test/github/wechaty/wechaty/badge.svg)](https://snyk.io/test/github/wechaty/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
155

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

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
158
To test Wechaty, run:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
159 160
```shell
npm test
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
161 162
```

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
165
# Release Notes
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
166

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
170
# Powered By Wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
171 172

[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-green.svg)](https://github.com/wechaty/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
173

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
174
## Wechaty Badge
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
175

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
178
## Projects Use Wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
179

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
180
1. [Wechaty.io](https://www.wechaty.io) ChatBot Portal Manager for Wechaty 
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
181

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
182
Know more about Projects Use Wechaty at [Wiki:PoweredByWechaty](https://github.com/wechaty/wechaty/wiki/PoweredByWechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
183

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

186
Howto [contribute](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