wechaty

Conversational RPA SDK for Chatbot Makers

Showing:

Popularity

Downloads/wk

3K

GitHub Stars

11.2K

Maintenance

Last Commit

6hrs ago

Contributors

56

Package

Dependencies

14

License

Apache-2.0

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

Wechaty NPM Version NPM Docker

Wechaty

Downloads GitHub stars Docker Pulls ES Modules

TypeScript JavaScript Python Go Java .NET PHP Rust Scala

WeChat Whatsapp

Gitter Telegram Wechaty Channel

Connecting Chatbots

Wechaty is a RPA (Robotic Process Automation) SDK for Chatbot Makers which can help you create a bot in 6 lines of JavaScript, Python, Go, and Java, with cross-platform support including Linux, Windows, MacOS, and Docker.

🕸️ https://wechaty.js.org
:octocat: https://github.com/Wechaty/wechaty
🐞 https://github.com/Wechaty/wechaty/issues
📖 https://github.com/Wechaty/wechaty-getting-started
🐳 https://hub.docker.com/r/wechaty/wechaty

Breaking News

Voice of Developers

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

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

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

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

"If you know js ... try Wechaty, it's easy to use."
@Urinx Uri Lee, Author of WeixinBot(Python)

"Wechaty is a good project, I hope it can continue! Therefore, I became a contributors in open collective."
@Simple

See more at Wiki:Voice Of Developer

Join Us

Gitter

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

Wechaty Friday.BOT QR Code

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

You are also welcome to join our Gitter channel at https://gitter.im/wechaty/wechaty with your GitHub account!

Resource

Wechaty already held lots of talk and got a lot of blogs in the past 4 years, here is all of the wechaty resources:

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


const { Wechaty } = require('wechaty') // import { Wechaty } from 'wechaty'

Wechaty.instance() // Global Instance
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`))
.on('login',            user => console.log(`User ${user} logged in`))
.on('message',       message => console.log(`Message: ${message}`))
.start()

Notice: Wechaty requires Node.js version >= 12

This bot can log all messages to the console after login by scan.

You can find Wechaty Official Example at examples/ding-dong-bot.ts, and more from our Example Directory.

🏁 Requirements

  1. Node.js version 16+
  2. NPM version 7+
  3. TypeScript version 4.4+

Getting Started

node

We have a Wechaty starter repository for beginners with the simplest setting. It will be just work out-of-the-box after you clone & npm install & npm start.

If you are new to Wechaty and want to try it the first time, we'd like to strong recommend you starting from this repository, and using it as your starter template for your project.

Otherwise, please saved the above The World's Shortest ChatBot Code: 6 lines of JavaScript example to a file named bot.js before you can use either NPM or Docker to run it.

1. Npm

NPM Version npm (tag)

Downloads install size

npm init
npm install wechaty

# create your first bot.js file, you can copy/paste from the above "The World's Shortest ChatBot Code: 6 lines of JavaScript"
# then:
node bot.js

2. Docker

Docker Pulls Docker Layers

Wechaty Docker supports both JavaScript and TypeScript. To use TypeScript just write in TypeScript and save with extension name .ts, no need to compile because we use ts-node to run it.

2.1. Run JavaScript

# for JavaScript
docker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.js

2.2. Run TypeScript

# for TypeScript
docker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.ts

Learn more about Wechaty Docker at Wiki:Docker.

3. Switch Protocol(Puppet)

Wechaty is very powerful that it can run over different protocols. You can specify the protocol by set the environment variable WECHATY_PUPPET to different puppet provider.

If you cannot use Web protocol, you can apply other protocal following the instruction here: https://github.com/wechaty/wechaty/wiki/Support-Developers We provide free token to support developers build a valuable WeChat chatbot.

Currently we support the following puppet providers :

ProtocolPuppet ProviderEnvironment Variable
WebPuppetPuppeteerexport WECHATY_PUPPET=wechaty-puppet-puppeteer
WindowsPuppetWxworkexport WECHATY_PUPPET=wechaty-puppet-service
MockPuppetMockexport WECHATY_PUPPET=wechaty-puppet-mock
WebPuppetWechat4uexport WECHATY_PUPPET=wechaty-puppet-wechat4u
iPadPuppetRockexport WECHATY_PUPPET=wechaty-puppet-service
iPadPuppetPadLocalexport WECHATY_PUPPET=wechaty-puppet-service
WindowsPuppetDonutexport WECHATY_PUPPET=wechaty-puppet-service
iPadPuppetPadpro DEPRECATEDexport WECHATY_PUPPET=wechaty-puppet-padpro
iPadPuppetPadchat DEPRECATEDexport WECHATY_PUPPET=wechaty-puppet-padchat
iPadPuppetPadplus DEPRECATEDexport WECHATY_PUPPET=wechaty-puppet-padplus
MacPuppetMacpro DEPRECATEDexport WECHATY_PUPPET=wechaty-puppet-macpro

Learn more about Wechaty Puppet from the Puppet Wiki:

  1. Puppet Directory: https://github.com/Wechaty/wechaty-puppet/wiki/Directory
  2. Puppet Compatibility: https://github.com/Wechaty/wechaty-puppet/wiki/Compatibility

🎸 API

Read the Full Documentation at Wechaty Official API Reference

1 Class Wechaty

Main bot class.

A Bot is a Wechaty instance that control a specific wechaty-puppet.

WechatyAPIDescription
eventloginemit after bot login full successful
eventlogoutemit after the bot log out
eventfriendshipemit when someone sends bot a friend request
eventmessageemit when there's a new message
eventroom-joinemit when anyone join any room
eventroom-topicemit when someone change room topic
eventroom-leaveemit when anyone leave the room
eventroom-inviteemit when there is a room invitation
eventscanemit when the bot needs to show you a QR Code for scanning
methodstart(): Promise<void>start the bot
methodstop(): Promise<void>stop the bot
methodlogonoff(): booleanbot login status
methodlogout(): Promise<void>logout the bot
methoduserSelf(): ContactSelfget the login-ed bot contact
methodsay(text: string): Promise<void>let bot say text to itself

2 Class Contact

All wechat contacts(friends/non-friends) will be encapsulated as a Contact.

ContactAPIDescription
staticfind(query: string): Promise<null \| Contact>find contact by name or alias, if the result more than one, return the first one.
staticfindAll(query: string): Promise<Contact[]>find contact by name or alias
staticload(query: string): Contactget contact by id
propertyid: readonly stringget contact id
methodsync(): Promise<void>force reload data for contact , sync data from lowlevel API again
methodsay(text: string): Promise<void \| Message>send text, Contact, or file to contact, return the message which the bot sent (only puppet-padplus supported).
methodself(): booleancheck if contact is self
methodname(): stringget the name from a contact
methodalias(): Promise<string>get the alias for a contact
methodalias(newAlias: string): Promise<void>set or delete the alias for a contact
methodfriend(): booleancheck if contact is friend
methodtype(): ContactTypereturn the type of the Contact
methodprovince(): stringget the region 'province' from a contact
methodcity(): stringget the region 'city' from a contact
methodavatar(): Promise<FileBox>get avatar picture file stream
methodgender(): ContactGenderget gender from a contact

2.1 Class ContactSelf

Class ContactSelf is extended from Contact.

ContactSelfAPIDescription
methodavatar(file: FileBox): Promise<void>set avatar for bot
methodqrcode(): Promise<string>get qrcode for bot
methodsignature(text: string): Promise<void>set signature for bot

2.2 Class Friendship

Send, receive friend request, and friend confirmation events.

FriendshipAPIDescription
staticadd(contact: Contact, hello?: string): Promise<void>send a friend invitation to contact
methodaccept(): Promise<void>accept Friend Request
methodhello(): stringget the hello string from a friendship invitation
methodcontact(): Contactget the contact from friendship
methodtype(): FriendshipTypereturn the Friendship Type(unknown, confirm, receive, verify)

3 Class Message

All wechat messages will be encapsulated as a Message.

MessageAPIDescription
staticfind(query: string): Promise<null \| Message>find message in cache and return the first one
staticfindAll(query: string): Promise<Message[]>find messages in cache, return a message list
methodfrom(): Contactget the sender from a message
methodto(): Contactget the destination of the message
methodroom(): null \| Roomget the room from the message.(If the message is not in a room, then will return null)
methodtext(): stringget the text content of the message
methodsay(text: string): Promise<void \| Message>reply a Text, Media File , or contact message to the sender, return the message which the bot sent (only puppet-padplus supported).
methodtype(): MessageTypeget the type from the message
methodself(): booleancheck if a message is sent by self
methodmention(): Contact[]get message mentioned contactList.
methodmentionSelf(): booleancheck if a message is mention self
methodforward(to: Contact): Promise<void>Forward the received message
methodage(): numberthe number of seconds since it has been created
methoddate(): Datethe time it was created
methodtoFileBox(): Promise<FileBox>extract the Media File from the Message, and put it into the FileBox.
methodtoContact(): Promise<Contact>get Share Card of the Message

4 Class Room

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

RoomAPIDescription
staticcreate(contactList: Contact[], topic?: string): Promise<Room>create a new room
staticfind(query: string): Promise<null \| Room>Try to find a room by filter. If get many, return the first one.
staticfindAll(query: string): Promise<Room[]>Find all contacts in a room
staticload(query: string): Roomload room by room id
propertyid: readonly string
eventjoinemit when anyone join any room
eventtopicemit when someone change room topic
eventleaveemit when anyone leave the room
eventinviteemit when receive a room invitation
methodsync(): <Promise<void>force reload data for room, sync data from lowlevel API again.
methodsay(text: string): Promise<void \| Message>Send text,media file, contact card, or text with mention @mention contact inside Room, return the message which the bot sent (only puppet-padplus supported).
methodadd(contact: Contact): Promise<void>Add contact in a room
methoddel(contact: Contact): Promise<void>Delete a contact from the room
methodquit(): Promise<void>Bot quit the room itself
methodtopic(): Promise<string>GET topic from the room
methodtopic(newTopic: string): Promise<void>SET topic from the room
methodannounce(text: string): Promise<void>SET/GET announce from the room
methodqrcode(): Promise<string>Get QR Code of the Room from the room, which can be used as scan and join the room.
methodalias(contact: Contact): Promise<string>Return contact's roomAlias in the room
methodroomAlias(contact: Contact): Promise<string \| null>Same as function alias
methodhas(contact: Contact): Promise<boolean>Check if the room has member contact
methodmemberAll(query?: string): Promise<Contact[]>Find all contacts or with specific name in a room
methodmember(query: string): Promise<null \| Contact>Find all contacts in a room, if get many, return the first one.
methodmemberList():Promise<Contact[]>get all room member from the room
methodowner(): null \| ContactGet room's owner from the room.

4.1 Class RoomInvitation

Accept room invitation

RoomInvitationAPIDescription
methodaccept(): Promise<void>accept Room Invitation
methodinviter(): Contactget the inviter from room invitation
methodroomTopic(): Promise<string>get the room topic from room invitation
methoddate(): Promise<Date>the time it was created
methodage(): Promise<number>the number of seconds since it has been created

TEST

NPM Docker Coverage Status

Known Vulnerabilities

Wechaty is fully automatically tested by unit and integration tests, with Continious Integration & Continious Deliver(CI/CD) support powered by CI like Travis, Shippable and Appveyor.

To test Wechaty, run:

npm test

Get to know more about the tests from Wiki:Tests

CREATING WECHATY PLUGIN

Creating and publishing a Wechaty Plugin is simple. Simply expose your module as a function that takes 1 parameter: wechaty. When your plugin is imported by Wechaty, it will pass itself in as the argument, and so you are free to add any configuration that Wechaty supports.

import { WechatyPlugin } from 'wechaty'

export default const MyPlugin: WechatyPlugin = (wechaty: Wechaty) => {
  // ...
}

The config exist so the user can pass in customizations to your Plugin. In documenting your Wechaty Plugin, you would lay out your supported config for the user.

See:

  1. Wechaty Plugin Support with KickOut Example #1939
  2. Wechaty Plugins Contrib

📝 RELEASE NOTES

🎷 Views Since Feb 15, 2019

HitCount

💖 POWERED BY WECHATY

Powered by Wechaty

✨ Wechaty Badge

[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://wechaty.js.org)

Get more embed html/markdown code from Wiki:Badge

🌟 Projects Using Wechaty

  1. 一个用CNN深度神经网络给图片评分的wechaty项目
  2. Relay between Telegram and WeChat
  3. A chat bot managing the HaoShiYou wechat groups run by volunteers of haoshiyou.org
  4. An interactive chat bot to manage a TODO list
  5. Forward WeChat messages to telegram
  6. koa与wechaty实现的微信小助手,可定时提醒与发消息设定定时任务
  7. Wechaty Pay - 让线上没有难做的生意
  8. 开源社的微信机器人项目

Pull Request is welcome to add yours!

Learn more about Projects Using Wechaty at Wiki:Projects Using Wechaty

😇 Find a Good Server

The best practice for running 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 are used by the Wechaty team, and they worked perfectly in production. You can use the following link to get one in minutes. Also, doing this can support Wechaty because you are referred by us.

LocationPriceRamPaymentProvider
Singapore$5512MBPaypalDigitalOcean
Japan$51GBPaypalLinode
Korea$101GBAlipay, PaypalNetdedi
Singapore$3.5512MBAlipay, WechatVultr

🎶 See Also

💩 The Story

In 2017 ...

Huan's daily life/work depends on too much chat on wechat.

  • Almost 14,000 wechat friends in May 2014, before wechat restricts a total number of friends to 5,000.
  • Almost 400 wechat rooms, and most of them have more than 400 members.

Can you imagine that? He was dying...

So a tireless bot working for me 24x7 on wechat, monitoring/filtering the most important message is badly needed. For example, it highlights discussion which contains the KEYWORDS which he want to follow up(especially in a noisy room). ;-)

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

Stargazers over time

Stargazers over time

💕 Contributors

GitHub issues GitHub pull requests Open Collective Backers Open Collective Sponsors

contributor contributor contributor contributor contributor contributor contributor contributor

This project exists thanks to all the people who contribute. [Contribute].


Contribute

😎 Backers

Backers on Open Collective

Thank you to all our backers! 🙏 [Become a backer]

Open Collective Wechaty

😏 Sponsors

Sponsors on Open Collective

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Wechaty Sponsor

Multi-language Wechaty

Python Wechaty Go Wechaty Java(Kotlin) Wechaty Scala Wechaty PHP Wechaty .NET(C#) Wechatyin

History

master v0.69

  1. Supports ES Modules (with CJS dual support) (#2232)

v0.68 (Aug 27, 2021)

  1. TLS support (#2231)
  2. The latest CommonJS version

Creators

  1. Huan (李卓桓), Tencent TVP of Chatbot
  2. Rui (李佳芮), Microsoft AI MVP, Founder & CEO of Juzi.BOT (YC W19 Alumni)

Profile of Huan LI (李卓桓) on StackOverflow

Cite Wechaty

To cite this project in publications:

@misc{wechaty,
  author = {Huan LI, Jiarui LI},
  title = {Wechaty: Conversational SDK for Chatbot Makers},
  year = {2016},
  publisher = {GitHub},
  journal = {GitHub Repository},
  howpublished = {\url{https://github.com/wechaty/wechaty}},
}
  • Code & Docs © 2016-now Huan, Rui, and Wechaty Community Contributors
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
TbhTBeiJing, China7 Ratings0 Reviews
2 months ago
Dashon 'DJ' HawkinsPhoenix, Arizona486 Ratings0 Reviews
Full-stack Javascript/Node.js developer, architect, & engineer in junior/mid role & CEO @GhettoGeek LLC; boutique, full-service digital agency downtown Phx, AZ.
8 months ago
Domenico GranitoShanghai14 Ratings0 Reviews
Creative Tech & Interactive Developer 10+ years of creating state of the art digital experiences.
September 8, 2020

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial