index.md 77.4 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
# Wechaty v0.62.1 Documentation
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
3 4
- Website - <https://wechaty.js.org>
- Docs Site - <https://wechaty.js.org/docs/>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5
- API References - <https://wechaty.github.io/wechaty/>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
7 8 9
## Classes

<dl>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
10 11
<dt><a href="#Wechaty">Wechaty</a></dt>
<dd><p>Main bot class.</p>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
12
<p>A <code>Bot</code> is a WeChat client depends on which puppet you use.
13 14
It may equals</p>
<ul>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
15 16 17
<li>web-WeChat, when you use: <a href="https://github.com/wechaty/wechaty-puppet-puppeteer">puppet-puppeteer</a>/<a href="https://github.com/wechaty/wechaty-puppet-wechat4u">puppet-wechat4u</a></li>
<li>ipad-WeChat, when you use: <a href="https://github.com/wechaty/wechaty-puppet-padchat">puppet-padchat</a></li>
<li>ios-WeChat, when you use: puppet-ioscat</li>
18 19 20
</ul>
<p>See more:</p>
<ul>
21
<li><a href="https://github.com/wechaty/wechaty-getting-started/wiki/FAQ-EN#31-what-is-a-puppet-in-wechaty">What is a Puppet in Wechaty</a></li>
22 23 24 25 26
</ul>
<blockquote>
<p>If you want to know how to send message, see <a href="#Message">Message</a> <br>
If you want to know how to get contact, see <a href="#Contact">Contact</a></p>
</blockquote>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
27
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
28
<dt><a href="#Room">Room</a></dt>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
29
<dd><p>All WeChat rooms(groups) will be encapsulated as a Room.</p>
30
<p><a href="https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/room-bot.ts">Examples/Room-Bot</a></p>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
31 32 33
</dd>
<dt><a href="#Contact">Contact</a></dt>
<dd><p>All wechat contacts(friend) will be encapsulated as a Contact.
34
<a href="https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/contact-bot.ts">Examples/Contact-Bot</a></p>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
35
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
36 37 38 39 40
<dt><a href="#ContactSelf">ContactSelf</a></dt>
<dd><p>Bot itself will be encapsulated as a ContactSelf.</p>
<blockquote>
<p>Tips: this class is extends Contact</p>
</blockquote>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
41 42 43 44 45 46 47 48
</dd>
<dt><a href="#Friendship">Friendship</a></dt>
<dd><p>Send, receive friend request, and friend confirmation events.</p>
<ol>
<li>send request</li>
<li>receive request(in friend event)</li>
<li>confirmation friendship(friend event)</li>
</ol>
49
<p><a href="https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts">Examples/Friend-Bot</a></p>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
50
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
51 52
<dt><a href="#Message">Message</a></dt>
<dd><p>All wechat messages will be encapsulated as a Message.</p>
53
<p><a href="https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/ding-dong-bot.ts">Examples/Ding-Dong-Bot</a></p>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
54 55 56 57
</dd>
<dt><a href="#RoomInvitation">RoomInvitation</a></dt>
<dd><p>accept room invitation</p>
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
58 59
</dl>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
## Constants

<dl>
<dt><a href="#cuid_1">cuid_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#clone_class_1">clone_class_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#clone_class_1">clone_class_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#wechaty_puppet_1">wechaty_puppet_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#events_1">events_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#events_1">events_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
<dt><a href="#clone_class_1">clone_class_1</a></dt>
<dd><p>Wechaty Chatbot SDK - <a href="https://github.com/wechaty/wechaty">https://github.com/wechaty/wechaty</a></p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#guardWechatify">guardWechatify()</a></dt>
<dd><p>Huan(202008): we will bind the wechaty puppet with user modules (Contact, Room, etc) together inside the start() method</p>
</dd>
</dl>

L
lijiarui 已提交
94
## Typedefs
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
95 96

<dl>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
97
<dt><a href="#PuppetModuleName">PuppetModuleName</a></dt>
98
<dd><p>The term <a href="https://github.com/wechaty/wechaty/wiki/Puppet">Puppet</a> in Wechaty is an Abstract Class for implementing protocol plugins.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
99
The plugins are the component that helps Wechaty to control the WeChat(that&#39;s the reason we call it puppet).
100 101
The plugins are named XXXPuppet, for example:</p>
<ul>
102 103
<li><a href="https://github.com/wechaty/wechaty-puppet-puppeteer">PuppetPuppeteer</a>:</li>
<li><a href="https://github.com/wechaty/wechaty-puppet-padchat">PuppetPadchat</a></li>
104 105 106 107 108 109 110 111
</ul>
</dd>
<dt><a href="#WechatyOptions">WechatyOptions</a></dt>
<dd><p>The option parameter to create a wechaty instance</p>
</dd>
<dt><a href="#RoomQueryFilter">RoomQueryFilter</a></dt>
<dd><p>The filter to find the room:  {topic: string | RegExp}</p>
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
112 113 114 115 116 117
<dt><a href="#RoomEventName">RoomEventName</a></dt>
<dd><p>Room Class Event Type</p>
</dd>
<dt><a href="#RoomEventFunction">RoomEventFunction</a></dt>
<dd><p>Room Class Event Function</p>
</dd>
118
<dt><a href="#RoomMemberQueryFilter">RoomMemberQueryFilter</a></dt>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
119 120 121 122 123
<dd><p>The way to search member by Room.member()</p>
</dd>
<dt><a href="#ContactQueryFilter">ContactQueryFilter</a></dt>
<dd><p>The way to search Contact</p>
</dd>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
124 125
</dl>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
126
<a name="Wechaty"></a>
L
lijiarui 已提交
127

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
128 129
## Wechaty
Main bot class.
L
lijiarui 已提交
130

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
131
A `Bot` is a WeChat client depends on which puppet you use.
132
It may equals
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
133 134 135
- web-WeChat, when you use: [puppet-puppeteer](https://github.com/wechaty/wechaty-puppet-puppeteer)/[puppet-wechat4u](https://github.com/wechaty/wechaty-puppet-wechat4u)
- ipad-WeChat, when you use: [puppet-padchat](https://github.com/wechaty/wechaty-puppet-padchat)
- ios-WeChat, when you use: puppet-ioscat
L
lijiarui 已提交
136

137
See more:
138
- [What is a Puppet in Wechaty](https://github.com/wechaty/wechaty-getting-started/wiki/FAQ-EN#31-what-is-a-puppet-in-wechaty)
139 140 141

> If you want to know how to send message, see [Message](#Message) <br>
> If you want to know how to get contact, see [Contact](#Contact)
L
lijiarui 已提交
142

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
143
**Kind**: global class  
L
lijiarui 已提交
144

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
145
* [Wechaty](#Wechaty)
146
    * [new Wechaty([options])](#new_Wechaty_new)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
147
    * _instance_
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
148
        * [.wechatifiedContact](#Wechaty+wechatifiedContact)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
149
        * [.name()](#Wechaty+name)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
150
        * [.use(...plugins)](#Wechaty+use)[<code>Wechaty</code>](#Wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
151
        * [.start()](#Wechaty+start)<code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
152 153 154
        * [.stop()](#Wechaty+stop)<code>Promise.&lt;void&gt;</code>
        * [.logout()](#Wechaty+logout)<code>Promise.&lt;void&gt;</code>
        * [.logonoff()](#Wechaty+logonoff)<code>boolean</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
155
        * [.userSelf()](#Wechaty+userSelf)[<code>ContactSelf</code>](#ContactSelf)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
156
        * [.say(something)](#Wechaty+say)<code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
157
    * _static_
158
        * [.instance([options])](#Wechaty.instance)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
159
        * [.use(...plugins)](#Wechaty.use)[<code>Wechaty</code>](#Wechaty)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
160

161
<a name="new_Wechaty_new"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
162

163 164
### new Wechaty([options])
Creates an instance of Wechaty.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
165 166


167 168 169
| Param | Type | Default |
| --- | --- | --- |
| [options] | [<code>WechatyOptions</code>](#WechatyOptions) | <code>{}</code> | 
L
lijiarui 已提交
170

171
**Example** *(The World&#x27;s Shortest ChatBot Code: 6 lines of JavaScript)*  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
172
```js
173 174
const { Wechaty } = require('wechaty')
const bot = new Wechaty()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
175
bot.on('scan',    (qrCode, status) => console.log('https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode)))
176
bot.on('login',   user => console.log(`User ${user} logged in`))
177 178
bot.on('message', message => console.log(`Message: ${message}`))
bot.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
179
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
180 181 182 183 184 185
<a name="Wechaty+wechatifiedContact"></a>

### wechaty.wechatifiedContact
1. Setup Wechaty User Classes

**Kind**: instance property of [<code>Wechaty</code>](#Wechaty)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
186 187 188
<a name="Wechaty+name"></a>

### wechaty.name()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
189
Wechaty bot name set by `options.name`
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
190 191 192
default: `wechaty`

**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
193
<a name="Wechaty+use"></a>
194

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
195 196
### wechaty.use(...plugins) ⇒ [<code>Wechaty</code>](#Wechaty)
For wechaty ecosystem, allow user to define a 3rd party plugin for the current wechaty instance.
L
lijiarui 已提交
197

198
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
199
**Returns**: [<code>Wechaty</code>](#Wechaty) - - this for chaining,  
L
lijiarui 已提交
200

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
201 202
| Param | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
203
| ...plugins | <code>Array.&lt;WechatyPlugin&gt;</code> | The plugins you want to use |
204

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
205
**Example**  
206
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
207
// The same usage with Wechaty.use().
208
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
209
<a name="Wechaty+start"></a>
L
lijiarui 已提交
210

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
211
### wechaty.start() ⇒ <code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
212
When you start the bot, bot will begin to login, need you WeChat scan qrcode to login
213
> Tips: All the bot operation needs to be triggered after start() is done
L
lijiarui 已提交
214

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
215 216 217
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
218 219
await bot.start()
// do other stuff with bot here
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
220 221
```
<a name="Wechaty+stop"></a>
L
lijiarui 已提交
222

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
223 224
### wechaty.stop() ⇒ <code>Promise.&lt;void&gt;</code>
Stop the bot
L
lijiarui 已提交
225

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
226
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
L
lijiarui 已提交
227 228
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
229
await bot.stop()
L
lijiarui 已提交
230
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
231
<a name="Wechaty+logout"></a>
L
lijiarui 已提交
232

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
233 234
### wechaty.logout() ⇒ <code>Promise.&lt;void&gt;</code>
Logout the bot
L
lijiarui 已提交
235

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
236 237 238 239 240 241
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
**Example**  
```js
await bot.logout()
```
<a name="Wechaty+logonoff"></a>
L
lijiarui 已提交
242

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
243 244
### wechaty.logonoff() ⇒ <code>boolean</code>
Get the logon / logoff state
L
lijiarui 已提交
245

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
246
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
L
lijiarui 已提交
247 248
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
249
if (bot.logonoff()) {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
250
  console.log('Bot logged in')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
251
} else {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
252
  console.log('Bot not logged in')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
253
}
L
lijiarui 已提交
254
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
255 256
<a name="Wechaty+userSelf"></a>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
257
### wechaty.userSelf() ⇒ [<code>ContactSelf</code>](#ContactSelf)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
258
Get current user
L
lijiarui 已提交
259

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
260 261 262
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
263
const contact = bot.userSelf()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
264 265 266
console.log(`Bot is ${contact.name()}`)
```
<a name="Wechaty+say"></a>
L
lijiarui 已提交
267

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
268
### wechaty.say(something) ⇒ <code>Promise.&lt;void&gt;</code>
269
Send message to userSelf, in other words, bot send message to itself.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
270
> Tips:
271
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
L
lijiarui 已提交
272

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
273
**Kind**: instance method of [<code>Wechaty</code>](#Wechaty)  
L
lijiarui 已提交
274

275 276
| Param | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
277
| something | <code>string</code> \| [<code>Contact</code>](#Contact) \| <code>FileBox</code> \| <code>UrlLink</code> \| <code>MiniProgram</code> | send text, Contact, or file to bot. </br> You can use [FileBox](https://www.npmjs.com/package/file-box) to send file |
278 279 280 281 282 283 284

**Example**  
```js
const bot = new Wechaty()
await bot.start()
// after logged in

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
285
// 1. send text to bot itself
286 287
await bot.say('hello!')

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
288
// 2. send Contact to bot itself
289
const contact = await bot.Contact.find()
290 291
await bot.say(contact)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
292
// 3. send Image to bot itself from remote url
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
293
import { FileBox }  from 'wechaty'
294
const fileBox = FileBox.fromUrl('https://wechaty.github.io/wechaty/images/bot-qr-code.png')
295 296
await bot.say(fileBox)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
297
// 4. send Image to bot itself from local file
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
298
import { FileBox }  from 'wechaty'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
299
const fileBox = FileBox.fromFile('/tmp/text.jpg')
300
await bot.say(fileBox)
301 302 303 304 305 306

// 5. send Link to bot itself
const linkPayload = new UrlLink ({
  description : 'WeChat Bot SDK for Individual Account, Powered by TypeScript, Docker, and Love',
  thumbnailUrl: 'https://avatars0.githubusercontent.com/u/25162437?s=200&v=4',
  title       : 'Welcome to Wechaty',
307
  url         : 'https://github.com/wechaty/wechaty',
308 309
})
await bot.say(linkPayload)
Z
zhaoic 已提交
310 311

// 6. send MiniProgram to bot itself
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
312 313 314 315 316 317 318
const miniPayload = new MiniProgram ({
  username           : 'gh_xxxxxxx',     //get from mp.weixin.qq.com
  appid              : '',               //optional, get from mp.weixin.qq.com
  title              : '',               //optional
  pagepath           : '',               //optional
  description        : '',               //optional
  thumbnailurl       : '',               //optional
Z
zhaoic 已提交
319
})
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
320
await bot.say(miniPayload)
321
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
322
<a name="Wechaty.instance"></a>
L
lijiarui 已提交
323

324
### Wechaty.instance([options])
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
325
Get the global instance of Wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
326

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
327
**Kind**: static method of [<code>Wechaty</code>](#Wechaty)  
328 329 330 331 332

| Param | Type | Default |
| --- | --- | --- |
| [options] | [<code>WechatyOptions</code>](#WechatyOptions) | <code>{}</code> | 

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
333 334 335
**Example** *(The World&#x27;s Shortest ChatBot Code: 6 lines of JavaScript)*  
```js
const { Wechaty } = require('wechaty')
L
lijiarui 已提交
336

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
337
Wechaty.instance() // Global instance
338
.on('scan', (url, status) => console.log(`Scan QR Code to login: ${status}\n${url}`))
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
339
.on('login',       user => console.log(`User ${user} logged in`))
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
340
.on('message',  message => console.log(`Message: ${message}`))
341
.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
342
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
<a name="Wechaty.use"></a>

### Wechaty.use(...plugins) ⇒ [<code>Wechaty</code>](#Wechaty)
For wechaty ecosystem, allow user to define a 3rd party plugin for the all wechaty instances

**Kind**: static method of [<code>Wechaty</code>](#Wechaty)  
**Returns**: [<code>Wechaty</code>](#Wechaty) - - this for chaining,  

| Param | Type | Description |
| --- | --- | --- |
| ...plugins | <code>Array.&lt;WechatyPlugin&gt;</code> | The plugins you want to use |

**Example**  
```js
// Report all chat message to my server.

function WechatyReportPlugin(options: { url: string }) {
  return function (this: Wechaty) {
    this.on('message', message => http.post(options.url, { data: message }))
  }
}

bot.use(WechatyReportPlugin({ url: 'http://somewhere.to.report.your.data.com' })
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
367
<a name="Room"></a>
L
lijiarui 已提交
368

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
369
## Room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
370
All WeChat rooms(groups) will be encapsulated as a Room.
L
lijiarui 已提交
371

372
[Examples/Room-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/room-bot.ts)
L
lijiarui 已提交
373

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
374
**Kind**: global class  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
375
**Properties**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
376

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
377 378
| Name | Type | Description |
| --- | --- | --- |
379
| id | <code>string</code> | Room id. This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
380

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

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
382 383 384 385 386
* [Room](#Room)
    * _instance_
        * [.sync()](#Room+sync)<code>Promise.&lt;void&gt;</code>
        * [.say(textOrContactOrFileOrUrlOrMini, [mention])](#Room+say)<code>Promise.&lt;(void\|Message)&gt;</code>
        * [.add(contact)](#Room+add)<code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
387 388
        * [.remove(contact)](#Room+remove)<code>Promise.&lt;void&gt;</code>
        * ~~[.del()](#Room+del)~~
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
389 390 391
        * [.quit()](#Room+quit)<code>Promise.&lt;void&gt;</code>
        * [.topic([newTopic])](#Room+topic)<code>Promise.&lt;(string\|void)&gt;</code>
        * [.announce([text])](#Room+announce)<code>Promise.&lt;(void\|string)&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
392
        * [.qrCode()](#Room+qrCode)<code>Promise.&lt;string&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
393 394 395 396 397
        * [.alias(contact)](#Room+alias)<code>Promise.&lt;(string\|null)&gt;</code>
        * [.has(contact)](#Room+has)<code>Promise.&lt;boolean&gt;</code>
        * [.memberAll([query])](#Room+memberAll)<code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
        * [.member(queryArg)](#Room+member)<code>Promise.&lt;(null\|Contact)&gt;</code>
        * [.owner()](#Room+owner)[<code>Contact</code>](#Contact) \| <code>null</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
398
        * [.avatar()](#Room+avatar)<code>FileBox</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
399 400 401 402
    * _static_
        * [.create(contactList, [topic])](#Room.create)[<code>Promise.&lt;Room&gt;</code>](#Room)
        * [.findAll([query])](#Room.findAll)<code>Promise.&lt;Array.&lt;Room&gt;&gt;</code>
        * [.find(query)](#Room.find)<code>Promise.&lt;(Room\|null)&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
403

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
404
<a name="Room+sync"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
405

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
406
### room.sync() ⇒ <code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
407
Force reload data for Room, Sync data from puppet API again.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
408

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
409 410
**Kind**: instance method of [<code>Room</code>](#Room)  
**Example**  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
411
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
412
await room.sync()
413
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
414 415 416 417 418
<a name="Room+say"></a>

### room.say(textOrContactOrFileOrUrlOrMini, [mention]) ⇒ <code>Promise.&lt;(void\|Message)&gt;</code>
Send message inside Room, if set [replyTo], wechaty will mention the contact as well.
> Tips:
419
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
420 421 422 423 424 425 426 427 428

**Kind**: instance method of [<code>Room</code>](#Room)  

| Param | Type | Description |
| --- | --- | --- |
| textOrContactOrFileOrUrlOrMini | <code>string</code> \| [<code>Contact</code>](#Contact) \| <code>FileBox</code> | Send `text` or `media file` inside Room. <br> You can use [FileBox](https://www.npmjs.com/package/file-box) to send file |
| [mention] | [<code>Contact</code>](#Contact) \| [<code>Array.&lt;Contact&gt;</code>](#Contact) | Optional parameter, send content inside Room, and mention @replyTo contact or contactList. |

**Example**  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
429
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
430 431 432 433 434 435 436 437 438 439 440
const bot = new Wechaty()
await bot.start()
// after logged in...
const room = await bot.Room.find({topic: 'wechaty'})

// 1. Send text inside Room

await room.say('Hello world!')
const msg = await room.say('Hello world!') // only supported by puppet-padplus

// 2. Send media file inside Room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
441
import { FileBox }  from 'wechaty'
442
const fileBox1 = FileBox.fromUrl('https://wechaty.github.io/wechaty/images/bot-qr-code.png')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
const fileBox2 = FileBox.fromLocal('/tmp/text.txt')
await room.say(fileBox1)
const msg1 = await room.say(fileBox1) // only supported by puppet-padplus
await room.say(fileBox2)
const msg2 = await room.say(fileBox2) // only supported by puppet-padplus

// 3. Send Contact Card in a room
const contactCard = await bot.Contact.find({name: 'lijiarui'}) // change 'lijiarui' to any of the room member
await room.say(contactCard)
const msg = await room.say(contactCard) // only supported by puppet-padplus

// 4. Send text inside room and mention @mention contact
const contact = await bot.Contact.find({name: 'lijiarui'}) // change 'lijiarui' to any of the room member
await room.say('Hello world!', contact)
const msg = await room.say('Hello world!', contact) // only supported by puppet-padplus

// 5. Send text inside room and mention someone with Tagged Template
const contact2 = await bot.Contact.find({name: 'zixia'}) // change 'zixia' to any of the room member
await room.say`Hello ${contact}, here is the world ${contact2}`
const msg = await room.say`Hello ${contact}, here is the world ${contact2}` // only supported by puppet-padplus

// 6. send url link in a room

const urlLink = new UrlLink ({
  description : 'WeChat Bot SDK for Individual Account, Powered by TypeScript, Docker, and Love',
  thumbnailUrl: 'https://avatars0.githubusercontent.com/u/25162437?s=200&v=4',
  title       : 'Welcome to Wechaty',
470
  url         : 'https://github.com/wechaty/wechaty',
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
471 472 473 474 475 476 477 478 479 480 481 482 483
})
await room.say(urlLink)
const msg = await room.say(urlLink) // only supported by puppet-padplus

// 7. send mini program in a room

const miniProgram = new MiniProgram ({
  username           : 'gh_xxxxxxx',     //get from mp.weixin.qq.com
  appid              : '',               //optional, get from mp.weixin.qq.com
  title              : '',               //optional
  pagepath           : '',               //optional
  description        : '',               //optional
  thumbnailurl       : '',               //optional
484
})
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
485 486
await room.say(miniProgram)
const msg = await room.say(miniProgram) // only supported by puppet-padplus
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
487
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
488
<a name="Room+add"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
489

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
490 491
### room.add(contact) ⇒ <code>Promise.&lt;void&gt;</code>
Add contact in a room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
492

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
493
> Tips:
494
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
495
>
496
> see [Web version of WeChat closed group interface](https://github.com/wechaty/wechaty/issues/1441)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
497

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
498 499 500
**Kind**: instance method of [<code>Room</code>](#Room)  

| Param | Type |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
501
| --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
502
| contact | [<code>Contact</code>](#Contact) | 
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
503 504 505

**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
506 507 508
const bot = new Wechaty()
await bot.start()
// after logged in...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
509 510
const contact = await bot.Contact.find({name: 'lijiarui'}) // change 'lijiarui' to any contact in your WeChat
const room = await bot.Room.find({topic: 'WeChat'})        // change 'WeChat' to any room topic in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
511
if (room) {
512
  try {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
513 514 515
     await room.add(contact)
  } catch(e) {
     console.error(e)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
516
  }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
517
}
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
518
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
519
<a name="Room+remove"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
520

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
521 522
### room.remove(contact) ⇒ <code>Promise.&lt;void&gt;</code>
Remove a contact from the room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
523
It works only when the bot is the owner of the room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
524

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
525
> Tips:
526
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
527
>
528
> see [Web version of WeChat closed group interface](https://github.com/wechaty/wechaty/issues/1441)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
529

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
530
**Kind**: instance method of [<code>Room</code>](#Room)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
531

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
532 533 534
| Param | Type |
| --- | --- |
| contact | [<code>Contact</code>](#Contact) | 
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
535

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
536 537 538 539 540
**Example**  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
541
const room = await bot.Room.find({topic: 'WeChat'})          // change 'WeChat' to any room topic in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
542 543 544
const contact = await bot.Contact.find({name: 'lijiarui'})   // change 'lijiarui' to any room member in the room you just set
if (room) {
  try {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
545
     await room.remove(contact)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
546 547 548 549 550
  } catch(e) {
     console.error(e)
  }
}
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
551 552 553 554 555 556
<a name="Room+del"></a>

### ~~room.del()~~
***Deprecated***

**Kind**: instance method of [<code>Room</code>](#Room)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
557
<a name="Room+quit"></a>
558

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
559 560
### room.quit() ⇒ <code>Promise.&lt;void&gt;</code>
Bot quit the room itself
561

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
562
> Tips:
563
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
564

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
565
**Kind**: instance method of [<code>Room</code>](#Room)  
566 567
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
568 569 570
await room.quit()
```
<a name="Room+topic"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
571

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
572 573
### room.topic([newTopic]) ⇒ <code>Promise.&lt;(string\|void)&gt;</code>
SET/GET topic from the room
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
574

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
575
**Kind**: instance method of [<code>Room</code>](#Room)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
576

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
577 578 579
| Param | Type | Description |
| --- | --- | --- |
| [newTopic] | <code>string</code> | If set this para, it will change room topic. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
580

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
581 582 583 584 585 586 587 588 589
**Example** *(When you say anything in a room, it will get room topic. )*  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  const room = m.room()
  if (room) {
    const topic = await room.topic()
    console.log(`room topic is : ${topic}`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
590
  }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
591
})
592 593
.start()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
594
**Example** *(When you say anything in a room, it will change room topic. )*  
595 596
```js
const bot = new Wechaty()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
597 598 599 600 601 602 603
bot
.on('message', async m => {
  const room = m.room()
  if (room) {
    const oldTopic = await room.topic()
    await room.topic('change topic to wechaty!')
    console.log(`room topic change from ${oldTopic} to ${room.topic()}`)
604
  }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
605
})
606
.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
607
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
608
<a name="Room+announce"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
609

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
610 611 612 613
### room.announce([text]) ⇒ <code>Promise.&lt;(void\|string)&gt;</code>
SET/GET announce from the room
> Tips: It only works when bot is the owner of the room.
>
614
> This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
615

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
616 617 618 619 620 621 622
**Kind**: instance method of [<code>Room</code>](#Room)  

| Param | Type | Description |
| --- | --- | --- |
| [text] | <code>string</code> | If set this para, it will change room announce. |

**Example** *(When you say anything in a room, it will get room announce. )*  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
623
```js
624
const bot = new Wechaty()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
625 626 627 628 629
await bot.start()
// after logged in...
const room = await bot.Room.find({topic: 'your room'})
const announce = await room.announce()
console.log(`room announce is : ${announce}`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
630
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
631 632 633 634 635 636 637 638 639 640
**Example** *(When you say anything in a room, it will change room announce. )*  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
const room = await bot.Room.find({topic: 'your room'})
const oldAnnounce = await room.announce()
await room.announce('change announce to wechaty!')
console.log(`room announce change from ${oldAnnounce} to ${room.announce()}`)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
641
<a name="Room+qrCode"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
642

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
643
### room.qrCode() ⇒ <code>Promise.&lt;string&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
644
Get QR Code Value of the Room from the room, which can be used as scan and join the room.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
645
> Tips:
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
646 647
1. This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
2. The return should be the QR Code Data, instead of the QR Code Image. (the data should be less than 8KB. See: https://stackoverflow.com/a/12764370/1123955 )
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
648

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
649 650 651 652 653 654 655 656 657 658 659 660 661 662
**Kind**: instance method of [<code>Room</code>](#Room)  
<a name="Room+alias"></a>

### room.alias(contact) ⇒ <code>Promise.&lt;(string\|null)&gt;</code>
Return contact's roomAlias in the room

**Kind**: instance method of [<code>Room</code>](#Room)  
**Returns**: <code>Promise.&lt;(string\|null)&gt;</code> - - If a contact has an alias in room, return string, otherwise return null  

| Param | Type |
| --- | --- |
| contact | [<code>Contact</code>](#Contact) | 

**Example**  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
663
```js
664
const bot = new Wechaty()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
665 666 667 668 669 670 671
bot
.on('message', async m => {
  const room = m.room()
  const contact = m.from()
  if (room) {
    const alias = await room.alias(contact)
    console.log(`${contact.name()} alias is ${alias}`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
672
  }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
673
})
674
.start()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
675
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
676
<a name="Room+has"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
677

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
678 679
### room.has(contact) ⇒ <code>Promise.&lt;boolean&gt;</code>
Check if the room has member `contact`, the return is a Promise and must be `await`-ed
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
680

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
681 682
**Kind**: instance method of [<code>Room</code>](#Room)  
**Returns**: <code>Promise.&lt;boolean&gt;</code> - Return `true` if has contact, else return `false`.  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
683

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
684 685 686
| Param | Type |
| --- | --- |
| contact | [<code>Contact</code>](#Contact) | 
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
687

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
688 689 690 691 692
**Example** *(Check whether &#x27;lijiarui&#x27; is in the room &#x27;wechaty&#x27;)*  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
693 694
const contact = await bot.Contact.find({name: 'lijiarui'})   // change 'lijiarui' to any of contact in your WeChat
const room = await bot.Room.find({topic: 'wechaty'})         // change 'wechaty' to any of the room in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
695 696 697 698 699 700 701 702 703
if (contact && room) {
  if (await room.has(contact)) {
    console.log(`${contact.name()} is in the room wechaty!`)
  } else {
    console.log(`${contact.name()} is not in the room wechaty!`)
  }
}
```
<a name="Room+memberAll"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
704

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
705 706
### room.memberAll([query]) ⇒ <code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
Find all contacts in a room
707

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
708 709 710 711 712 713
#### definition
- `name`                 the name-string set by user-self, should be called name, equal to `Contact.name()`
- `roomAlias`            the name-string set by user-self in the room, should be called roomAlias
- `contactAlias`         the name-string set by bot for others, should be called alias, equal to `Contact.alias()`

**Kind**: instance method of [<code>Room</code>](#Room)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
714

715 716
| Param | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
717
| [query] | [<code>RoomMemberQueryFilter</code>](#RoomMemberQueryFilter) \| <code>string</code> | Optional parameter, When use memberAll(name:string), return all matched members, including name, roomAlias, contactAlias |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
718

719 720
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
721
const roomList:Contact[] | null = await room.findAll()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
722 723
if(roomList)
 console.log(`room all member list: `, roomList)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
724
const memberContactList: Contact[] | null =await room.findAll(`abc`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
console.log(`contact list with all name, room alias, alias are abc:`, memberContactList)
```
<a name="Room+member"></a>

### room.member(queryArg) ⇒ <code>Promise.&lt;(null\|Contact)&gt;</code>
Find all contacts in a room, if get many, return the first one.

**Kind**: instance method of [<code>Room</code>](#Room)  

| Param | Type | Description |
| --- | --- | --- |
| queryArg | [<code>RoomMemberQueryFilter</code>](#RoomMemberQueryFilter) \| <code>string</code> | When use member(name:string), return all matched members, including name, roomAlias, contactAlias |

**Example** *(Find member by name)*  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
743
const room = await bot.Room.find({topic: 'wechaty'})           // change 'wechaty' to any room name in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
744
if (room) {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
745
  const member = await room.member('lijiarui')             // change 'lijiarui' to any room member in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
746 747 748 749 750 751 752 753 754 755 756 757
  if (member) {
    console.log(`wechaty room got the member: ${member.name()}`)
  } else {
    console.log(`cannot get member in wechaty room!`)
  }
}
```
**Example** *(Find member by MemberQueryFilter)*  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
758
const room = await bot.Room.find({topic: 'wechaty'})          // change 'wechaty' to any room name in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
759
if (room) {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
760
  const member = await room.member({name: 'lijiarui'})        // change 'lijiarui' to any room member in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
761 762 763 764 765 766 767 768 769 770 771 772
  if (member) {
    console.log(`wechaty room got the member: ${member.name()}`)
  } else {
    console.log(`cannot get member in wechaty room!`)
  }
}
```
<a name="Room+owner"></a>

### room.owner() ⇒ [<code>Contact</code>](#Contact) \| <code>null</code>
Get room's owner from the room.
> Tips:
773
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
774 775 776 777 778 779

**Kind**: instance method of [<code>Room</code>](#Room)  
**Example**  
```js
const owner = room.owner()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
780 781 782 783 784 785 786 787 788 789 790 791
<a name="Room+avatar"></a>

### room.avatar() ⇒ <code>FileBox</code>
Get avatar from the room.

**Kind**: instance method of [<code>Room</code>](#Room)  
**Example**  
```js
const fileBox = await room.avatar()
const name = fileBox.name
fileBox.toFile(name)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
792 793 794 795 796 797 798 799 800 801 802 803
<a name="Room.create"></a>

### Room.create(contactList, [topic]) ⇒ [<code>Promise.&lt;Room&gt;</code>](#Room)
Create a new room.

**Kind**: static method of [<code>Room</code>](#Room)  

| Param | Type |
| --- | --- |
| contactList | [<code>Array.&lt;Contact&gt;</code>](#Contact) | 
| [topic] | <code>string</code> | 

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
804
**Example** *(Creat a room with &#x27;lijiarui&#x27; and &#x27;huan&#x27;, the room topic is &#x27;ding - created&#x27;)*  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
805
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
806 807
const helperContactA = await Contact.find({ name: 'lijiarui' })  // change 'lijiarui' to any contact in your WeChat
const helperContactB = await Contact.find({ name: 'huan' })  // change 'huan' to any contact in your WeChat
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
const contactList = [helperContactA, helperContactB]
console.log('Bot', 'contactList: %s', contactList.join(','))
const room = await Room.create(contactList, 'ding')
console.log('Bot', 'createDingRoom() new ding room created: %s', room)
await room.topic('ding - created')
await room.say('ding - created')
```
<a name="Room.findAll"></a>

### Room.findAll([query]) ⇒ <code>Promise.&lt;Array.&lt;Room&gt;&gt;</code>
Find room by by filter: {topic: string | RegExp}, return all the matched room

**Kind**: static method of [<code>Room</code>](#Room)  

| Param | Type |
| --- | --- |
| [query] | [<code>RoomQueryFilter</code>](#RoomQueryFilter) | 

**Example**  
```js
const bot = new Wechaty()
await bot.start()
// after logged in
const roomList = await bot.Room.findAll()                    // get the room list of the bot
const roomList = await bot.Room.findAll({topic: 'wechaty'})  // find all of the rooms with name 'wechaty'
```
<a name="Room.find"></a>

### Room.find(query) ⇒ <code>Promise.&lt;(Room\|null)&gt;</code>
Try to find a room by filter: {topic: string | RegExp}. If get many, return the first one.

**Kind**: static method of [<code>Room</code>](#Room)  
**Returns**: <code>Promise.&lt;(Room\|null)&gt;</code> - If can find the room, return Room, or return null  

| Param | Type |
| --- | --- |
| query | [<code>RoomQueryFilter</code>](#RoomQueryFilter) | 

**Example**  
```js
const bot = new Wechaty()
await bot.start()
// after logged in...
const roomList = await bot.Room.find()
const roomList = await bot.Room.find({topic: 'wechaty'})
```
<a name="Contact"></a>

## Contact
All wechat contacts(friend) will be encapsulated as a Contact.
858
[Examples/Contact-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/contact-bot.ts)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
859 860 861 862 863 864

**Kind**: global class  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
865
| id | <code>string</code> | Get Contact id. This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
866 867 868 869 870 871 872 873 874 875 876 877 878


* [Contact](#Contact)
    * _instance_
        * [.say(something)](#Contact+say)<code>Promise.&lt;(void\|Message)&gt;</code>
        * [.name()](#Contact+name)<code>string</code>
        * [.alias(newAlias)](#Contact+alias)<code>Promise.&lt;(null\|string\|void)&gt;</code>
        * [.friend()](#Contact+friend)<code>boolean</code> \| <code>null</code>
        * [.type()](#Contact+type)<code>ContactType.Unknown</code> \| <code>ContactType.Personal</code> \| <code>ContactType.Official</code>
        * [.gender()](#Contact+gender)<code>ContactGender.Unknown</code> \| <code>ContactGender.Male</code> \| <code>ContactGender.Female</code>
        * [.province()](#Contact+province)<code>string</code> \| <code>null</code>
        * [.city()](#Contact+city)<code>string</code> \| <code>null</code>
        * [.avatar()](#Contact+avatar)<code>Promise.&lt;FileBox&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
879
        * [.tags()](#Contact+tags)<code>Promise.&lt;Array.&lt;Tag&gt;&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
880 881 882 883 884
        * [.sync()](#Contact+sync)<code>Promise.&lt;this&gt;</code>
        * [.self()](#Contact+self)<code>boolean</code>
    * _static_
        * [.find(query)](#Contact.find)<code>Promise.&lt;(Contact\|null)&gt;</code>
        * [.findAll([queryArg])](#Contact.findAll)<code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
885
        * [.tags()](#Contact.tags)<code>Promise.&lt;Array.&lt;Tag&gt;&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
886 887 888 889 890

<a name="Contact+say"></a>

### contact.say(something) ⇒ <code>Promise.&lt;(void\|Message)&gt;</code>
> Tips:
891
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911

**Kind**: instance method of [<code>Contact</code>](#Contact)  

| Param | Type | Description |
| --- | --- | --- |
| something | <code>string</code> \| [<code>Contact</code>](#Contact) \| <code>FileBox</code> \| <code>UrlLink</code> \| <code>MiniProgram</code> | send text, Contact, or file to contact. </br> You can use [FileBox](https://www.npmjs.com/package/file-box) to send file |

**Example**  
```js
const bot = new Wechaty()
await bot.start()
const contact = await bot.Contact.find({name: 'lijiarui'})  // change 'lijiarui' to any of your contact name in wechat

// 1. send text to contact

await contact.say('welcome to wechaty!')
const msg = await contact.say('welcome to wechaty!') // only supported by puppet-padplus

// 2. send media file to contact

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
912
import { FileBox }  from 'wechaty'
913
const fileBox1 = FileBox.fromUrl('https://wechaty.github.io/wechaty/images/bot-qr-code.png')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
const fileBox2 = FileBox.fromFile('/tmp/text.txt')
await contact.say(fileBox1)
const msg1 = await contact.say(fileBox1) // only supported by puppet-padplus
await contact.say(fileBox2)
const msg2 = await contact.say(fileBox2) // only supported by puppet-padplus

// 3. send contact card to contact

const contactCard = bot.Contact.load('contactId')
const msg = await contact.say(contactCard) // only supported by puppet-padplus

// 4. send url link to contact

const urlLink = new UrlLink ({
  description : 'WeChat Bot SDK for Individual Account, Powered by TypeScript, Docker, and Love',
  thumbnailUrl: 'https://avatars0.githubusercontent.com/u/25162437?s=200&v=4',
  title       : 'Welcome to Wechaty',
931
  url         : 'https://github.com/wechaty/wechaty',
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
})
await contact.say(urlLink)
const msg = await contact.say(urlLink) // only supported by puppet-padplus

// 5. send mini program to contact

const miniProgram = new MiniProgram ({
  username           : 'gh_xxxxxxx',     //get from mp.weixin.qq.com
  appid              : '',               //optional, get from mp.weixin.qq.com
  title              : '',               //optional
  pagepath           : '',               //optional
  description        : '',               //optional
  thumbnailurl       : '',               //optional
})
await contact.say(miniProgram)
const msg = await contact.say(miniProgram) // only supported by puppet-padplus
```
<a name="Contact+name"></a>

### contact.name() ⇒ <code>string</code>
Get the name from a contact

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const name = contact.name()
```
<a name="Contact+alias"></a>

### contact.alias(newAlias) ⇒ <code>Promise.&lt;(null\|string\|void)&gt;</code>
GET / SET / DELETE the alias for a contact

Tests show it will failed if set alias too frequently(60 times in one minute).

**Kind**: instance method of [<code>Contact</code>](#Contact)  

| Param | Type |
| --- | --- |
| newAlias | <code>none</code> \| <code>string</code> \| <code>null</code> | 

**Example** *( GET the alias for a contact, return {(Promise&lt;string | null&gt;)})*  
```js
const alias = await contact.alias()
if (alias === null) {
  console.log('You have not yet set any alias for contact ' + contact.name())
} else {
  console.log('You have already set an alias for contact ' + contact.name() + ':' + alias)
}
```
**Example** *(SET the alias for a contact)*  
```js
try {
  await contact.alias('lijiarui')
  console.log(`change ${contact.name()}'s alias successfully!`)
} catch (e) {
  console.log(`failed to change ${contact.name()} alias!`)
}
```
**Example** *(DELETE the alias for a contact)*  
```js
try {
  const oldAlias = await contact.alias(null)
  console.log(`delete ${contact.name()}'s alias successfully!`)
  console.log('old alias is ${oldAlias}`)
} catch (e) {
  console.log(`failed to delete ${contact.name()}'s alias!`)
}
```
<a name="Contact+friend"></a>

### contact.friend() ⇒ <code>boolean</code> \| <code>null</code>
Check if contact is friend

> Tips:
1006
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Returns**: <code>boolean</code> \| <code>null</code> - <br>True for friend of the bot <br>
False for not friend of the bot, null for unknown.  
**Example**  
```js
const isFriend = contact.friend()
```
<a name="Contact+type"></a>

### contact.type() ⇒ <code>ContactType.Unknown</code> \| <code>ContactType.Personal</code> \| <code>ContactType.Official</code>
Return the type of the Contact
> Tips: ContactType is enum here.</br>

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const bot = new Wechaty()
await bot.start()
const isOfficial = contact.type() === bot.Contact.Type.Official
```
<a name="Contact+gender"></a>

### contact.gender() ⇒ <code>ContactGender.Unknown</code> \| <code>ContactGender.Male</code> \| <code>ContactGender.Female</code>
Contact gender
> Tips: ContactGender is enum here. </br>

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const gender = contact.gender() === bot.Contact.Gender.Male
```
<a name="Contact+province"></a>

### contact.province() ⇒ <code>string</code> \| <code>null</code>
Get the region 'province' from a contact

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const province = contact.province()
```
<a name="Contact+city"></a>

### contact.city() ⇒ <code>string</code> \| <code>null</code>
Get the region 'city' from a contact

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const city = contact.city()
```
<a name="Contact+avatar"></a>

### contact.avatar() ⇒ <code>Promise.&lt;FileBox&gt;</code>
Get avatar picture file stream

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
// Save avatar to local file like `1-name.jpg`

const file = await contact.avatar()
const name = file.name
await file.toFile(name, true)
console.log(`Contact: ${contact.name()} with avatar file: ${name}`)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
<a name="Contact+tags"></a>

### contact.tags() ⇒ <code>Promise.&lt;Array.&lt;Tag&gt;&gt;</code>
Get all tags of contact

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const tags = await contact.tags()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1084 1085 1086
<a name="Contact+sync"></a>

### contact.sync() ⇒ <code>Promise.&lt;this&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1087
Force reload data for Contact, Sync data from low-level API again.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Example**  
```js
await contact.sync()
```
<a name="Contact+self"></a>

### contact.self() ⇒ <code>boolean</code>
Check if contact is self

**Kind**: instance method of [<code>Contact</code>](#Contact)  
**Returns**: <code>boolean</code> - True for contact is self, False for contact is others  
**Example**  
```js
const isSelf = contact.self()
```
<a name="Contact.find"></a>

### Contact.find(query) ⇒ <code>Promise.&lt;(Contact\|null)&gt;</code>
Try to find a contact by filter: {name: string | RegExp} / {alias: string | RegExp}

Find contact by name or alias, if the result more than one, return the first one.

**Kind**: static method of [<code>Contact</code>](#Contact)  
**Returns**: <code>Promise.&lt;(Contact\|null)&gt;</code> - If can find the contact, return Contact, or return null  

| Param | Type |
| --- | --- |
| query | [<code>ContactQueryFilter</code>](#ContactQueryFilter) | 

**Example**  
```js
const bot = new Wechaty()
await bot.start()
const contactFindByName = await bot.Contact.find({ name:"ruirui"} )
const contactFindByAlias = await bot.Contact.find({ alias:"lijiarui"} )
```
<a name="Contact.findAll"></a>

### Contact.findAll([queryArg]) ⇒ <code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
Find contact by `name` or `alias`

If use Contact.findAll() get the contact list of the bot.

#### definition
- `name`   the name-string set by user-self, should be called name
- `alias`  the name-string set by bot for others, should be called alias

**Kind**: static method of [<code>Contact</code>](#Contact)  

| Param | Type |
| --- | --- |
| [queryArg] | [<code>ContactQueryFilter</code>](#ContactQueryFilter) | 

**Example**  
```js
const bot = new Wechaty()
await bot.start()
const contactList = await bot.Contact.findAll()                      // get the contact list of the bot
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1148
const contactList = await bot.Contact.findAll({ name: 'ruirui' })    // find all of the contacts whose name is 'ruirui'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1149 1150
const contactList = await bot.Contact.findAll({ alias: 'lijiarui' }) // find all of the contacts whose alias is 'lijiarui'
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
<a name="Contact.tags"></a>

### Contact.tags() ⇒ <code>Promise.&lt;Array.&lt;Tag&gt;&gt;</code>
Get tags for all contact

**Kind**: static method of [<code>Contact</code>](#Contact)  
**Example**  
```js
const tags = await wechaty.Contact.tags()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
<a name="ContactSelf"></a>

## ContactSelf
Bot itself will be encapsulated as a ContactSelf.

> Tips: this class is extends Contact

**Kind**: global class  

* [ContactSelf](#ContactSelf)
    * [.avatar([file])](#ContactSelf+avatar)<code>Promise.&lt;(void\|FileBox)&gt;</code>
    * [.qrcode()](#ContactSelf+qrcode)<code>Promise.&lt;string&gt;</code>
    * [.signature(signature)](#ContactSelf+signature)

<a name="ContactSelf+avatar"></a>

### contactSelf.avatar([file]) ⇒ <code>Promise.&lt;(void\|FileBox)&gt;</code>
GET / SET bot avatar

**Kind**: instance method of [<code>ContactSelf</code>](#ContactSelf)  

| Param | Type |
| --- | --- |
| [file] | <code>FileBox</code> | 

**Example** *( GET the avatar for bot, return {Promise&lt;FileBox&gt;})*  
```js
// Save avatar to local file like `1-name.jpg`

bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
  const file = await user.avatar()
  const name = file.name
  await file.toFile(name, true)
  console.log(`Save bot avatar: ${contact.name()} with avatar file: ${name}`)
})
```
**Example** *(SET the avatar for a bot)*  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1200
import { FileBox }  from 'wechaty'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1201 1202
bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
1203
  const fileBox = FileBox.fromUrl('https://wechaty.github.io/wechaty/images/bot-qr-code.png')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
  await user.avatar(fileBox)
  console.log(`Change bot avatar successfully!`)
})
```
<a name="ContactSelf+qrcode"></a>

### contactSelf.qrcode() ⇒ <code>Promise.&lt;string&gt;</code>
Get bot qrcode

**Kind**: instance method of [<code>ContactSelf</code>](#ContactSelf)  
**Example**  
```js
import { generate } from 'qrcode-terminal'
bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
  const qrcode = await user.qrcode()
  console.log(`Following is the bot qrcode!`)
  generate(qrcode, { small: true })
})
```
<a name="ContactSelf+signature"></a>

### contactSelf.signature(signature)
Change bot signature

**Kind**: instance method of [<code>ContactSelf</code>](#ContactSelf)  

| Param | Description |
| --- | --- |
| signature | The new signature that the bot will change to |

**Example**  
```js
bot.on('login', async user => {
  console.log(`user ${user} login`)
  try {
    await user.signature(`Signature changed by wechaty on ${new Date()}`)
  } catch (e) {
    console.error('change signature failed', e)
  }
})
```
<a name="Friendship"></a>

## Friendship
Send, receive friend request, and friend confirmation events.

1. send request
2. receive request(in friend event)
3. confirmation friendship(friend event)

1255
[Examples/Friend-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1256 1257 1258 1259 1260 1261 1262 1263 1264

**Kind**: global class  

* [Friendship](#Friendship)
    * _instance_
        * [.accept()](#Friendship+accept)<code>Promise.&lt;void&gt;</code>
        * [.hello()](#Friendship+hello)<code>string</code>
        * [.contact()](#Friendship+contact)[<code>Contact</code>](#Contact)
        * [.type()](#Friendship+type)<code>FriendshipType</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1265
        * [.toJSON()](#Friendship+toJSON)<code>FriendshipPayload</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1266
    * _static_
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1267
        * [.search(condition)](#Friendship.search)[<code>Promise.&lt;Contact&gt;</code>](#Contact)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1268
        * [.add(contact, options)](#Friendship.add)<code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1269
        * [.fromJSON()](#Friendship.fromJSON)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364

<a name="Friendship+accept"></a>

### friendship.accept() ⇒ <code>Promise.&lt;void&gt;</code>
Accept Friend Request

**Kind**: instance method of [<code>Friendship</code>](#Friendship)  
**Example**  
```js
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    console.log(`received friend event.`)
    switch (friendship.type()) {

    // 1. New Friend Request

    case Friendship.Type.Receive:
      await friendship.accept()
      break

    // 2. Friend Ship Confirmed

    case Friendship.Type.Confirm:
      console.log(`friend ship confirmed`)
      break
    }
  } catch (e) {
    console.error(e)
  }
}
.start()
```
<a name="Friendship+hello"></a>

### friendship.hello() ⇒ <code>string</code>
Get verify message from

**Kind**: instance method of [<code>Friendship</code>](#Friendship)  
**Example** *(If request content is &#x60;ding&#x60;, then accept the friendship)*  
```js
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    console.log(`received friend event from ${friendship.contact().name()}`)
    if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
      await friendship.accept()
    }
  } catch (e) {
    console.error(e)
  }
}
.start()
```
<a name="Friendship+contact"></a>

### friendship.contact() ⇒ [<code>Contact</code>](#Contact)
Get the contact from friendship

**Kind**: instance method of [<code>Friendship</code>](#Friendship)  
**Example**  
```js
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  const contact = friendship.contact()
  const name = contact.name()
  console.log(`received friend event from ${name}`)
}
.start()
```
<a name="Friendship+type"></a>

### friendship.type() ⇒ <code>FriendshipType</code>
Return the Friendship Type
> Tips: FriendshipType is enum here. </br>
- FriendshipType.Unknown  </br>
- FriendshipType.Confirm  </br>
- FriendshipType.Receive  </br>
- FriendshipType.Verify   </br>

**Kind**: instance method of [<code>Friendship</code>](#Friendship)  
**Example** *(If request content is &#x60;ding&#x60;, then accept the friendship)*  
```js
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
      await friendship.accept()
    }
  } catch (e) {
    console.error(e)
  }
}
.start()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
<a name="Friendship+toJSON"></a>

### friendship.toJSON() ⇒ <code>FriendshipPayload</code>
get friendShipPayload Json

**Kind**: instance method of [<code>Friendship</code>](#Friendship)  
**Example**  
```js
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    // JSON.stringify(friendship) as well.
    const payload = await friendship.toJSON()
  } catch (e) {
    console.error(e)
  }
}
.start()
```
<a name="Friendship.search"></a>

### Friendship.search(condition) ⇒ [<code>Promise.&lt;Contact&gt;</code>](#Contact)
Search a Friend by phone or weixin.

The best practice is to search friend request once per minute.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1390
Remember not to do this too frequently, or your account may be blocked.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405

**Kind**: static method of [<code>Friendship</code>](#Friendship)  

| Param | Type | Description |
| --- | --- | --- |
| condition | <code>FriendshipSearchCondition</code> | Search friend by phone or weixin. |

**Example**  
```js
const friend_phone = await bot.Friendship.search({phone: '13112341234'})
const friend_weixin = await bot.Friendship.search({weixin: 'weixin_account'})

console.log(`This is the new friend info searched by phone : ${friend_phone}`)
await bot.Friendship.add(friend_phone, 'hello')
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1406 1407
<a name="Friendship.add"></a>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1408
### Friendship.add(contact, options) ⇒ <code>Promise.&lt;void&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
Send a Friend Request to a `contact` with message `hello`.

The best practice is to send friend request once per minute.
Remeber not to do this too frequently, or your account may be blocked.

**Kind**: static method of [<code>Friendship</code>](#Friendship)  

| Param | Type | Description |
| --- | --- | --- |
| contact | [<code>Contact</code>](#Contact) | Send friend request to contact |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1419
| options | <code>FriendshipAddOptions</code> | The friend request content |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1420 1421 1422

**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1423 1424 1425
const contact = await bot.Friendship.search({phone: '13112341234'})
await bot.Friendship.add(contact, 'Nice to meet you! I am wechaty bot!')

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1426 1427
const memberList = await room.memberList()
for (let i = 0; i < memberList.length; i++) {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1428 1429 1430 1431
  await bot.Friendship.add(member, {
    room: room,
    hello: `Nice to meet you! I am wechaty bot from room: ${await room.topic()}!`,
  })
1432 1433
}
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
<a name="Friendship.fromJSON"></a>

### Friendship.fromJSON()
create friendShip by friendshipJson

**Kind**: static method of [<code>Friendship</code>](#Friendship)  
**Example**  
```js
const bot = new Wechaty()
bot.start()

const payload = '{...}'  // your saved JSON payload
const friendship = bot.FriendShip.fromJSON(friendshipFromDisk)
await friendship.accept()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1449 1450 1451 1452 1453
<a name="Message"></a>

## Message
All wechat messages will be encapsulated as a Message.

1454
[Examples/Ding-Dong-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/ding-dong-bot.ts)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1455 1456 1457 1458 1459

**Kind**: global class  

* [Message](#Message)
    * _instance_
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1460 1461
        * [.talker()](#Message+talker)[<code>Contact</code>](#Contact)
        * [.from()](#Message+from)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1462 1463 1464 1465 1466
        * [.to()](#Message+to)[<code>Contact</code>](#Contact) \| <code>null</code>
        * [.room()](#Message+room)[<code>Room</code>](#Room) \| <code>null</code>
        * [.text()](#Message+text)<code>string</code>
        * [.toRecalled()](#Message+toRecalled)
        * [.say(textOrContactOrFile, [mention])](#Message+say)<code>Promise.&lt;(void\|Message)&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1467
        * [.recall()](#Message+recall)<code>Promise.&lt;boolean&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1468 1469
        * [.type()](#Message+type)<code>MessageType</code>
        * [.self()](#Message+self)<code>boolean</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1470
        * [.mentionList()](#Message+mentionList)<code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1471
        * ~~[.mention()](#Message+mention)~~
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1472 1473 1474 1475 1476
        * [.mentionSelf()](#Message+mentionSelf)<code>Promise.&lt;boolean&gt;</code>
        * [.forward(to)](#Message+forward)<code>Promise.&lt;void&gt;</code>
        * [.date()](#Message+date)
        * [.age()](#Message+age)<code>number</code>
        * [.toFileBox()](#Message+toFileBox)<code>Promise.&lt;FileBox&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1477
        * [.toImage()](#Message+toImage)<code>Image</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1478 1479 1480 1481 1482
        * [.toContact()](#Message+toContact)[<code>Promise.&lt;Contact&gt;</code>](#Contact)
    * _static_
        * [.find()](#Message.find)
        * [.findAll()](#Message.findAll)

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1483
<a name="Message+talker"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1484

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1485 1486
### message.talker() ⇒ [<code>Contact</code>](#Contact)
Get the talker of a message.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1487 1488 1489 1490 1491 1492 1493

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1494
  const talker = msg.talker()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1495 1496 1497 1498
  const text = msg.text()
  const room = msg.room()
  if (room) {
    const topic = await room.topic()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1499
    console.log(`Room: ${topic} Contact: ${talker.name()} Text: ${text}`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1500
  } else {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1501
    console.log(`Contact: ${talker.name()} Text: ${text}`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1502 1503 1504 1505
  }
})
.start()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1506 1507 1508 1509 1510 1511
<a name="Message+from"></a>

### message.from()
**Kind**: instance method of [<code>Message</code>](#Message)  
**Depreacated**: Use `message.talker()` to replace `message.from()`
 https://github.com/wechaty/wechaty/issues/2094  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
<a name="Message+to"></a>

### message.to() ⇒ [<code>Contact</code>](#Contact) \| <code>null</code>
Get the destination of the message
Message.to() will return null if a message is in a room, use Message.room() to get the room.

**Kind**: instance method of [<code>Message</code>](#Message)  
<a name="Message+room"></a>

### message.room() ⇒ [<code>Room</code>](#Room) \| <code>null</code>
Get the room from the message.
If the message is not in a room, then will return `null`

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  const contact = msg.from()
  const text = msg.text()
  const room = msg.room()
  if (room) {
    const topic = await room.topic()
    console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`)
  } else {
    console.log(`Contact: ${contact.name()} Text: ${text}`)
  }
})
.start()
```
<a name="Message+text"></a>

### message.text() ⇒ <code>string</code>
Get the text content of the message

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  const contact = msg.from()
  const text = msg.text()
  const room = msg.room()
  if (room) {
    const topic = await room.topic()
    console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`)
  } else {
    console.log(`Contact: ${contact.name()} Text: ${text}`)
  }
})
.start()
```
<a name="Message+toRecalled"></a>

### message.toRecalled()
Get the recalled message

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  if (m.type() === MessageType.Recalled) {
    const recalledMessage = await m.toRecalled()
    console.log(`Message: ${recalledMessage} has been recalled.`)
  }
})
.start()
```
<a name="Message+say"></a>

### message.say(textOrContactOrFile, [mention]) ⇒ <code>Promise.&lt;(void\|Message)&gt;</code>
Reply a Text or Media File message to the sender.
> Tips:
1589
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1590 1591

**Kind**: instance method of [<code>Message</code>](#Message)  
1592
**See**: [Examples/ding-dong-bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/ding-dong-bot.ts)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1593 1594 1595 1596 1597 1598 1599 1600

| Param | Type | Description |
| --- | --- | --- |
| textOrContactOrFile | <code>string</code> \| [<code>Contact</code>](#Contact) \| <code>FileBox</code> \| <code>UrlLink</code> \| <code>MiniProgram</code> | send text, Contact, or file to bot. </br> You can use [FileBox](https://www.npmjs.com/package/file-box) to send file |
| [mention] | [<code>Contact</code>](#Contact) \| [<code>Array.&lt;Contact&gt;</code>](#Contact) | If this is a room message, when you set mention param, you can `@` Contact in the room. |

**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1601
import { FileBox }  from 'wechaty'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1602 1603 1604 1605 1606 1607 1608
const bot = new Wechaty()
bot
.on('message', async m => {

// 1. send Image

  if (/^ding$/i.test(m.text())) {
1609
    const fileBox = FileBox.fromUrl('https://wechaty.github.io/wechaty/images/bot-qr-code.png')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1610 1611 1612 1613 1614 1615 1616
    await msg.say(fileBox)
    const message = await msg.say(fileBox) // only supported by puppet-padplus
  }

// 2. send Text

  if (/^dong$/i.test(m.text())) {
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1617 1618
    await msg.say('ding')
    const message = await msg.say('ding') // only supported by puppet-padplus
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
  }

// 3. send Contact

  if (/^lijiarui$/i.test(m.text())) {
    const contactCard = await bot.Contact.find({name: 'lijiarui'})
    if (!contactCard) {
      console.log('not found')
      return
    }
    await msg.say(contactCard)
    const message = await msg.say(contactCard) // only supported by puppet-padplus
  }

// 4. send Link

  if (/^link$/i.test(m.text())) {
    const linkPayload = new UrlLink ({
      description : 'WeChat Bot SDK for Individual Account, Powered by TypeScript, Docker, and Love',
      thumbnailUrl: 'https://avatars0.githubusercontent.com/u/25162437?s=200&v=4',
      title       : 'Welcome to Wechaty',
1640
      url         : 'https://github.com/wechaty/wechaty',
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663
    })
    await msg.say(linkPayload)
    const message = await msg.say(linkPayload) // only supported by puppet-padplus
  }

// 5. send MiniProgram

  if (/^link$/i.test(m.text())) {
    const miniProgramPayload = new MiniProgram ({
      username           : 'gh_xxxxxxx',     //get from mp.weixin.qq.com
      appid              : '',               //optional, get from mp.weixin.qq.com
      title              : '',               //optional
      pagepath           : '',               //optional
      description        : '',               //optional
      thumbnailurl       : '',               //optional
    })
    await msg.say(miniProgramPayload)
    const message = await msg.say(miniProgramPayload) // only supported by puppet-padplus
  }

})
.start()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
<a name="Message+recall"></a>

### message.recall() ⇒ <code>Promise.&lt;boolean&gt;</code>
Recall a message.
> Tips:

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  const recallMessage = await msg.say('123')
  if (recallMessage) {
    const isSuccess = await recallMessage.recall()
  }
})
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
<a name="Message+type"></a>

### message.type() ⇒ <code>MessageType</code>
Get the type from the message.
> Tips: MessageType is Enum here. </br>
- MessageType.Unknown     </br>
- MessageType.Attachment  </br>
- MessageType.Audio       </br>
- MessageType.Contact     </br>
- MessageType.Emoticon    </br>
- MessageType.Image       </br>
- MessageType.Text        </br>
- MessageType.Video       </br>
- MessageType.Url         </br>

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example**  
```js
const bot = new Wechaty()
if (message.type() === bot.Message.Type.Text) {
  console.log('This is a text message')
}
```
<a name="Message+self"></a>

### message.self() ⇒ <code>boolean</code>
Check if a message is sent by self.

**Kind**: instance method of [<code>Message</code>](#Message)  
**Returns**: <code>boolean</code> - - Return `true` for send from self, `false` for send from others.  
**Example**  
```js
if (message.self()) {
 console.log('this message is sent by myself!')
}
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1718
<a name="Message+mentionList"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1719

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1720
### message.mentionList() ⇒ <code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
Get message mentioned contactList.

Message event table as follows

|                                                                            | Web  |  Mac PC Client | iOS Mobile |  android Mobile |
| :---                                                                       | :--: |     :----:     |   :---:    |     :---:       |
| [You were mentioned] tip ([有人@我]的提示)                                   |  ✘   |        √       |     √      |       √         |
| Identify magic code (8197) by copy & paste in mobile                       |  ✘   |        √       |     √      |       ✘         |
| Identify magic code (8197) by programming                                  |  ✘   |        ✘       |     ✘      |       ✘         |
| Identify two contacts with the same roomAlias by [You were  mentioned] tip |  ✘   |        ✘       |     √      |       √         |

**Kind**: instance method of [<code>Message</code>](#Message)  
**Returns**: <code>Promise.&lt;Array.&lt;Contact&gt;&gt;</code> - - Return message mentioned contactList  
**Example**  
```js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1736
const contactList = await message.mentionList()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1737 1738
console.log(contactList)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1739 1740 1741 1742 1743 1744
<a name="Message+mention"></a>

### ~~message.mention()~~
***Deprecated***

**Kind**: instance method of [<code>Message</code>](#Message)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797
<a name="Message+mentionSelf"></a>

### message.mentionSelf() ⇒ <code>Promise.&lt;boolean&gt;</code>
Check if a message is mention self.

**Kind**: instance method of [<code>Message</code>](#Message)  
**Returns**: <code>Promise.&lt;boolean&gt;</code> - - Return `true` for mention me.  
**Example**  
```js
if (await message.mentionSelf()) {
 console.log('this message were mentioned me! [You were mentioned] tip ([有人@我]的提示)')
}
```
<a name="Message+forward"></a>

### message.forward(to) ⇒ <code>Promise.&lt;void&gt;</code>
Forward the received message.

**Kind**: instance method of [<code>Message</code>](#Message)  

| Param | Type | Description |
| --- | --- | --- |
| to | <code>Sayable</code> \| <code>Array.&lt;Sayable&gt;</code> | Room or Contact The recipient of the message, the room, or the contact |

**Example**  
```js
const bot = new Wechaty()
bot
.on('message', async m => {
  const room = await bot.Room.find({topic: 'wechaty'})
  if (room) {
    await m.forward(room)
    console.log('forward this message to wechaty room!')
  }
})
.start()
```
<a name="Message+date"></a>

### message.date()
Message sent date

**Kind**: instance method of [<code>Message</code>](#Message)  
<a name="Message+age"></a>

### message.age() ⇒ <code>number</code>
Returns the message age in seconds. <br>

For example, the message is sent at time `8:43:01`,
and when we received it in Wechaty, the time is `8:43:15`,
then the age() will return `8:43:15 - 8:43:01 = 14 (seconds)`

**Kind**: instance method of [<code>Message</code>](#Message)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1798
**Returns**: <code>number</code> - message age in seconds.  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1799 1800 1801 1802 1803
<a name="Message+toFileBox"></a>

### message.toFileBox() ⇒ <code>Promise.&lt;FileBox&gt;</code>
Extract the Media File from the Message, and put it into the FileBox.
> Tips:
1804
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1805 1806 1807 1808 1809 1810 1811 1812

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example** *(Save media file from a message)*  
```js
const fileBox = await message.toFileBox()
const fileName = fileBox.name
fileBox.toFile(fileName)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
<a name="Message+toImage"></a>

### message.toImage() ⇒ <code>Image</code>
Extract the Image File from the Message, so that we can use different image sizes.
> Tips:
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)

**Kind**: instance method of [<code>Message</code>](#Message)  
**Example** *(Save image file from a message)*  
```js
const image = message.toImage()
const fileBox = await image.artwork()
const fileName = fileBox.name
fileBox.toFile(fileName)
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1828 1829 1830 1831 1832 1833
<a name="Message+toContact"></a>

### message.toContact() ⇒ [<code>Promise.&lt;Contact&gt;</code>](#Contact)
Get Share Card of the Message
Extract the Contact Card from the Message, and encapsulate it into Contact class
> Tips:
1834
This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856

**Kind**: instance method of [<code>Message</code>](#Message)  
<a name="Message.find"></a>

### Message.find()
Find message in cache

**Kind**: static method of [<code>Message</code>](#Message)  
<a name="Message.findAll"></a>

### Message.findAll()
Find messages in cache

**Kind**: static method of [<code>Message</code>](#Message)  
<a name="RoomInvitation"></a>

## RoomInvitation
accept room invitation

**Kind**: global class  

* [RoomInvitation](#RoomInvitation)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1857 1858 1859
    * _instance_
        * [.accept()](#RoomInvitation+accept)<code>Promise.&lt;void&gt;</code>
        * [.inviter()](#RoomInvitation+inviter)[<code>Contact</code>](#Contact)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1860
        * [.topic()](#RoomInvitation+topic)<code>string</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1861 1862 1863 1864 1865
        * [.date()](#RoomInvitation+date)<code>Promise.&lt;Date&gt;</code>
        * [.age()](#RoomInvitation+age)<code>number</code>
        * [.toJSON()](#RoomInvitation+toJSON)<code>string</code>
    * _static_
        * [.fromJSON()](#RoomInvitation.fromJSON)[<code>RoomInvitation</code>](#RoomInvitation)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903

<a name="RoomInvitation+accept"></a>

### roomInvitation.accept() ⇒ <code>Promise.&lt;void&gt;</code>
Accept Room Invitation

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
**Example**  
```js
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  try {
    console.log(`received room-invite event.`)
    await roomInvitation.accept()
  } catch (e) {
    console.error(e)
  }
}
.start()
```
<a name="RoomInvitation+inviter"></a>

### roomInvitation.inviter() ⇒ [<code>Contact</code>](#Contact)
Get the inviter from room invitation

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
**Example**  
```js
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  const inviter = await roomInvitation.inviter()
  const name = inviter.name()
  console.log(`received room invitation event from ${name}`)
}
.start()
```
<a name="RoomInvitation+topic"></a>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1904
### roomInvitation.topic() ⇒ <code>string</code>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
Get the room topic from room invitation

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
**Example**  
```js
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  const topic = await roomInvitation.topic()
  console.log(`received room invitation event from room ${topic}`)
}
.start()
```
<a name="RoomInvitation+date"></a>

### roomInvitation.date() ⇒ <code>Promise.&lt;Date&gt;</code>
Get the invitation time

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
<a name="RoomInvitation+age"></a>

### roomInvitation.age() ⇒ <code>number</code>
Returns the roopm invitation age in seconds. <br>

For example, the invitation is sent at time `8:43:01`,
and when we received it in Wechaty, the time is `8:43:15`,
then the age() will return `8:43:15 - 8:43:01 = 14 (seconds)`

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961
<a name="RoomInvitation+toJSON"></a>

### roomInvitation.toJSON() ⇒ <code>string</code>
Get the room invitation info when listened on room-invite event

**Kind**: instance method of [<code>RoomInvitation</code>](#RoomInvitation)  
**Example**  
```js
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
 const roomInvitation = bot.RoomInvitation.load(roomInvitation.id)
 const jsonData = await roomInvitation.toJSON(roomInvitation.id)
 // save the json data to disk, and we can use it by RoomInvitation.fromJSON()
}
.start()
```
<a name="RoomInvitation.fromJSON"></a>

### RoomInvitation.fromJSON() ⇒ [<code>RoomInvitation</code>](#RoomInvitation)
Load the room invitation info from disk

**Kind**: static method of [<code>RoomInvitation</code>](#RoomInvitation)  
**Example**  
```js
const bot = new Wechaty()
const dataFromDisk // get the room invitation info data from disk
const roomInvitation = await bot.RoomInvitation.fromJSON(dataFromDisk)
await roomInvitation.accept()
```
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
<a name="cuid_1"></a>

## cuid\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="clone_class_1"></a>

## clone\_class\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="clone_class_1"></a>

## clone\_class\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="wechaty_puppet_1"></a>

## wechaty\_puppet\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="events_1"></a>

## events\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="events_1"></a>

## events\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="clone_class_1"></a>

## clone\_class\_1
Wechaty Chatbot SDK - https://github.com/wechaty/wechaty

**Kind**: global constant  
**Copyright**: 2016 Huan LI (李卓桓) <https://github.com/huan>, and
                  Wechaty Contributors <https://github.com/wechaty>.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.  
<a name="guardWechatify"></a>

## guardWechatify()
Huan(202008): we will bind the wechaty puppet with user modules (Contact, Room, etc) together inside the start() method

**Kind**: global function  
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2108
<a name="PuppetModuleName"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2109

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2110
## PuppetModuleName
2111
The term [Puppet](https://github.com/wechaty/wechaty/wiki/Puppet) in Wechaty is an Abstract Class for implementing protocol plugins.
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2112
The plugins are the component that helps Wechaty to control the WeChat(that's the reason we call it puppet).
2113
The plugins are named XXXPuppet, for example:
2114 2115
- [PuppetPuppeteer](https://github.com/wechaty/wechaty-puppet-puppeteer):
- [PuppetPadchat](https://github.com/wechaty/wechaty-puppet-padchat)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2116

2117 2118 2119 2120 2121
**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2122 2123
| PUPPET_DEFAULT | <code>string</code> | The default puppet. |
| wechaty-puppet-wechat4u | <code>string</code> | The default puppet, using the [wechat4u](https://github.com/nodeWechat/wechat4u) to control the [WeChat Web API](https://wx.qq.com/) via a chrome browser. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2124
| wechaty-puppet-padchat | <code>string</code> | - Using the WebSocket protocol to connect with a Protocol Server for controlling the iPad WeChat program. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2125 2126
| wechaty-puppet-puppeteer | <code>string</code> | - Using the [google puppeteer](https://github.com/GoogleChrome/puppeteer) to control the [WeChat Web API](https://wx.qq.com/) via a chrome browser. |
| wechaty-puppet-mock | <code>string</code> | - Using the mock data to mock wechat operation, just for test. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2127

2128
<a name="WechatyOptions"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2129

2130 2131
## WechatyOptions
The option parameter to create a wechaty instance
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2132

2133 2134
**Kind**: global typedef  
**Properties**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2135

2136 2137
| Name | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2138
| name | <code>string</code> | Wechaty Name. </br>          When you set this: </br>          `new Wechaty({name: 'wechaty-name'}) ` </br>          it will generate a file called `wechaty-name.memory-card.json`. </br>          This file stores the login information for bot. </br>          If the file is valid, the bot can auto login so you don't need to scan the qrCode to login again. </br>          Also, you can set the environment variable for `WECHATY_NAME` to set this value when you start. </br>          eg:  `WECHATY_NAME="your-cute-bot-name" node bot.js` |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2139
| puppet | [<code>PuppetModuleName</code>](#PuppetModuleName) \| <code>Puppet</code> | Puppet name or instance |
2140 2141
| puppetOptions | <code>Partial.&lt;PuppetOptions&gt;</code> | Puppet TOKEN |
| ioToken | <code>string</code> | Io TOKEN |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2142

2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
<a name="RoomQueryFilter"></a>

## RoomQueryFilter
The filter to find the room:  {topic: string | RegExp}

**Kind**: global typedef  
**Properties**

| Name | Type |
| --- | --- |
| topic | <code>string</code> | 

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166
<a name="RoomEventName"></a>

## RoomEventName
Room Class Event Type

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| join | <code>string</code> | Emit when anyone join any room. |
| topic | <code>string</code> | Get topic event, emitted when someone change room topic. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2167
| leave | <code>string</code> | Emit when anyone leave the room.<br>                               If someone leaves the room by themselves, WeChat will not notice other people in the room, so the bot will never get the "leave" event. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182

<a name="RoomEventFunction"></a>

## RoomEventFunction
Room Class Event Function

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| room-join | <code>function</code> | (this: Room, inviteeList: Contact[] , inviter: Contact)  => void |
| room-topic | <code>function</code> | (this: Room, topic: string, oldTopic: string, changer: Contact) => void |
| room-leave | <code>function</code> | (this: Room, leaver: Contact) => void |

2183
<a name="RoomMemberQueryFilter"></a>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2184

2185
## RoomMemberQueryFilter
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2186 2187 2188 2189 2190 2191 2192
The way to search member by Room.member()

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2193
| name | <code>string</code> | Find the contact by WeChat name in a room, equal to `Contact.name()`. |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2194
| roomAlias | <code>string</code> | Find the contact by alias set by the bot for others in a room. |
2195
| contactAlias | <code>string</code> | Find the contact by alias set by the contact out of a room, equal to `Contact.alias()`. [More Detail](https://github.com/wechaty/wechaty/issues/365) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207

<a name="ContactQueryFilter"></a>

## ContactQueryFilter
The way to search Contact

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | The name-string set by user-self, should be called name |
2208
| alias | <code>string</code> | The name-string set by bot for others, should be called alias [More Detail](https://github.com/wechaty/wechaty/issues/365) |
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2209

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2210 2211 2212 2213 2214 2215
<script>
  ((window.gitter = {}).chat = {}).options = {
    room: 'chatie/wechaty'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>