MCPcopy
hub / github.com/wechaty/wechaty

github.com/wechaty/wechaty @v0.56 sqlite

repository ↗ · DeepWiki ↗ · release v0.56 ↗
409 symbols 889 edges 81 files 134 documented · 33%
README

Wechaty NPM Version NPM Docker

Wechaty

Downloads GitHub stars Docker Pulls TypeScript

Gitter Telegram Wechaty Channel

:hearts: 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.

:octocat: https://github.com/Wechaty/wechaty
:beetle: https://github.com/Wechaty/wechaty/issues
:book: https://github.com/Wechaty/wechaty/wiki
:whale: https://hub.docker.com/r/wechaty/wechaty

:yum: 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

:raising_hand: 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!

:book: 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:

:rocket: 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.

:checkered_flag: Requirements

  1. Node.js v12
  2. sudo apt-get install build-essential && sudo snap install shellcheck

:triangular_flag_on_post: 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 :

Protocol Puppet Provider Environment Variable
Web PuppetPuppeteer export WECHATY_PUPPET=wechaty-puppet-puppeteer
Windows PuppetWxwork export WECHATY_PUPPET=wechaty-puppet-service
Mock PuppetMock export WECHATY_PUPPET=wechaty-puppet-mock
Web PuppetWechat4u export WECHATY_PUPPET=wechaty-puppet-wechat4u
iPad PuppetRock export WECHATY_PUPPET=wechaty-puppet-service
iPad PuppetPadLocal export WECHATY_PUPPET=wechaty-puppet-service
Windows PuppetDonut export WECHATY_PUPPET=wechaty-puppet-service
iPad ~~PuppetPadpro~~ DEPRECATED export WECHATY_PUPPET=wechaty-puppet-padpro
iPad ~~PuppetPadchat~~ DEPRECATED export WECHATY_PUPPET=wechaty-puppet-padchat
iPad ~~PuppetPadplus~~ DEPRECATED export WECHATY_PUPPET=wechaty-puppet-padplus
Mac ~~PuppetMacpro~~ DEPRECATED export 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

:guitar: 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.

Wechaty API Description
event login emit after bot login full successful
event logout emit after the bot log out
event friendship emit when someone sends bot a friend request
event message emit when there's a new message
event room-join emit when anyone join any room
event room-topic emit when someone change room topic
event room-leave emit when anyone leave the room
event room-invite emit when there is a room invitation
event scan emit when the bot needs to show you a QR Code for scanning
method start(): Promise<void> start the bot
method stop(): Promise<void> stop the bot
method logonoff(): boolean bot login status
method logout(): Promise<void> logout the bot
method userSelf(): ContactSelf get the login-ed bot contact
method say(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.

Contact API Description
static find(query: string): Promise<null \| Contact> find contact by name or alias, if the result more than one, return the first one.
static findAll(query: string): Promise<Contact[]> find contact by name or alias
static load(query: string): Contact get contact by id
property id: readonly string get contact id
method sync(): Promise<void> force reload data for contact , sync data from lowlevel API again
method say(text: string): Promise<void \| Message> send text, Contact, or file to contact, return the message which the bot sent (only `pupp

Extension points exported contracts — how you extend this code

Sayable (Interface)
(no doc) [8 implementers]
src/types.ts
WechatyEvents (Interface)
* @listens Wechaty * @param {WechatyEventName} event - Emit WechatyEvent * @param {WechatyEventFunction}
src/events/wechaty-events.ts
WechatyPlugin (Interface)
(no doc)
src/plugin.ts
WechatyOptions (Interface)
(no doc)
src/wechaty.ts
DefaultSetting (Interface)
(no doc)
src/config.ts
IoOptions (Interface)
(no doc)
src/io.ts
ResolveOptions (Interface)
(no doc)
src/puppet-manager.ts
IoClientOptions (Interface)
(no doc)
src/io-client.ts

Core symbols most depended-on inside this repo

on
called by 68
src/wechaty.ts
load
called by 27
src/user/tag.ts
stop
called by 17
src/io.ts
start
called by 14
src/io.ts
type
called by 13
src/user/message.ts
load
called by 12
src/user/message.ts
ready
called by 11
src/wechaty.ts
send
called by 11
src/io.ts

Shape

Method 254
Class 74
Function 66
Interface 15

Languages

TypeScript100%

Modules by API surface

src/user/message.ts40 symbols
src/wechaty.ts37 symbols
src/user/contact.ts35 symbols
src/user/room.ts33 symbols
src/user/friendship.ts21 symbols
src/io.ts21 symbols
src/user/room-invitation.ts20 symbols
src/user/mini-program.ts16 symbols
src/io-client.ts14 symbols
src/user/tag.ts13 symbols
src/user/image.ts12 symbols
src/puppet-manager.ts12 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@babel/core7.12.10 · 1×
@babel/node7.12.10 · 1×
@babel/preset-env7.12.11 · 1×
@chatie/eslint-config0.12.3 · 1×
@chatie/git-scripts0.6.2 · 1×
@chatie/semver0.4.7 · 1×
@chatie/tsconfig0.14.1 · 1×
@types/cuid1.3.1 · 1×
@types/dotenv8.2.0 · 1×
@types/glob7.1.3 · 1×
@types/open-graph0.2.1 · 1×
@types/promise-retry1.1.3 · 1×

For agents

$ claude mcp add wechaty \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact