Skip to content

Latest commit

 

History

History
1292 lines (1033 loc) · 44.5 KB

index.md

File metadata and controls

1292 lines (1033 loc) · 44.5 KB

Wechaty v0.17.60 Documentation

Classes

Wechaty

Main bot class.

The World's Shortest ChatBot Code: 6 lines of JavaScript

Wechaty Starter Project

Room

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

Room is Sayable, Examples/Room-Bot

Contact

All wechat contacts(friend) will be encapsulated as a Contact.

Contact is Sayable, Examples/Contact-Bot

Friendship

Send, receive friend request, and friend confirmation events.

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

Examples/Friend-Bot

Message

All wechat messages will be encapsulated as a Message.

Message is Sayable, Examples/Ding-Dong-Bot

Typedefs

WechatyEventName

Wechaty Class Event Type

WechatyEventFunction

Wechaty Class Event Function

RoomEventName

Room Class Event Type

RoomEventFunction

Room Class Event Function

MemberQueryFilter

The way to search member by Room.member()

ContactQueryFilter

The way to search Contact

Wechaty

Main bot class.

The World's Shortest ChatBot Code: 6 lines of JavaScript

Wechaty Starter Project

Kind: global class

wechaty.Contact

Clone Classes for this bot and attach the puppet to the Class

https://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript microsoft/TypeScript#5843 (comment) microsoft/TypeScript#19197

Kind: instance property of Wechaty

Contact.wechaty

  1. Set Wechaty

Kind: static property of Contact

Contact.puppet

  1. Set Puppet

Kind: static property of Contact

wechaty.version([forceNpm]) ⇒ string

Return version of Wechaty

Kind: instance method of Wechaty
Returns: string - - the version number

Param Type Default Description
[forceNpm] boolean false if set to true, will only return the version in package.json. otherwise will return git commit hash if .git exists.

Example

console.log(Wechaty.instance().version())       // return '#git[af39df]'
console.log(Wechaty.instance().version(true))   // return '0.7.9'

wechaty.on(event, listener) ⇒ Wechaty

Kind: instance method of Wechaty
Returns: Wechaty - - this for chain

More Example Gist: Examples/Friend-Bot

Param Type Description
event WechatyEventName Emit WechatyEvent
listener WechatyEventFunction Depends on the WechatyEvent

Example (Event:scan )

wechaty.on('scan', (url: string, code: number) => {
  console.log(`[${code}] Scan ${url} to login.` )
})

Example (Event:login )

bot.on('login', (user: ContactSelf) => {
  console.log(`user ${user} login`)
})

Example (Event:logout )

bot.on('logout', (user: ContactSelf) => {
  console.log(`user ${user} logout`)
})

Example (Event:message )

wechaty.on('message', (message: Message) => {
  console.log(`message ${message} received`)
})

Example (Event:friend )

bot.on('friend', (request: Friendship) => {
  if(request.type === Friendship.Type.RECEIVE){ // 1. receive new friend request from new contact
    const contact = request.contact()
    let result = await request.accept()
      if(result){
        console.log(`Request from ${contact.name()} is accept succesfully!`)
      } else{
        console.log(`Request from ${contact.name()} failed to accept!`)
      }
	  } else if (request.type === Friendship.Type.CONFIRM) { // 2. confirm friend ship
      console.log(`new friendship confirmed with ${contact.name()}`)
   }
 })

Example (Event:room-join )

bot.on('room-join', (room: Room, inviteeList: Contact[], inviter: Contact) => {
  const nameList = inviteeList.map(c => c.name()).join(',')
  console.log(`Room ${room.topic()} got new member ${nameList}, invited by ${inviter}`)
})

Example (Event:room-leave )

bot.on('room-leave', (room: Room, leaverList: Contact[]) => {
  const nameList = leaverList.map(c => c.name()).join(',')
  console.log(`Room ${room.topic()} lost member ${nameList}`)
})

Example (Event:room-topic )

bot.on('room-topic', (room: Room, topic: string, oldTopic: string, changer: Contact) => {
  console.log(`Room ${room.topic()} topic changed from ${oldTopic} to ${topic} by ${changer.name()}`)
})

wechaty.start() ⇒ Promise.<void>

Start the bot, return Promise.

Kind: instance method of Wechaty
Example

await bot.start()
// do other stuff with bot here

wechaty.stop() ⇒ Promise.<void>

Stop the bot

Kind: instance method of Wechaty
Example

await bot.stop()

wechaty.logout() ⇒ Promise.<void>

Logout the bot

Kind: instance method of Wechaty
Example

await bot.logout()

wechaty.logonoff() ⇒ boolean

Get the logon / logoff state

Kind: instance method of Wechaty
Example

if (bot.logonoff()) {
  console.log('Bot logined')
} else {
  console.log('Bot not logined')
}

wechaty.self()

Deprecated

Kind: instance method of Wechaty

wechaty.userSelf() ⇒ Contact

Get current user

Kind: instance method of Wechaty
Example

const contact = bot.userSelf()
console.log(`Bot is ${contact.name()}`)

wechaty.say(textOrContactOrFile) ⇒ Promise.<boolean>

Send message to userSelf

Kind: instance method of Wechaty

Param Type
textOrContactOrFile string

Wechaty.instance()

get the singleton instance of Wechaty

Kind: static method of Wechaty
Example (The World's Shortest ChatBot Code: 6 lines of JavaScript)

const { Wechaty } = require('wechaty')

Wechaty.instance() // Singleton
.on('scan', (url, code) => console.log(`Scan QR Code to login: ${code}\n${url}`))
.on('login',       user => console.log(`User ${user} logined`))
.on('message',  message => console.log(`Message: ${message}`))
.init()

Room

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

Room is Sayable, Examples/Room-Bot

Kind: global class

room.say(textOrContactOrFile, [replyTo]) ⇒ Promise.<boolean>

Send message inside Room, if set [replyTo], wechaty will mention the contact as well.

Kind: instance method of Room
Returns: Promise.<boolean> - If bot send message successfully, it will return true. If the bot failed to send for blocking or any other reason, it will return false

Param Type Description
textOrContactOrFile string | MediaMessage Send text or media file inside Room.
[replyTo] Contact | Array.<Contact> Optional parameter, send content inside Room, and mention @replyTo contact or contactList.

Example (Send text inside Room)

const room = await Room.find({name: 'wechaty'})        // change 'wechaty' to any of your room in wechat
await room.say('Hello world!')

Example (Send media file inside Room)

const room = await Room.find({name: 'wechaty'})        // change 'wechaty' to any of your room in wechat
await room.say(new MediaMessage('/test.jpg'))          // put the filePath you want to send here

Example (Send text inside Room, and mention @replyTo contact)

const contact = await Contact.find({name: 'lijiarui'}) // change 'lijiarui' to any of the room member
const room = await Room.find({name: 'wechaty'})        // change 'wechaty' to any of your room in wechat
await room.say('Hello world!', contact)

room.on(event, listener) ⇒ this

Kind: instance method of Room
Returns: this - - this for chain

Param Type Description
event RoomEventName Emit WechatyEvent
listener RoomEventFunction Depends on the WechatyEvent

Example (Event:join )

const room = await Room.find({topic: 'event-room'}) // change `event-room` to any room topic in your wechat
if (room) {
  room.on('join', (room: Room, inviteeList: Contact[], inviter: Contact) => {
    const nameList = inviteeList.map(c => c.name()).join(',')
    console.log(`Room ${room.topic()} got new member ${nameList}, invited by ${inviter}`)
  })
}

Example (Event:leave )

const room = await Room.find({topic: 'event-room'}) // change `event-room` to any room topic in your wechat
if (room) {
  room.on('leave', (room: Room, leaverList: Contact[]) => {
    const nameList = leaverList.map(c => c.name()).join(',')
    console.log(`Room ${room.topic()} lost member ${nameList}`)
  })
}

Example (Event:topic )

const room = await Room.find({topic: 'event-room'}) // change `event-room` to any room topic in your wechat
if (room) {
  room.on('topic', (room: Room, topic: string, oldTopic: string, changer: Contact) => {
    console.log(`Room ${room.topic()} topic changed from ${oldTopic} to ${topic} by ${changer.name()}`)
  })
}

room.add(contact) ⇒ Promise.<number>

Add contact in a room

Kind: instance method of Room

Param Type
contact Contact

Example

const contact = await Contact.find({name: 'lijiarui'}) // change 'lijiarui' to any contact in your wechat
const room = await Room.find({topic: 'wechat'})        // change 'wechat' to any room topic in your wechat
if (room) {
  const result = await room.add(contact)
  if (result) {
    console.log(`add ${contact.name()} to ${room.topic()} successfully! `)
  } else{
    console.log(`failed to add ${contact.name()} to ${room.topic()}! `)
  }
}

room.del(contact) ⇒ Promise.<number>

Delete a contact from the room It works only when the bot is the owner of the room

Kind: instance method of Room

Param Type
contact Contact

Example

const room = await Room.find({topic: 'wechat'})          // change 'wechat' to any room topic in your wechat
const contact = await Contact.find({name: 'lijiarui'})   // change 'lijiarui' to any room member in the room you just set
if (room) {
  const result = await room.del(contact)
  if (result) {
    console.log(`remove ${contact.name()} from ${room.topic()} successfully! `)
  } else{
    console.log(`failed to remove ${contact.name()} from ${room.topic()}! `)
  }
}

room.topic([newTopic]) ⇒ Promise.<(string|void)>

SET/GET topic from the room

Kind: instance method of Room

Param Type Description
[newTopic] string If set this para, it will change room topic.

Example (When you say anything in a room, it will get room topic. )

const bot = Wechaty.instance()
bot
.on('message', async m => {
  const room = m.room()
  if (room) {
    const topic = await room.topic()
    console.log(`room topic is : ${topic}`)
  }
})

Example (When you say anything in a room, it will change room topic. )

const bot = Wechaty.instance()
bot
.on('message', async m => {
  const room = m.room()
  if (room) {
    const oldTopic = room.topic()
    room.topic('change topic to wechaty!')
    console.log(`room topic change from ${oldTopic} to ${room.topic()}`)
  }
})

room.qrcode()

Room QR Code

Kind: instance method of Room

room.alias(contact) ⇒ string | null

Return contact's roomAlias in the room, the same as roomAlias

Kind: instance method of Room
Returns: string | null - - If a contact has an alias in room, return string, otherwise return null

Param Type
contact Contact

Example

const bot = Wechaty.instance()
bot
.on('message', async m => {
  const room = m.room()
  const contact = m.from()
  if (room) {
    const alias = room.alias(contact)
    console.log(`${contact.name()} alias is ${alias}`)
  }
})

room.roomAlias(contact) ⇒ string | null

Same as function alias

Kind: instance method of Room

Param Type
contact Contact

room.has(contact) ⇒ boolean

Check if the room has member contact, the return is a Promise and must be await-ed

Kind: instance method of Room
Returns: boolean - Return true if has contact, else return false.

Param Type
contact Contact

Example (Check whether 'lijiarui' is in the room 'wechaty')

const contact = await Contact.find({name: 'lijiarui'})   // change 'lijiarui' to any of contact in your wechat
const room = await Room.find({topic: 'wechaty'})         // change 'wechaty' to any of the room in your wechat
if (contact && room) {
  if (await room.has(contact)) {
    console.log(`${contact.name()} is in the room ${room.topic()}!`)
  } else {
    console.log(`${contact.name()} is not in the room ${room.topic()} !`)
  }
}

room.memberAll(query) ⇒ Array.<Contact>

Find all contacts in a room

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 Room

Param Type Description
query RoomMemberQueryFilter | string When use memberAll(name:string), return all matched members, including name, roomAlias, contactAlias

room.member(queryArg) ⇒ Contact | null

Find all contacts in a room, if get many, return the first one.

Kind: instance method of Room

Param Type Description
queryArg RoomMemberQueryFilter | string When use member(name:string), return all matched members, including name, roomAlias, contactAlias

Example (Find member by name)

const room = await Room.find({topic: 'wechaty'})           // change 'wechaty' to any room name in your wechat
if (room) {
  const member = room.member('lijiarui')                   // change 'lijiarui' to any room member in your wechat
  if (member) {
    console.log(`${room.topic()} got the member: ${member.name()}`)
  } else {
    console.log(`cannot get member in room: ${room.topic()}`)
  }
}

Example (Find member by MemberQueryFilter)

const room = await Room.find({topic: 'wechaty'})          // change 'wechaty' to any room name in your wechat
if (room) {
  const member = room.member({name: 'lijiarui'})          // change 'lijiarui' to any room member in your wechat
  if (member) {
    console.log(`${room.topic()} got the member: ${member.name()}`)
  } else {
    console.log(`cannot get member in room: ${room.topic()}`)
  }
}

room.memberList() ⇒ Array.<Contact>

Get all room member from the room

Kind: instance method of Room

room.sync() ⇒ Promise.<void>

Sync data for Room

Kind: instance method of Room

Room.create(contactList, [topic]) ⇒ Promise.<Room>

Create a new room.

Kind: static method of Room

Param Type
contactList Array.<Contact>
[topic] string

Example (Creat a room with 'lijiarui' and 'juxiaomi', the room topic is 'ding - created')

const helperContactA = await Contact.find({ name: 'lijiarui' })  // change 'lijiarui' to any contact in your wechat
const helperContactB = await Contact.find({ name: 'juxiaomi' })  // change 'juxiaomi' to any contact in your wechat
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')

Room.findAll([query]) ⇒ Promise.<Array.<Room>>

Find room by topic, return all the matched room

Kind: static method of Room

Param Type
[query] RoomQueryFilter

Example

const roomList = await Room.findAll()                    // get the room list of the bot
const roomList = await Room.findAll({name: 'wechaty'})   // find all of the rooms with name 'wechaty'

Room.find(query) ⇒ Promise.<(Room|null)>

Try to find a room by filter: {topic: string | RegExp}. If get many, return the first one.

Kind: static method of Room
Returns: Promise.<(Room|null)> - If can find the room, return Room, or return null

Param Type
query RoomQueryFilter

Contact

All wechat contacts(friend) will be encapsulated as a Contact.

Contact is Sayable, Examples/Contact-Bot

Kind: global class

contact.payload

Instance properties

Kind: instance property of Contact

contact.name() ⇒ string

Get the name from a contact

Kind: instance method of Contact
Example

const name = contact.name()

contact.alias(newAlias) ⇒ string | null | Promise.<boolean>

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 Contact

Param Type
newAlias none | string | null

Example ( GET the alias for a contact, return {(string | null)})

const alias = 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)

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)

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!`)
}

contact.stranger() ⇒ boolean | null

Deprecated

Check if contact is stranger

Kind: instance method of Contact
Returns: boolean | null - - True for not friend of the bot, False for friend of the bot, null for unknown.
Example

const isStranger = contact.stranger()

contact.friend() ⇒ boolean | null

Check if contact is friend

Kind: instance method of Contact
Returns: boolean | null - - True for friend of the bot, False for not friend of the bot, null for unknown.
Example

const isFriend = contact.friend()

contact.official() ⇒ boolean | null

Deprecated

Check if it's a offical account

Kind: instance method of Contact
Returns: boolean | null - - True for official account, Flase for contact is not a official account, null for unknown
See

Example

const isOfficial = contact.official()

contact.personal() ⇒ boolean

Deprecated

Check if it's a personal account

Kind: instance method of Contact
Returns: boolean - - True for personal account, Flase for contact is not a personal account
Example

const isPersonal = contact.personal()

contact.type() ⇒

Return the type of the Contact

Kind: instance method of Contact
Returns: ContactType - Contact.Type.PERSONAL for personal account, Contact.Type.OFFICIAL for official account
Example

const isOfficial = contact.type() === Contact.Type.OFFICIAL

contact.star() ⇒ boolean | null

Check if the contact is star contact.

Kind: instance method of Contact
Returns: boolean | null - - True for star friend, False for no star friend.
Example

const isStar = contact.star()

contact.gender() ⇒ ContactGender.Male(2) | Gender.Female(1) | Gender.Unknown(0)

Contact gender

Kind: instance method of Contact
Example

const gender = contact.gender()

contact.province() ⇒ string | null

Get the region 'province' from a contact

Kind: instance method of Contact
Example

const province = contact.province()

contact.city() ⇒ string | null

Get the region 'city' from a contact

Kind: instance method of Contact
Example

const city = contact.city()

contact.avatar() ⇒ Promise.<FileBox>

Get avatar picture file stream

Kind: instance method of Contact
Example

const avatarFileName = contact.name() + `.jpg`
const fileBox = await contact.avatar()
const avatarWriteStream = createWriteStream(avatarFileName)
fileBox.pipe(avatarWriteStream)
log.info('Bot', 'Contact: %s: %s with avatar file: %s', contact.weixin(), contact.name(), avatarFileName)

contact.refresh() ⇒ Promise.<this>

Deprecated

Force reload(re-ready()) data for Contact

Kind: instance method of Contact
Example

await contact.refresh()

contact.sync() ⇒ Promise.<this>

sycc data for Contact

Kind: instance method of Contact
Example

await contact.sync()

contact.self() ⇒ boolean

Check if contact is self

Kind: instance method of Contact
Returns: boolean - True for contact is self, False for contact is others
Example

const isSelf = contact.self()

Contact.find(query) ⇒ Promise.<(Contact|null)>

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 Contact
Returns: Promise.<(Contact|null)> - If can find the contact, return Contact, or return null

Param Type
query ContactQueryFilter

Example

const contactFindByName = await Contact.find({ name:"ruirui"} )
const contactFindByAlias = await Contact.find({ alias:"lijiarui"} )

Contact.findAll([queryArg]) ⇒ Promise.<Array.<Contact>>

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 Contact

Param Type
[queryArg] ContactQueryFilter

Example

const contactList = await Contact.findAll()                    // get the contact list of the bot
const contactList = await Contact.findAll({name: 'ruirui'})    // find allof the contacts whose name is 'ruirui'
const contactList = await Contact.findAll({alias: 'lijiarui'}) // find all of the contacts whose alias is 'lijiarui'

Friendship

Send, receive friend request, and friend confirmation events.

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

Examples/Friend-Bot

Kind: global class

friendship.payload

Instance Properties

Kind: instance property of Friendship

friendship.ready()

no dirty support because Friendship has no rawPayload(yet)

Kind: instance method of Friendship

Friendship.send()

Deprecated

Kind: static method of Friendship

Friendship.add(contact, hello)

Send a Friend Request to a contact with message hello.

Kind: static method of Friendship

Param
contact
hello

Message

All wechat messages will be encapsulated as a Message.

Message is Sayable, Examples/Ding-Dong-Bot

Kind: global class

message.payload

Instance Properties

Kind: instance property of Message

message.from() ⇒ Contact

Get the sender from a message.

Kind: instance method of Message

message.to() ⇒ Contact | null

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 Message

message.room() ⇒ Room | null

Get the room from the message. If the message is not in a room, then will return null

Kind: instance method of Message

message.content()

Deprecated

Kind: instance method of Message

message.text() ⇒ string

Get the text content of the message

Kind: instance method of Message

message.say(textOrContactOrFile, [mention]) ⇒ Promise.<void>

Reply a Text or Media File message to the sender.

Kind: instance method of Message
See: Examples/ding-dong-bot

Param Type
textOrContactOrFile string | FileBox
[mention] Contact | Array.<Contact>

Example

const bot = new Wechaty()
bot
.on('message', async m => {
  if (/^ding$/i.test(m.text())) {
    await m.say('hello world')
    console.log('Bot REPLY: hello world')
    await m.say(new bot.Message(__dirname + '/wechaty.png'))
    console.log('Bot REPLY: Image')
  }
})

message.file()

Deprecated

Kind: instance method of Message

message.type() ⇒ WebMsgType

Get the type from the message.

If type is equal to MsgType.RECALLED, Message#id is the msgId of the recalled message.

Kind: instance method of Message
See: MsgType

message.self() ⇒ boolean

Check if a message is sent by self.

Kind: instance method of Message
Returns: boolean - - Return true for send from self, false for send from others.
Example

if (message.self()) {
 console.log('this message is sent by myself!')
}

message.mention() ⇒ Array.<Contact>

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 Message
Returns: Array.<Contact> - - Return message mentioned contactList
Example

const contactList = message.mentioned()
console.log(contactList)

message.mentioned()

Kind: instance method of Message
Deprecated:: use mention() instead

message.forward(to) ⇒ Promise.<void>

Forward the received message.

Kind: instance method of Message

Param Type Description
to Sayable | Array.<Sayable> Room or Contact The recipient of the message, the room, or the contact

message.age()

Message Age: in seconds.

Kind: instance method of Message

Message.Type

Static Properties

Kind: static property of Message

Message.find()

Kind: static method of Message
Todo

  • add function

Message.findAll()

Kind: static method of Message
Todo

  • add function

Message.create()

Create a Mobile Terminated Message

"mobile originated" or "mobile terminated" https://www.tatango.com/resources/video-lessons/video-mo-mt-sms-messaging/

Kind: static method of Message

WechatyEventName

Wechaty Class Event Type

Kind: global typedef
Properties

Name Type Description
error string When the bot get error, there will be a Wechaty error event fired.
login string After the bot login full successful, the event login will be emitted, with a Contact of current logined user.
logout string Logout will be emitted when bot detected log out, with a Contact of the current login user.
heartbeat string Get bot's heartbeat.
friend string When someone sends you a friend request, there will be a Wechaty friend event fired.
message string Emit when there's a new message.
room-join string Emit when anyone join any room.
room-topic string Get topic event, emitted when someone change room topic.
room-leave string Emit when anyone leave the room.
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.
scan string A scan event will be emitted when the bot needs to show you a QR Code for scanning.

WechatyEventFunction

Wechaty Class Event Function

Kind: global typedef
Properties

Name Type Description
error function (this: Wechaty, error: Error) => void callback function
login function (this: Wechaty, user: ContactSelf)=> void
logout function (this: Wechaty, user: ContactSelf) => void
scan function (this: Wechaty, url: string, code: number) => void
  1. URL: {String} the QR code image URL
  2. code: {Number} the scan status code. some known status of the code list here is:
  • 0 initial_
  • 200 login confirmed
  • 201 scaned, wait for confirm
  • 408 waits for scan
heartbeat function (this: Wechaty, data: any) => void
friend function (this: Wechaty, request?: Friendship) => void
message function (this: Wechaty, message: Message) => void
room-join function (this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void
room-topic function (this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void
room-leave function (this: Wechaty, room: Room, leaverList: Contact[]) => void

RoomEventName

Room Class Event Type

Kind: global typedef
Properties

Name Type Description
join string Emit when anyone join any room.
topic string Get topic event, emitted when someone change room topic.
leave string Emit when anyone leave the room.
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.

RoomEventFunction

Room Class Event Function

Kind: global typedef
Properties

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

MemberQueryFilter

The way to search member by Room.member()

Kind: global typedef
Properties

Name Type Description
name string Find the contact by wechat name in a room, equal to Contact.name().
roomAlias string Find the contact by alias set by the bot for others in a room.
contactAlias string Find the contact by alias set by the contact out of a room, equal to Contact.alias(). More Detail

ContactQueryFilter

The way to search Contact

Kind: global typedef
Properties

Name Type Description
name string The name-string set by user-self, should be called name
alias string The name-string set by bot for others, should be called alias More Detail