README.md 26.9 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
[![NPM Version](https://badge.fury.io/js/wechaty.svg)](https://www.npmjs.com/package/wechaty)
6
[![Downloads](https://img.shields.io/npm/dm/wechaty.svg?style=flat-square)](https://www.npmjs.com/package/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
7
[![GitHub stars](https://img.shields.io/github/stars/Chatie/wechaty.svg?label=github%20stars)](https://github.com/chatie/wechaty)
8
[![Docker Pulls](https://img.shields.io/docker/pulls/zixia/wechaty.svg?maxAge=2592000)](https://hub.docker.com/r/zixia/wechaty/)
9
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](https://www.typescriptlang.org/)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
10
[![Greenkeeper badge](https://badges.greenkeeper.io/Chatie/wechaty.svg)](https://greenkeeper.io/)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
11
[![Gitter](https://badges.gitter.im/Chatie/wechaty.svg)](https://gitter.im/Chatie/wechaty?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
12

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
13 14 15 16
## CONNECTING CHATBOTS

Wechaty is a Bot SDK for Wechat **Individual** Account which can help you create a bot in 6 lines of javascript, with cross-platform support including [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).

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

Huan (李卓桓)'s avatar
clean  
Huan (李卓桓) 已提交
22
## VOICE OF DEVELOPERS
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
23

24
> "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 (李卓桓) 已提交
25 26
> &mdash; <cite>@Gcaufy, Tencent Engineer, Author of [WePY](https://github.com/Tencent/wepy)</cite>
>
27
> "太好用,好用的想哭"  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
28 29
> &mdash; <cite>@xinbenlv, Google Engineer, Founder of HaoShiYou.org</cite>
>
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
30
> "最好的微信开发库" [link](http://weibo.com/3296245513/Ec4iNp9Ld?type=comment)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
31 32
> &mdash; <cite>@Jarvis, Baidu Engineer</cite>
>
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
33
> "Wechaty让运营人员更多的时间思考如何进行活动策划、留存用户,商业变现" [link](http://mp.weixin.qq.com/s/dWHAj8XtiKG-1fIS5Og79g)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
34 35
> &mdash; <cite>@lijiarui, CEO of BotOrange.</cite>
>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
36
> "If you know js ... try Wechaty, it's easy to use."  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
37
> &mdash; <cite>@Urinx Uri Lee, Author of [WeixinBot(Python)](https://github.com/Urinx/WeixinBot)</cite>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
38

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
39
See more at [Wiki:Voice Of Developer](https://github.com/Chatie/wechaty/wiki/Voice%20Of%20Developer)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
40

41 42 43 44 45 46 47 48
### Join Us

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**.

![Wechaty Developers' Home](https://chatie.io/wechaty/images/bot-qr-code.png)

Scan now, because other Wechaty developers want to talk with you too! (secret code: _wechaty_)

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
51
```javascript
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
52

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
55
Wechaty.instance() // Global Instance
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
56
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrcode)}`))
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
57 58
.on('login',            user => console.log(`User ${user} logined`))
.on('message',       message => console.log(`Message: ${message}`))
59
.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
60
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
61

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
62
> **Notice: Wechaty requires Node.js version >= 10**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
63

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
64
This bot can log all messages to the console after login by scan.
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
65

66
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 (李卓桓) 已提交
67

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
68 69 70 71 72
## REQUIREMENTS

1. Node.js 10 or above
1. Global Network Connection

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
73
## GETTING STARTED
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
74

75 76
[![node](https://img.shields.io/node/v/wechaty.svg?maxAge=604800)](https://nodejs.org/)

77
* Wechaty Starter Repository - <https://github.com/wechaty/wechaty-getting-started>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
78

Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
79
We have a Wechaty starter repository for beginners with the simplest setting. It will be **just work** out-of-the-box after you `clone` & `npm install` & `npm start`.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
80

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
81
If you are new to Wechaty and want to try it the first time, we'd like to strong recommend you starting from this repository, and using it as your starter template for your project.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
82

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
83
Otherwise, please saved the above _The World's Shortest ChatBot Code: 6 lines of JavaScript_ example to a file named `mybot.js` before you can use either NPM or Docker to run it.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
84

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
85
### 1. NPM
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
86

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
87
[![NPM Version](https://badge.fury.io/js/wechaty.svg)](https://www.npmjs.com/package/wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
88
[![npm (tag)](https://img.shields.io/npm/v/wechaty/next.svg)](https://www.npmjs.com/package/wechaty?activeTab=versions)
89
[![Downloads](https://img.shields.io/npm/dm/wechaty.svg?style=flat-square)](https://www.npmjs.com/package/wechaty)
Huan (李卓桓)'s avatar
layout  
Huan (李卓桓) 已提交
90
[![install size](https://packagephobia.now.sh/badge?p=wechaty)](https://packagephobia.now.sh/result?p=wechaty)
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
91

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
92 93 94
```shell
npm init
npm install wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
95

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
96 97 98 99
# create your first mybot.js file, you can copy/paste from the above "The World's Shortest ChatBot Code: 6 lines of JavaScript"
# then:
node mybot.js
```
李文成 已提交
100

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
101
### 2. Docker
Huan (李卓桓)'s avatar
doc  
Huan (李卓桓) 已提交
102

103 104
[![Docker Pulls](https://img.shields.io/docker/pulls/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 (李卓桓) 已提交
105

106
* Wechaty Starter Repository for Docker - <https://github.com/wechaty/docker-wechaty-getting-started>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
107

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
108
> Wechaty Docker supports both JavaScript and TypeScript. To use TypeScript just write in TypeScript and save with extension name `.ts`, no need to compile because we use `ts-node` to run it.
109

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
110
2.1. Run JavaScript
111

112
```shell
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
113 114
# for JavaScript
docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
115 116
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
117
2.2. Run TypeScript
118

119
```shell
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
120 121
# for TypeScript
docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.ts
122 123
```

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
124
> Learn more about Wechaty Docker at [Wiki:Docker](https://github.com/chatie/wechaty/wiki/Docker).
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
125

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
126 127
### 3. Switch Protocol(Puppet)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
128
Wechaty is very powerful that it can run over different protocols. You can specify the protocol by set the environment variable `WECHATY_PUPPET` to different puppet provider.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
129 130 131

Currently we support the following puppet providers:

132 133 134 135 136 137
| Protocol | Puppet Provider | Environment Variable |
| --- | --- | --- |
| Web | PuppetPuppeteer | `export WECHATY_PUPPET=wechaty-puppet-puppeteer` |
| iPad | PuppetPadchat | `export WECHATY_PUPPET=wechaty-puppet-padchat` |
| Mock | PuppetMock | `export WECHATY_PUPPET=wechaty-puppet-mock` |
| Web | PuppetWechat4u | `export WECHATY_PUPPET=wechaty-puppet-wechat4u` |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
138 139 140 141 142 143 144

Learn more about Wechaty Puppet from the Puppet Wiki:

1. Puppet Directory: <https://github.com/Chatie/wechaty-puppet/wiki/Directory>
1. Puppet Compatibility: <https://github.com/Chatie/wechaty-puppet/wiki/Compatibility>


Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
145
## API
146

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
147
Read the Full Documentation at [Wechaty Official API Reference](https://chatie.github.io/wechaty/)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
148 149 150 151 152 153 154

### 1 Class `Wechaty`

Main bot class.

A `Bot` is a Wechaty instance that control a specific [wechaty-puppet](https://github.com/Chatie/wechaty/wiki/Puppet).

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
155
* `new Wechaty(options?: WechatyOptions)`
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
156 157
    1. `options.name?: string` the name of this bot(optional)
    2. `optoins.puppet?: string` select which puppet provider we want to use. must be one of the:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
158 159
        1. [wechaty-puppet-puppeteer](https://github.com/chatie/wechaty-puppet-puppeteer) - Angular Hook for Web Wechat <- This is the DEFAULT
        2. [wechaty-puppet-wechat4u](https://github.com/chatie/wechaty-puppet-wechat4u) - HTTP API for Web Wechat
160
        3. [wechaty-puppet-padpro](https://github.com/botorange/wechaty-puppet-padpro) - iPad App Protocol
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
161
        4. [wechaty-puppet-ioscat](https://github.com/linyimin-bupt/wechaty-puppet-ioscat) - iPhone App Hook
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
162 163
        5. [wechaty-puppet-mock](https://github.com/chatie/wechaty-puppet-mock) - Mock for Testing
    3. `optoins.puppetOptions?: PuppetOptions` options for the puppet provider.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
164

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
165 166
| Wechaty | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| event | [`login`](https://chatie.io/wechaty/#Wechaty+on) | emit after bot login full successful |
| event | [`logout`](https://chatie.io/wechaty/#Wechaty+on) | emit after the bot log out |
| event | [`friendship`](https://chatie.io/wechaty/#Wechaty+on) | emit when someone sends bot a friend request|
| event | [`message`](https://chatie.io/wechaty/#Wechaty+on) | emit when there's a new message |
| event | [`room-join`](https://chatie.io/wechaty/#Wechaty+on) | emit when anyone join any room |
| event | [`room-topic`](https://chatie.io/wechaty/#Wechaty+on) | emit when someone change room topic |
| event | [`room-leave`](https://chatie.io/wechaty/#Wechaty+on) | emit when anyone leave the room |
| event | [`room-invite`](https://chatie.io/wechaty/#Wechaty+on) | emit when there is a room invitation |
| event | [`scan`](https://chatie.io/wechaty/#Wechaty+on) | emit when the bot needs to show you a QR Code for scanning |
| method | [`start(): Promise<void>`](https://chatie.io/wechaty/#Wechaty+start) | start the bot |
| method | [`stop(): Promise<void>`](https://chatie.io/wechaty/#Wechaty+stop) | stop the bot |
| method | [`logonoff(): boolean`](https://chatie.io/wechaty/#Wechaty+logonoff) | bot login status |
| method | [`logout(): Promise<void>`](https://chatie.io/wechaty/#Wechaty+logout) | logout the bot |
| method | [`userSelf(): ContactSelf`](https://chatie.io/wechaty/#Wechaty+userSelf) | get the login-ed bot contact |
| method | [`say(text: string): Promise<void>`](https://chatie.io/wechaty/#Wechaty+say) | let bot say `text` to itself |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
182 183 184 185 186

### 2 Class `Contact`

All wechat contacts(friends/non-friends) will be encapsulated as a Contact.

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
187 188
| Contact | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
189 190 191
| static | [`find(query: string): Promise<null \| Contact>`](https://chatie.io/wechaty/#Contact.find) | find contact by name or alias, if the result more than one, return the first one. |
| static | [`findAll(query: string): Promise<Contact[]>`](https://chatie.io/wechaty/#Contact.findAll) | find contact by `name` or `alias` |
| static | [`load(query: string): Contact`](https://chatie.io/wechaty/#Contact.load) | get contact by id |
W
William Chen 已提交
192
| property | `id: readonly string` | get contact id |
T
TbhT 已提交
193 194 195 196 197 198 199 200
| method | [`sync(): Promise<void>`](https://chatie.io/wechaty/#Contact+sync) | force reload data for contact , sync data from lowlevel API again|
| method | [`say(text: string): Promise<void>`](https://chatie.io/wechaty/#Contact+say) | send text, Contact, or file to contact |
| method | [`self(): boolean`](https://chatie.io/wechaty/#Contact+self) | check if contact is self |
| method | [`name(): string`](https://chatie.io/wechaty/#Contact+name) | get the name from a contact |
| method | [`alias(): Promise<string>`](https://chatie.io/wechaty/#Contact+alias) | get the alias for a contact |
| method | [`alias(newAlias: string): Promise<void>`](https://chatie.io/wechaty/#Contact+alias) | set or delete the alias for a contact |
| method | [`friend(): boolean`](https://chatie.io/wechaty/#Contact+friend) | check if contact is friend |
| method | [`type(): ContactType`](https://chatie.io/wechaty/#Contact+type) | return the type of the Contact |
G
Gcaufy 已提交
201
| method | [`province(): string`](https://chatie.io/wechaty/#Contact+province) | get the region 'province' from a contact |
T
TbhT 已提交
202 203 204
| method | [`city(): string`](https://chatie.io/wechaty/#Contact+city) | get the region 'city' from a contact |
| method | [`avatar(): Promise<FileBox>`](https://chatie.io/wechaty/#Contact+avatar) | get avatar picture file stream |
| method | [`gender(): ContactGender`](https://chatie.io/wechaty/#Contact+gender) | get gender from a contact |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
205

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
206 207 208
#### 2.1 Class `ContactSelf`

Class `ContactSelf` is extended from `Contact`.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
209

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
210 211
| ContactSelf | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
212 213 214
| method | [`avatar(file: FileBox): Promise<void>`](https://chatie.io/wechaty/#ContactSelf+avatar) | set avatar for bot |
| method | [`qrcode(): Promise<string>`](https://chatie.io/wechaty/#ContactSelf+qrcode) | get qrcode for bot |
| method | [`signature(text: string): Promise<void>`](https://chatie.io/wechaty/#ContactSelf+signature) | set signature for bot |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
215

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
216 217 218 219 220 221
#### 2.2 Class `Friendship`

Send, receive friend request, and friend confirmation events.

| Friendship | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
222 223 224 225 226
| static | [`add(contact: Contact, hello?: string): Promise<void>`](https://chatie.io/wechaty/#Friendship.add) | send a friend invitation to contact |
| method | [`accept(): Promise<void>`](https://chatie.io/wechaty/#Friendship+accept) | accept Friend Request |
| method | [`hello(): string`](https://chatie.io/wechaty/#Friendship+hello) | get the hello string from a friendship invitation |
| method | [`contact(): Contact`](https://chatie.io/wechaty/#Friendship+contact) | get the contact from friendship |
| method | [`type(): FriendshipType`](https://chatie.io/wechaty/#Friendship+type) | return the Friendship Type(unknown, confirm, receive, verify) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
227

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
228
### 3 Class `Message`
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
229 230 231

All wechat messages will be encapsulated as a Message.

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
232 233
| Message | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246
| static | [`find(query: string): Promise<null \| Message>`](https://chatie.io/wechaty/#Message.find) | find message in cache and return the first one |
| static | [`findAll(query: string): Promise<Message[]>`](https://chatie.io/wechaty/#Message.findAll) | find messages in cache, return a message list |
| method | [`from(): Contact`](https://chatie.io/wechaty/#Message+from) | get the sender from a message |
| method | [`to(): Contact`](https://chatie.io/wechaty/#Message+to) | get the destination of the message |
| method | [`room(): null \| Room`](https://chatie.io/wechaty/#Message+room) | get the room from the message.(If the message is not in a room, then will return `null`) |
| method | [`text(): string`](https://chatie.io/wechaty/#Message+text) | get the text content of the message |
| method | [`say(text: string): Promise<void>`](https://chatie.io/wechaty/#Message+say) | reply a Text, Media File , or contact message to the sender. |
| method | [`type(): MessageType`](https://chatie.io/wechaty/#Message+type) | get the type from the message |
| method | [`self(): boolean`](https://chatie.io/wechaty/#Message+self) | check if a message is sent by self |
| method | [`mention(): Contact[]`](https://chatie.io/wechaty/#Message+mention) | get message mentioned contactList. |
| method | [`mentionSelf(): boolean`](https://chatie.io/wechaty/#Message+mentionSelf) | check if a message is mention self |
| method | [`forward(to: Contact): Promise<void>`](https://chatie.io/wechaty/#Message+forward) | Forward the received message |
| method | [`age(): number`](https://chatie.io/wechaty/#Message+age) | the number of seconds since it has been created |
T
TbhT 已提交
247
| method | `date(): Date` | the time it was created |
T
TbhT 已提交
248 249
| method | [`toFileBox(): Promise<FileBox>`](https://chatie.io/wechaty/#Message+toFileBox) | extract the Media File from the Message, and put it into the FileBox. |
| method | [`toContact(): Promise<Contact>`](https://chatie.io/wechaty/#Message+toContact) | get Share Card of the Message |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
250

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
251
### 4 Class `Room`
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
252 253 254

All wechat rooms(groups) will be encapsulated as a Room.

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
255 256
| Room | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
257 258 259 260
| static | [`create(contactList: Contact[], topic?: string): Promise<Room>`](https://chatie.io/wechaty/#Room.create) | create a new room |
| static | [`find(query: string): Promise<null \| Room>`](https://chatie.io/wechaty/#Room.find) | Try to find a room by filter. If get many, return the first one. |
| static | [`findAll(query: string): Promise<Room[]>`](https://chatie.io/wechaty/#Room.findAll) | Find all contacts in a room |
| static | [`load(query: string): Room`](https://chatie.io/wechaty/#Room.load) | load room by room id |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
261
| property | `id: readonly string` |  |
T
TbhT 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275
| event | [`join`](https://chatie.io/wechaty/#Room+on) | emit when anyone join any room |
| event | [`topic`](https://chatie.io/wechaty/#Room+on) | emit when someone change room topic |
| event | [`leave`](https://chatie.io/wechaty/#Room+on) | emit when anyone leave the room |
| event | [`invite`](https://chatie.io/wechaty/#Room+on) | emit when receive a room invitation |
| method | [`sync(): <Promise<void>`](https://chatie.io/wechaty/#Room+sync) | force reload data for room, sync data from lowlevel API again.
| method | [`say(text: string): Promise<void>`](https://chatie.io/wechaty/#Room+say) | Send text,media file, contact card, or text with mention @mention contact inside Room |
| method | [`add(contact: Contact): Promise<void>`](https://chatie.io/wechaty/#Room+add) | Add contact in a room |
| method | [`del(contact: Contact): Promise<void>`](https://chatie.io/wechaty/#Room+del) | Delete a contact from the room |
| method | [`quit(): Promise<void>`](https://chatie.io/wechaty/#Room+quit) | Bot quit the room itself |
| method | [`topic(): Promise<string>`](https://chatie.io/wechaty/#Room+topic) | GET topic from the room |
| method | [`topic(newTopic: string): Promise<void>`](https://chatie.io/wechaty/#Room+topic) | SET topic from the room |
| method | [`announce(text: string): Promise<void>`](https://chatie.io/wechaty/#Room+announce) | SET/GET announce from the room |
| method | [`qrcode(): Promise<string>`](https://chatie.io/wechaty/#Room+qrcode) | Get QR Code of the Room from the room, which can be used as scan and join the room. |
| method | [`alias(contact: Contact): Promise<string>`](https://chatie.io/wechaty/#Room+alias) | Return contact's roomAlias in the room |
T
TbhT 已提交
276
| method | [`roomAlias(contact: Contact): Promise<string \| null>`](https://chatie.io/wechaty/#Room+roomAlias) | Same as function alias |
T
TbhT 已提交
277 278
| method | [`has(contact: Contact): Promise<boolean>`](https://chatie.io/wechaty/#Room+has) | Check if the room has member `contact` |
| method | [`memberAll(query?: string): Promise<Contact[]>`](https://chatie.io/wechaty/#Room+memberAll) | Find all contacts or with specific name in a room |
T
TbhT 已提交
279 280
| method | [`member(query: string): Promise<null \| Contact>`](https://chatie.io/wechaty/#Room+member) | Find all contacts in a room, if get many, return the first one. |
| method | [`memberList():Promise<Contact[]>`](https://chatie.io/wechaty/#Room+memberList) | get all room member from the room |
T
TbhT 已提交
281
| method | [`owner(): null \| Contact`](https://chatie.io/wechaty/#Room+owner) | Get room's owner from the room. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
282

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
283 284 285 286 287 288
#### 4.1 Class `RoomInvitation`

Accept room invitation

| RoomInvitation | API | Description |
| :--- | :--- | :---        |
T
TbhT 已提交
289 290 291 292
| method | [`accept(): Promise<void>`](https://chatie.io/wechaty/#RoomInvitation+accept) | accept Room Invitation |
| method | [`inviter(): Contact`](https://chatie.io/wechaty/#RoomInvitation+inviter) | get the inviter from room invitation |
| method | [`roomTopic(): Promise<string>`](https://chatie.io/wechaty/#RoomInvitation+inviter) | get the room topic from room invitation |
| method | [`date(): Promise<Date>`](https://chatie.io/wechaty/#RoomInvitation+date) | the time it was created |
T
TbhT 已提交
293
| method | `age(): Promise<number>` | the number of seconds since it has been created |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
294

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
## TEST

[![Ubuntu Linux/Mac Build Status](https://travis-ci.com/Chatie/wechaty.svg?branch=master)](https://travis-ci.com/Chatie/wechaty)
[![Travis](https://img.shields.io/travis/Chatie/wechaty.svg?label=Ubuntu/OSX)](https://travis-ci.com/Chatie/wechaty)
[![CentOS Linux Build Status](https://circleci.com/gh/Chatie/wechaty.svg?style=svg)](https://circleci.com/gh/Chatie/wechaty)
[![CircleCI](https://img.shields.io/circleci/project/github/Chatie/wechaty.svg?label=CentOS)](https://circleci.com/gh/Chatie/wechaty)
[![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)

[![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)

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.

To test Wechaty, run:

```shell
npm test
```

Get to know more about the tests from [Wiki:Tests](https://github.com/chatie/wechaty/wiki/Tests)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
317
## RELEASE NOTES
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
318

319 320
* [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 (李卓桓) 已提交
321

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
322 323 324 325
### Views Since Feb 15, 2019

[![HitCount](http://hits.dwyl.io/chatie/wechaty.svg)](http://hits.dwyl.io/chatie/wechaty)

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
330
### Wechaty Badge
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
331

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
332 333 334 335 336
```markdown
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-blue.svg)](https://github.com/chatie/wechaty)
```

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
340
1. [一个用CNN深度神剧网络给图片评分的wechaty项目](https://github.com/huyingxi/wechaty_selfie)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
341 342 343 344
2. [Relay between Telegram and WeChat](https://github.com/Firaenix/TeleChatRelay)
3. [A chat bot managing the HaoShiYou wechat groups run by volunteers of haoshiyou.org](https://github.com/xinbenlv/haoshiyou-bot)
4. [An interactive chat bot to manage a TODO list](https://github.com/coderbunker/candobot)
5. [Forward WeChat messages to telegram](https://github.com/luosheng/Wegram)
345
6. [koa与wechaty实现的微信小助手,可定时提醒与发消息设定定时任务](https://github.com/gengchen528/wechat-assistant)
346 347
7. [Wechaty Pay - 让线上没有难做的生意](https://github.com/coderwhocode/wechaty-pay)

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
349 350
Pull Request is welcome to add yours!

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

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

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

357
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 (李卓桓) 已提交
358 359 360 361 362 363

| 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 (李卓桓) 已提交
364
| Singapore | $3.5  | 512MB   | Alipay, Wechat    | [Vultr](https://www.vultr.com/?ref=6986613) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
365

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
366
## SEE ALSO
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
367 368 369

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
370
## AUTHOR
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
371

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
372
1. [Huan LI (李卓桓)](http://linkedin.com/in/zixia) \<zixia@zixia.net\>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
373
1. [Grace LI (李佳芮)](https://angel.co/lijiarui)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
374

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
375
[![Profile of Huan LI (李卓桓) on StackOverflow](https://stackexchange.com/users/flair/265499.png)](https://stackexchange.com/users/265499)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
376

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
377
## The Story
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
378

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
379
In 2017 ...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
380

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

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
386
Can you imagine that? He was dying...
387

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
388 389 390
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 he want to follow up(especially in a noisy room). ;-)

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

J
jess 已提交
392 393
## Contributors

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
394 395
[![GitHub issues](https://img.shields.io/github/issues/chatie/wechaty.svg)](https://github.com/chatie/wechaty/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/chatie/wechaty.svg)](https://github.com/Chatie/wechaty/pulls)
396 397 398
[![Open Collective Backers](https://opencollective.com/wechaty/backer/badge.svg?label=open%20collective%20backers&color=blue)](https://opencollective.com/wechaty/)
[![Open Collective Sponsors](https://opencollective.com/wechaty/sponsors/badge.svg?label=open%20collective%20sponsors&color=blue)](https://opencollective.com/wechaty/)

J
jess 已提交
399 400 401 402 403
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="https://github.com/Chatie/wechaty/graphs/contributors"><img src="https://opencollective.com/wechaty/contributors.svg?width=890&button=false" /></a>

## Backers

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
404 405
[![Backers on Open Collective](https://opencollective.com/wechaty/backers/badge.svg)](#backers)

J
jess 已提交
406 407 408 409 410 411
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/wechaty#backer)]

<a href="https://opencollective.com/wechaty#backers" target="_blank"><img src="https://opencollective.com/wechaty/backers.svg?width=890"></a>

## Sponsors

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
412 413
[![Sponsors on Open Collective](https://opencollective.com/wechaty/sponsors/badge.svg)](#sponsors) 

J
jess 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/wechaty#sponsor)]

<a href="https://opencollective.com/wechaty/sponsor/0/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/1/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/2/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/3/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/4/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/5/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/6/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/7/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/8/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/wechaty/sponsor/9/website" target="_blank"><img src="https://opencollective.com/wechaty/sponsor/9/avatar.svg"></a>

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

429 430 431
* Code & Docs © 2016-2019 Huan LI \<zixia@zixia.net\>
* Code released under the Apache-2.0 License
* Docs released under Creative Commons