Wechaty
Main bot class, A Bot is a wechat client depends on which puppet you use.
Classes
Main bot class.
A Bot
is a wechat client depends on which puppet you use. It may equals
web-wechat, when you use: puppet-puppeteer/puppet-wechat4u
ipad-wechat, when you use: puppet-padchat
ios-wechat, when you use: puppet-ioscat
See more:
If you want to know how to send message, see Message If you want to know how to get contact, see Contact
Typedefs
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 PuppetXXX, for example:
The option parameter to create a wechaty instance WechatyEventName
Wechaty Class Event Type WechatyEventFunction
Wechaty Class Event Function
Wechaty
Main bot class.
A Bot
is a wechat client depends on which puppet you use. It may equals
web-wechat, when you use: puppet-puppeteer/puppet-wechat4u
ipad-wechat, when you use: puppet-padchat
ios-wechat, when you use: puppet-ioscat
See more:
If you want to know how to send message, see Message If you want to know how to get contact, see Contact
Kind: global class
instance
.start() ⇒
Promise <void>
.stop() ⇒
Promise <void>
.logout() ⇒
Promise <void>
.logonoff() ⇒
boolean
.userSelf() ⇒
ContactSelf
.say(textOrContactOrFileOrUrl) ⇒
Promise <void>
static
new Wechaty([options])
Creates an instance of Wechaty.
Param | Type | Default |
[options] |
|
Example (The World's Shortest ChatBot Code: 6 lines of JavaScript)
wechaty.on(event, listener) ⇒ Wechaty
Wechaty
When the bot get message, it will emit the following Event.
You can do anything you want when in these events functions. The main Event name as follows:
scan: Emit when the bot needs to show you a QR Code for scanning. After scan the qrcode, you can login
login: Emit when bot login full successful.
logout: Emit when bot detected log out.
message: Emit when there's a new message.
see more in WechatyEventName
Kind: instance method of Wechaty
Returns: Wechaty
- - this for chaining, see advanced chaining usage
Param | Type | Description |
event | Emit WechatyEvent | |
listener | Depends on the WechatyEvent |
Example (Event:scan)
Example (Event:login )
Example (Event:logout )
Example (Event:message )
Example (Event:friendship )
Example (Event:room-join )
Example (Event:room-leave )
Example (Event:room-topic )
Example (Event:room-invite, RoomInvitation has been encapsulated as a RoomInvitation Class. )
Example (Event:error )
wechaty.start() ⇒ Promise <void>
Promise <void>
When you start the bot, bot will begin to login, need you wechat scan qrcode to login
Tips: All the bot operation needs to be triggered after start() is done
Kind: instance method of Wechaty
Example
wechaty.stop() ⇒ Promise <void>
Promise <void>
Stop the bot
Kind: instance method of Wechaty
Example
wechaty.logout() ⇒ Promise <void>
Promise <void>
Logout the bot
Kind: instance method of Wechaty
Example
wechaty.logonoff() ⇒ boolean
boolean
Get the logon / logoff state
Kind: instance method of Wechaty
Example
wechaty.userSelf() ⇒ ContactSelf
ContactSelf
Get current user
Kind: instance method of Wechaty
Example
wechaty.say(textOrContactOrFileOrUrl) ⇒ Promise <void>
Promise <void>
Send message to userSelf, in other words, bot send message to itself.
Tips: This function is depending on the Puppet Implementation, see puppet-compatible-table
Kind: instance method of Wechaty
Param | Type | Description |
textOrContactOrFileOrUrl |
| send text, Contact, file or Link to bot. </br> You can use FileBox to send file |
Example
Wechaty.instance([options])
Get the global instance of Wechaty
Kind: static method of Wechaty
Param | Type | Default |
[options] |
|
Example (The World's Shortest ChatBot Code: 6 lines of JavaScript)
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 PuppetXXX, for example:
Kind: global typedef Properties
Name | Type | Description |
wechat4u |
| The default puppet, using the wechat4u to control the WeChat Web API via a chrome browser. |
padchat |
| - Using the WebSocket protocol to connect with a Protocol Server for controlling the iPad Wechat program. |
puppeteer |
| - Using the google puppeteer to control the WeChat Web API via a chrome browser. |
mock |
| - 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 |
| Wechaty Name. When you set this: |
puppet |
| Puppet name or instance |
puppetOptions |
| Puppet TOKEN |
ioToken |
| Io TOKEN |
WechatyEventName
Wechaty Class Event Type
Kind: global typedef Properties
Name | Type | Description |
error |
| When the bot get error, there will be a Wechaty error event fired. |
login |
| After the bot login full successful, the event login will be emitted, with a Contact of current logined user. |
logout |
| Logout will be emitted when bot detected log out, with a Contact of the current login user. |
heartbeat |
| Get bot's heartbeat. |
friendship |
| When someone sends you a friend request, there will be a Wechaty friendship event fired. |
message |
| Emit when there's a new message. |
ready |
| Emit when all data has load completed, in wechaty-puppet-padchat, it means it has sync Contact and Room completed |
room-join |
| Emit when anyone join any room. |
room-topic |
| Get topic event, emitted when someone change room topic. |
room-leave |
| Emit when anyone leave the room. |
room-invite |
| Emit when there is a room invitation, see more in RoomInvitation 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 |
| A scan event will be emitted when the bot needs to show you a QR Code for scanning. </br> It is recommend to install qrcode-terminal(run |
WechatyEventFunction
Wechaty Class Event Function
Kind: global typedef Properties
Name | Type | Description |
error |
| (this: Wechaty, error: Error) => void callback function |
login |
| (this: Wechaty, user: ContactSelf)=> void |
logout |
| (this: Wechaty, user: ContactSelf) => void |
scan |
| (this: Wechaty, url: string, code: number) => void |
heartbeat |
| (this: Wechaty, data: any) => void |
friendship |
| (this: Wechaty, friendship: Friendship) => void |
message |
| (this: Wechaty, message: Message) => void |
ready |
| (this: Wechaty) => void |
room-join |
| (this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void |
room-topic |
| (this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void |
room-leave |
| (this: Wechaty, room: Room, leaverList: Contact[]) => void |
room-invite |
| (this: Wechaty, room: Room, leaverList: Contact[]) => void see more in RoomInvitation |
Last updated