Skip to content
forked from wechaty/wechaty

Wechat for Bot. Powered by WebDriver / Node.js / TypeScript / Docker

License

Notifications You must be signed in to change notification settings

lakxtxue/wechaty

Repository files navigation

Wechaty

Wechaty

Connecting ChatBots.

Wechaty is a Bot Framework for Wechat Personal Account that helps you easy creating bot in 6 lines of javascript, with cross-platform support include Linux, Windows, Darwin(OSX/Mac) and Docker.

Join the chat at https://gitter.im/zixia/wechaty node Repo Size

:octocat: https://github.com/wechaty/wechaty
🪲 https://github.com/wechaty/wechaty/issues
📖 https://github.com/wechaty/wechaty/wiki
🐳 https://hub.docker.com/r/zixia/wechaty

Voice of the Developer

@JasLin: the best wechat SDK I have seen in Github! link

@Jarvis: 最好的微信开发库 link

@ccaapton: wechaty library fantastic! link

@ak5: it's quite cool! link

@Samurais: wechaty is great. link

@naishstar: thanks for great SDK link

Example

The shortest wechat bot code in the world: 6 lines 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()

This bot can log all message to console.

You can find more example from Wiki and Example Directory.

Run

Let's say, you have saved the above six lines javascript example to mybot.js.

We have two options to run wechaty:

  1. Docker
  2. NPM

Docker

Docker Pulls Docker Stars Docker Layers

$ docker run \
  -t -i --rm \
  --volume="$(pwd)":/bot \
  --name=wechaty \
  zixia/wechaty \
  mybot.js
  • Wechaty Docker has native support for TypeScript as well: just write in TypeScript and save to mybot.ts, then run wechaty mybot.ts.

Get to know more about Wechaty Docker from here.

NPM

NPM Version Downloads

$ npm install --save wechaty

$ node mybot.js

You might be asked for install the chromedriver, depends on which platform you are.

Get to know more about NPM at Wiki

API Reference

  1. init(): Promise<void>

Initialize the bot, return Promise.

  1. instance(setting: PuppetSetting): Promise<Wechaty>

create a bot instance

  1. send(message: Message): Promise<void>

send a message

  1. say(content: string): Promise<void>

send message to filehelper, just for logging/reporting usage for your convenience

  1. error

Emit when there's an error occurred.

  1. friend

Emit when got a new friend request, or friendship is confirmed.

  1. login

Emit when bot login full successful.

  1. logout

Emit when bot detected log out.

  1. message

Emit when there's a new message.

  1. room-join

Emit when someone join the room

  1. room-leave

Emit when someone leave the room

  1. room-topic

Emit when someone change the room's topic

  1. scan

Emit when the bot needs to show you a QR Code for scanning

  1. id:string

get uniq id from a contact

  1. name():string

get name from a contact

  1. remark():string

get remark name from a contact

  1. remark(remark:string):Promise

set remark name to a contact

  1. ready():Promise

confirm get all the contact data needed, will be resolved when all data is ready

  1. say(content:string):Promise

say content to a contact

  1. hello:string

get content from friendrequest

  1. accept():void

accept a friendrequest

  1. send(contact:Contact,hello:string):void

send a new friend request

  1. from():Contact

get the sender from a message

  1. from(contact:Contact):void

set a sender to the message

  1. from(contactId:string):void

set a sender to the message by contact id

  1. to():Contact

get the destination of the message

  1. to(contact:Contact):void

set the destination as contact for the message

  1. to(contact:string):void

set the destination as contact by 'weixin', for the message

  1. content():string

get the content of the message

  1. content(content:string):string

set the content for the message

  1. room():Room|null

get the room from a message.

  1. room(room:Room):void

set the room for a message.

  1. room(roomId:string):void

set the room by id for a Message

  1. say(content:string):Promise

reply a message to the sender.

  1. ready():Promise

confirm get all the data needed, will be resolved when all message data is ready.

  1. self(message:Message):boolean

check if a message is sent by self

  1. say(content:string,replyTo:Contact|ContactArray):Promise

say content inside Room.

  1. ready():Promise

confirm get all the data needed, will be resolved when all data is ready

  1. refresh():Promise

force reload data for Room

  1. join

Emit when someone join the room

  1. leave

Emit when someone leave the room

  1. topic

Emit when someone change the room topic

Test

Linux/Mac Build Status Windows Build status Docker CircleCI Coverage Status Known Vulnerabilities

Wechaty use AVA for unit testing

To test Wechaty, run:

npm test

Get to know more about test from Wiki:Test

Release Notes

Powered By Wechaty

Powered by Wechaty

Wechaty Badge

Get embed html/markdown code from Wiki:PoweredByWechaty

Projects Use Wechaty

  1. Wechaty.io ChatBot Portal Manager for Wechaty

Know more about Projects Use Wechaty at Wiki:PoweredByWechaty

Contributing

Howto contribute

See Also

My Story

My daily life/work depends on too much chat on wechat.

  • I almost have 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
  • I almost have 400 wechat rooms 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, monitoring/filtering the most important message is badly needed. For example highlights discussion which contains the KEYWORDS which I want to follow up(especially in a noisy room). ;-)

At last, It's built for my personal study purpose of Automatically Testing.

Author

Zhuohuan LI zixia@zixia.net (http://linkedin.com/in/zixia)

profile for zixia at Stack Overflow, Q&A for professional and enthusiast programmers

Copyright & License

  • Code & Docs 2016© zixia
  • Code released under the ISC license
  • Docs released under Creative Commons

About

Wechat for Bot. Powered by WebDriver / Node.js / TypeScript / Docker

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 84.6%
  • JavaScript 11.0%
  • Shell 4.4%