Package Exports
- wechaty
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wechaty) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

Wechaty

Wechaty is Wechat for Bot.(Personal Account Robot, NOT Official Account)
Easy creating wechat robot code in 10 lines.
Why
My daily life/work depends on too much wechat.
- I almost have 14,000 wechat friends till May 2014, before wechat restricts a total number of friends to 5,000.
- I almost have 400 wechat groups that most of them have more than 400 members.
Can you image that? I'm dying...
So a tireless bot working for me 24x7 on wechat, moniting/filtering the most important message is badly needed. For example: highlights discusstion which contains the KEYWORDS I want to follow up(especially in a noisy group). ;-)
Examples
Wechaty is super easy to use: 10 lines of javascript is enough for your first wechat robot.
1. Basic: 10 lines
The following 10 lines of code will implement a bot that will reply a message automatically to you:
const Wechaty = require('wechaty')
const bot = new Wechaty()
bot.init()
.then(bot.getLoginQrImgUrl.bind(bot.puppet))
.then(url => console.log(`Scan qrcode in url to login: \n${url}`))
bot.on('message', m => {
console.log('RECV: ' + m.get('content')) // 1. print received message
const reply = new Wechaty.Message() // 2. create reply message
.set('to', m.get('from')) // 1) set receipt
.set('content', 'roger.') // 2) set content
bot.send(reply) // 3. do reply!
.then(() => console.log('REPLY: roger.')) // 4. print reply message
})Notice that you need to wait a moment while bot trys to get the login QRCode from Wechat. As soon as the bot gets login QRCode url, he will print url out. You need to scan the qrcode on wechat, and confirm login.
After that, bot will be on duty. (roger-bot source can be found at here)
2. Advanced: 50 lines
There's another basic usage demo bot named ding-dong-bot, who can reply dong when bot receives a message ding.
3. Hardcore: 100 lines
To Be Written.
Plan to glue with Machine Learning/Deep Learning/Neural Network/Natural Language Processing.
Installation
The recommended installation method is a local NPM install for your project:
$ npm install --save wechatyRequirement
ECMAScript2015/ES6. I develop and test wechaty under nodejs6.0.
API Refference
Class Wechaty
Main bot class.
const bot = new Wechaty()Wechaty.init()
Initialize the bot, return Promise.
bot.init()
.then(() => {
// do other staff with bot here
}Wechaty.getLoginQrImgUrl()
Get the login QrCode image url. Must be called after init().
Return a Promise, for url link.
bot.getLoginQrImgUrl()
.then(url => {
// show url
})Event: message
Emit when there's a new message.
bot.on('message', callback)Callback will get an instance of Message Class. (see Class Message)
Event: login & logout
To-Be-Supported
Class Message
All messages will be encaped in Message.
Message.ready()
A message may be not fully initialized yet. Call ready() to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
message.ready()
.then(() => {
// Here we can be sure all the data is ready for use.
})Message.get(prop)
Get prop from a message.
Supported prop list:
id:Stringfrom:Contactto:Contactcontent:Stringgroup:Groupdate:Date
message.get('content')Message.set(prop, value)
Set prop to value for a message.
Supported prop list: the same as get(prop)
message.set('content', 'Hello, World!')Class Contact
Contact.ready()
A Contact may be not fully initialized yet. Call ready() to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
contact.ready()
.then(() => {
// Here we can be sure all the data is ready for use.
})Contact.get(prop)
Get prop from a contact.
Supported prop list:
id:Stringweixin:Stringname:Stringremark:Stringsex:Numberprovince:Stringcity:Stringsignature:String
contact.get('name')Class Group
Group.ready()
A group may be not fully initialized yet. Call ready() to confirm we get all the data needed.
Return a Promise, will be resolved when all data is ready.
group.ready()
.then(() => {
// Here we can be sure all the data is ready for use.
})Group.get(prop)
Get prop from a group.
Supported prop list:
id:Stringname:Stringmembers:Arraycontact:Contactname:String
group.get('members').lengthTest
Wechaty use TAP protocol to test itself by tape.
To test Wechaty, run:
$ npm testKnow more about tape: Why I use Tape Instead of Mocha & So Should You
Version History
v0.0.5 (2016/5/11)
- Receive & send message
- Show contacts info
- Show groups info
- 1st usable version
- Start coding from May 1st 2016
Todo List
- Deal with friend request
- Manage contacts(send friend request/delete contact etc.)
Everybody is welcome to issue your needs.
Known Issues & Support
Github Issue - https://github.com/zixia/wechaty/issues
Contributing
Lint: eslint
$ npm lintCreate an issue, fork, then send a pull request(with unit test please).
Author
Zhuohuan LI zixia@zixia.net (http://linkedin.com/in/zixia)
Copyright & License
- Code & Docs 2016© zixia
- Code released under the ISC license
- Docs released under Creative Commons