Skip to content

Latest commit

 

History

History
230 lines (186 loc) · 10.8 KB

README.md

File metadata and controls

230 lines (186 loc) · 10.8 KB

API

Classes

[Wechaty](/api/wechaty)

Main bot class.

A Bot is a wechat client depends on which puppet you use. It may equals

See more:

If you want to know how to send message, see [Message](/api/message)
If you want to know how to get contact, see [Contact](/api/contact)

[Room](/api/room)

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

Examples/Room-Bot

[Contact](/api/contact)

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

Examples/Contact-Bot

[Friendship](/api/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](/api/message)

All wechat messages will be encapsulated as a Message.

Examples/Ding-Dong-Bot

Typedefs

[PuppetName](/api/?id=puppetname)

The term Puppet in Wechaty is an Abstract Class for implementing protocol plugins. The plugins are the component that helps Wechaty to control the Wechat(that's the reason we call it puppet). The plugins are named XXXPuppet, for example:

[WechatyOptions](/api/?id=wechatyoptions)

The option parameter to create a wechaty instance

[WechatyEventName](/api/?id=wechatyeventname)

Wechaty Class Event Type

[WechatyEventFunction](/api/?id=wechatyeventfunction)

Wechaty Class Event Function

[RoomQueryFilter](/api/?id=roomqueryfilter)

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

[RoomEventName](/api/?id=roomeventname)

Room Class Event Type

[RoomEventFunction](/api/?id=roomeventfunction)

Room Class Event Function

[RoomMemberQueryFilter](/api/?id=roommemberqueryfilter)

The way to search member by Room.member()

[ContactQueryFilter](/api/?id=contactqueryfilter)

The way to search Contact

PuppetName

The term [Puppet](https://github.com/Chatie/wechaty/wiki/Puppet) in Wechaty is an Abstract Class for implementing protocol plugins. The plugins are the component that helps Wechaty to control the Wechat(that's the reason we call it puppet). The plugins are named XXXPuppet, for example: - [PuppetPuppeteer](https://github.com/Chatie/wechaty-puppet-puppeteer): - [PuppetPadchat](https://github.com/lijiarui/wechaty-puppet-padchat)

Kind: global typedef
Properties

Name Type Description
wechat4u string The default puppet, using the wechat4u to control the WeChat Web API via a chrome browser.
padchat string - Using the WebSocket protocol to connect with a Protocol Server for controlling the iPad Wechat program.
puppeteer string - Using the google puppeteer to control the WeChat Web API via a chrome browser.
mock string - Using the mock data to mock wechat operation, just for test.

WechatyOptions

The option parameter to create a wechaty instance

Kind: global typedef
Properties

Name Type Description
profile string Wechaty Name.
When you set this:
new Wechaty({profile: 'wechatyName'})
it will generate a file called wechatyName.memory-card.json.
This file stores the bot's login information.
If the file is valid, the bot can auto login so you don't need to scan the qrcode to login again.
Also, you can set the environment variable for WECHATY_PROFILE to set this value when you start.
eg: WECHATY_PROFILE="your-cute-bot-name" node bot.js
puppet PuppetName | Puppet Puppet name or instance
puppetOptions Partial.<PuppetOptions> Puppet TOKEN
ioToken string Io TOKEN

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.
It is recommend to install qrcode-terminal(run npm install qrcode-terminal) in order to show qrcode in the terminal.

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
friendship function (this: Wechaty, friendship: 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

RoomQueryFilter

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

Kind: global typedef
Properties

Name Type
topic string

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

RoomMemberQueryFilter

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