Giter Site home page Giter Site logo

apple006 / wechaty Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wechaty/wechaty

0.0 1.0 0.0 3.25 MB

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

Home Page: https://blog.chatie.io

License: Apache License 2.0

JavaScript 11.33% Shell 3.91% TypeScript 84.76%

wechaty's Introduction

Wechaty

Wechaty

Connecting ChatBots.

Wechaty is a Bot Framework for Wechat Personal Account which can help you create a bot in 6 lines of javascript by easy to use API, with cross-platform support include Linux, Windows, Darwin(OSX/Mac) and Docker.

node TypeScript Repo Size

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

Voice of the Developer

I ... fall in love with it. It’s really easy to get started to make your own wechatbot. link
-- @kungfu-software, Founder of Kungfu Software

"Wechaty is a great solution, I believe there would be much more users recognize it." link
-- @Gcaufy, Tencent

"The best wechat SDK I have seen in Github!" link
-- @JasLin, BotWave CTO

"Wechaty简单的接口...和Docker化的封装...绝对是一个不错的选择" link
-- @shevyan, Ghost Cloud CEO

"Wechaty is great." link
-- @Samurais, SnapLingo Director of Engineering

"最好的微信开发库" link
-- @Jarvis, Baidu Developer

"Wechaty让运营人员更多的时间思考如何进行活动策划、留存用户,商业变现" link
-- @lijiarui, Orange Interactive CEO.

"太好用,好用的想哭"
-- @xinbenlv, Google Engineer, HaoShiYou.org Founder

"If you know js ... try Chatie/wechaty, it's easy to use."
-- @Urinx Uri Lee, Author of WeixinBot

"Wechaty library fantastic!" link - @ccaapton

"it's quite cool!" link - @ak5

"Thanks for great SDK" link - @naishstar

"Your docker solution is awesome!" link - @ax4

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

const { Wechaty } = require('wechaty') // import { Wechaty } from '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()

Notice: Wechaty requires Node.js version >= 6.9.0

This bot can log all message to console.

You can find more example from Wiki and Example Directory.

Getting Started

A Great Live Coding Tutorial

The above 10 minutes video tutorial is a good start point if you are new to Wechaty.

Source code in the video can be found at here: Wechaty Starter Repository

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

Notice: The published versions have always passed the CI tests. We highly recommend running wechaty with the versions installed by docker or npm instead of the latest master branch unless you are prepared to deal with the broken code problems.

Docker

Docker Pulls Docker Stars Docker Layers

The best practice to use Wechaty is run by docker, becasue it's not only the most easy way to get start, but also protect you out of the troubles of dependencies problems.

$ docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.js

Wechaty Docker support to run TypeScript directly as well: just write in TypeScript and save to mybot.ts.

Get to know more about Wechaty Docker at Wiki:Docker.

NPM

NPM Version Downloads Greenkeeper badge

$ npm install wechaty

$ cat > mybot.js <<'_EOF_'
const { Wechaty } = require('wechaty')
const bot = Wechaty.instance()
console.log(bot.version())
_EOF_

$ node mybot.js

Get to know more about NPM at Wiki:NPM

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

API Reference

Wechaty Events

  1. scan Emit when the bot needs to show you a QR Code for scanning
  2. login Emit when bot login full successful.
  3. logout Emit when bot detected log out.
  4. message Emit when there's a new message.
  5. error Emit when there's an error occurred.
  6. friend Emit when got a new friend request, or friendship is confirmed.
  7. room-join Emit when someone join the room
  8. room-leave Emit when someone leave the room
  9. room-topic Emit when someone change the room's topic

Wechaty

  1. instance(setting: PuppetSetting): Promise<Wechaty> get the bot instance
  2. init(): Promise<void> Initialize the bot
  3. say(content: string): Promise<void> send message to filehelper, just for logging/reporting usage for your convenience

Message

  1. from():Contact get the sender from a message
  2. from(contact:Contact):void set a sender to the message
  3. to():Contact get the destination of the message
  4. to(contact:Contact):void set the destination as contact for the message
  5. content():string get the content of the message
  6. content(content:string):string set the content for the message
  7. room():Room|null get the room from a message.
  8. room(room:Room):void set the room for a message.
  9. type():MsgType get the type of a Message.
  10. say(content:string):Promise reply a message to the sender.
  11. self():boolean check if a message is sent by self

Contact

  1. name():string get name from a contact
  2. remark():string get remark name from a contact
  3. remark(remark:string):Promise set remark name to a contact
  4. weixin():string get weixin id from a contact
  5. star():boolean true for star friend, false for no star friend
  6. say(content:string):Promise say content to a contact

Room

  1. say(content:string,replyTo:Contact|ContactArray):Promise say content inside Room.
  2. refresh():Promise reload data for Room

Room Event

  1. join Emit when someone join the room
  2. leave Emit when someone leave the room
  3. topic Emit when someone change the room topic

FriendRequest

  1. hello:string get content from friendrequest
  2. accept():Promise accept the friendrequest
  3. send(contact:Contact,hello:string):Promise send a new friend request

Release Notes

Powered By Wechaty

Powered by Wechaty

Wechaty Badge

Get embed html/markdown code from Wiki:PoweredByWechaty

Projects Use Wechaty

  1. Relay between Telegram and WeChat
  2. A chat bot managing the HaoShiYou wechat groups run by volunteers of haoshiyou.org
  3. A chat interactive bot to manage TODO list
  4. Forward WeChat messages to telegram

Know more about Projects Use Wechaty at Wiki:PoweredByWechaty

Find a Good Server

The best practice for runing Wechaty Docker/NPM is using a VPS(Virtual Private Server) outside of China, which can save you hours of time because npm install and docker pull will run smoothly without any problem.

The following VPS providers is used by ourselves, they worked perfectly in production. You can use the following link to get one in minutes, and also do this can support Wechaty because you are refered by us.

Location Price Ram Payment Provider
Singapore $5 512MB Paypal DigitalOcean
Japan $5 1GB Paypal Linode
Korea $10 1GB Alipay, Paypal Netdedi

Contributing

Issue Stats Issue Stats Join the chat at https://gitter.im/zixia/wechaty

Howto contribute

Contributions in any form are highly encouraged and welcome! Be it new or improved presets, optimized streaming code or just some cleanup. So start forking!

Code Contributions

If you want to add new features or change the API, please submit an issue first to make sure no one else is already working on the same thing and discuss the implementation and API details with maintainers and users by creating an issue. When everything is settled down, you can submit a pull request.

When fixing bugs, you can directly submit a pull request.

Make sure to add tests for your features and bugfixes and update the documentation (see below) before submitting your code!

Documentation Contributions

You can directly submit pull requests for documentation changes.

Main Contributors

Join Wechaty Developers' Community

Wechaty is used in many ChatBot projects by hundreds of developers. If you want to talk with other developers, just scan the following QR Code in WeChat with secret code wechaty, you can join our Wechaty Developers' Home at once.

Wechaty Developers' Home

Scan now, because other Wechaty developers want to talk with you too! (secret code: wechaty)

See Also

Documentation

In order to sync the doc with the lastest code for best, Wechaty use jsdoc to descript API, and use jsdoc-to-markdown to generate markdown format document to docs directory.

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

Huan LI <[email protected]> (http://linkedin.com/in/zixia)

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

Copyright & License

  • Code & Docs © 2016-2017 Huan LI <[email protected]>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

wechaty's People

Contributors

christianzzz avatar flyingblazer avatar gcaufy avatar gitter-badger avatar greenkeeper[bot] avatar greenkeeperio-bot avatar huan avatar imerse avatar jaslin avatar lijiarui avatar mukaiu avatar xinbenlv avatar xjchengo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.