Github url

wechaty

by wechaty

wechaty /wechaty

Conversational AI RPA SDK for Chatbot1

8.3K Stars 1.2K Forks Last release: 3 months ago (v0.38) Apache License 2.0 6.0K Commits 22 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Wechaty NPM Version NPM Docker

Wechaty

DownloadsGitHub starsDocker PullsTypeScriptGitter

:hearts: Connecting Chatbots

Wechaty is a Conversational AI RPA Chatbot SDK for Wechat Individual Account 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/zixia/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

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 Developers' Home

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

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

: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.github.io/qrcode/${encodeURIComponent(qrcode)}`)) .on('login', user =\> console.log(`User ${user} logined`)) .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 more examples from Wiki and 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

mybot.js

before you can use either NPM or Docker to run it.

1. Npm

NPM Versionnpm (tag)

Downloadsinstall size

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

2. Docker

Docker PullsDocker 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 zixia/wechaty mybot.js

2.2. Run TypeScript

# for TypeScript docker run -ti --rm --volume="$(pwd)":/bot zixia/wechaty mybot.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

| | iPad | PuppetPadplus |

export WECHATY\_PUPPET=wechaty-puppet-padplus

| | Mac | PuppetMacpro |

export WECHATY\_PUPPET=wechaty-puppet-macpro

| | Mock | PuppetMock |

export WECHATY\_PUPPET=wechaty-puppet-mock

| | Web | PuppetWechat4u |

export WECHATY\_PUPPET=wechaty-puppet-wechat4u

| | iPad | PuppetPadpro DEPRECATED |

export WECHATY\_PUPPET=wechaty-puppet-padpro

| | iPad | PuppetPadchat DEPRECATED |

export WECHATY\_PUPPET=wechaty-puppet-padchat

|

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.

new Wechaty(options?: WechatyOptions)
  1. options.name?: string
    the name of this bot(optional)
  2. options.puppet?: string
    select which puppet provider we want to use. must be one of the:
    1. wechaty-puppet-puppeteer - Angular Hook for Web Wechat <- This is the DEFAULT
    2. wechaty-puppet-wechat4u - HTTP API for Web Wechat
    3. wechaty-puppet-padpro - iPad App Protocol
    4. wechaty-puppet-ioscat - iPhone App Hook
    5. wechaty-puppet-mock - Mock for Testing
  3. options.puppetOptions?: PuppetOptions
    options for the puppet provider.

| Wechaty | API | Description | | :--- | :--- | :--- | | event | [

login

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit after bot login full successful | | event | [

logout

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit after the bot log out | | event | [

friendship

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when someone sends bot a friend request| | event | [

message

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when there's a new message | | event | [

room-join

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when anyone join any room | | event | [

room-topic

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when someone change room topic | | event | [

room-leave

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when anyone leave the room | | event | [

room-invite

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when there is a room invitation | | event | [

scan

](https://wechaty.github.io/wechaty/#Wechaty+on) | emit when the bot needs to show you a QR Code for scanning | | method | [

start(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Wechaty+start) | start the bot | | method | [

stop(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Wechaty+stop) | stop the bot | | method | [

logonoff(): boolean

](https://wechaty.github.io/wechaty/#Wechaty+logonoff) | bot login status | | method | [

logout(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Wechaty+logout) | logout the bot | | method | [

userSelf(): ContactSelf

](https://wechaty.github.io/wechaty/#Wechaty+userSelf) | get the login-ed bot contact | | method | [

say(text: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#Wechaty+say) | 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></null>

](https://wechaty.github.io/wechaty/#Contact.find) | find contact by name or alias, if the result more than one, return the first one. | | static | [

findAll(query: string): Promise<contact></contact>

](https://wechaty.github.io/wechaty/#Contact.findAll) | find contact by

name

or

alias

| | static | [

load(query: string): Contact

](https://wechaty.github.io/wechaty/#Contact.load) | get contact by id | | property |

id: readonly string

| get contact id | | method | [

sync(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Contact+sync) | force reload data for contact , sync data from lowlevel API again| | method | [

say(text: string): Promise<void message></void>

](https://wechaty.github.io/wechaty/#Contact+say) | send text, Contact, or file to contact, return the message which the bot sent (only

puppet-padplus

supported). | | method | [

self(): boolean

](https://wechaty.github.io/wechaty/#Contact+self) | check if contact is self | | method | [

name(): string

](https://wechaty.github.io/wechaty/#Contact+name) | get the name from a contact | | method | [

alias(): Promise<string></string>

](https://wechaty.github.io/wechaty/#Contact+alias) | get the alias for a contact | | method | [

alias(newAlias: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#Contact+alias) | set or delete the alias for a contact | | method | [

friend(): boolean

](https://wechaty.github.io/wechaty/#Contact+friend) | check if contact is friend | | method | [

type(): ContactType

](https://wechaty.github.io/wechaty/#Contact+type) | return the type of the Contact | | method | [

province(): string

](https://wechaty.github.io/wechaty/#Contact+province) | get the region 'province' from a contact | | method | [

city(): string

](https://wechaty.github.io/wechaty/#Contact+city) | get the region 'city' from a contact | | method | [

avatar(): Promise<filebox></filebox>

](https://wechaty.github.io/wechaty/#Contact+avatar) | get avatar picture file stream | | method | [

gender(): ContactGender

](https://wechaty.github.io/wechaty/#Contact+gender) | get gender from a contact |

2.1 Class

ContactSelf

Class

ContactSelf

is extended from

Contact

.

| ContactSelf | API | Description | | :--- | :--- | :--- | | method | [

avatar(file: FileBox): Promise<void></void>

](https://wechaty.github.io/wechaty/#ContactSelf+avatar) | set avatar for bot | | method | [

qrcode(): Promise<string></string>

](https://wechaty.github.io/wechaty/#ContactSelf+qrcode) | get qrcode for bot | | method | [

signature(text: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#ContactSelf+signature) | set signature for bot |

2.2 Class

Friendship

Send, receive friend request, and friend confirmation events.

| Friendship | API | Description | | :--- | :--- | :--- | | static | [

add(contact: Contact, hello?: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#Friendship.add) | send a friend invitation to contact | | method | [

accept(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Friendship+accept) | accept Friend Request | | method | [

hello(): string

](https://wechaty.github.io/wechaty/#Friendship+hello) | get the hello string from a friendship invitation | | method | [

contact(): Contact

](https://wechaty.github.io/wechaty/#Friendship+contact) | get the contact from friendship | | method | [

type(): FriendshipType

](https://wechaty.github.io/wechaty/#Friendship+type) | return the Friendship Type(unknown, confirm, receive, verify) |

3 Class

Message

All wechat messages will be encapsulated as a Message.

| Message | API | Description | | :--- | :--- | :--- | | static | [

find(query: string): Promise<null message></null>

](https://wechaty.github.io/wechaty/#Message.find) | find message in cache and return the first one | | static | [

findAll(query: string): Promise<message></message>

](https://wechaty.github.io/wechaty/#Message.findAll) | find messages in cache, return a message list | | method | [

from(): Contact

](https://wechaty.github.io/wechaty/#Message+from) | get the sender from a message | | method | [

to(): Contact

](https://wechaty.github.io/wechaty/#Message+to) | get the destination of the message | | method | [

room(): null \| Room

](https://wechaty.github.io/wechaty/#Message+room) | get the room from the message.(If the message is not in a room, then will return

null

) | | method | [

text(): string

](https://wechaty.github.io/wechaty/#Message+text) | get the text content of the message | | method | [

say(text: string): Promise<void message></void>

](https://wechaty.github.io/wechaty/#Message+say) | reply a Text, Media File , or contact message to the sender, return the message which the bot sent (only

puppet-padplus

supported). | | method | [

type(): MessageType

](https://wechaty.github.io/wechaty/#Message+type) | get the type from the message | | method | [

self(): boolean

](https://wechaty.github.io/wechaty/#Message+self) | check if a message is sent by self | | method | [

mention(): Contact[]

](https://wechaty.github.io/wechaty/#Message+mention) | get message mentioned contactList. | | method | [

mentionSelf(): boolean

](https://wechaty.github.io/wechaty/#Message+mentionSelf) | check if a message is mention self | | method | [

forward(to: Contact): Promise<void></void>

](https://wechaty.github.io/wechaty/#Message+forward) | Forward the received message | | method | [

age(): number

](https://wechaty.github.io/wechaty/#Message+age) | the number of seconds since it has been created | | method | [

date(): Date

](https://wechaty.github.io/wechaty/#Message+date) | the time it was created | | method | [

toFileBox(): Promise<filebox></filebox>

](https://wechaty.github.io/wechaty/#Message+toFileBox) | extract the Media File from the Message, and put it into the FileBox. | | method | [

toContact(): Promise<contact></contact>

](https://wechaty.github.io/wechaty/#Message+toContact) | get Share Card of the Message |

4 Class

Room

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

| Room | API | Description | | :--- | :--- | :--- | | static | [

create(contactList: Contact[], topic?: string): Promise<room></room>

](https://wechaty.github.io/wechaty/#Room.create) | create a new room | | static | [

find(query: string): Promise<null room></null>

](https://wechaty.github.io/wechaty/#Room.find) | Try to find a room by filter. If get many, return the first one. | | static | [

findAll(query: string): Promise<room></room>

](https://wechaty.github.io/wechaty/#Room.findAll) | Find all contacts in a room | | static | [

load(query: string): Room

](https://wechaty.github.io/wechaty/#Room.load) | load room by room id | | property |

id: readonly string

| | | event | [

join

](https://wechaty.github.io/wechaty/#Room+on) | emit when anyone join any room | | event | [

topic

](https://wechaty.github.io/wechaty/#Room+on) | emit when someone change room topic | | event | [

leave

](https://wechaty.github.io/wechaty/#Room+on) | emit when anyone leave the room | | event | [

invite

](https://wechaty.github.io/wechaty/#Room+on) | emit when receive a room invitation | | method | [

sync(): <promise></promise>

](https://wechaty.github.io/wechaty/#Room+sync) | force reload data for room, sync data from lowlevel API again. | method | [

say(text: string): Promise<void message></void>

](https://wechaty.github.io/wechaty/#Room+say) | 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). | | method | [

add(contact: Contact): Promise<void></void>

](https://wechaty.github.io/wechaty/#Room+add) | Add contact in a room | | method | [

del(contact: Contact): Promise<void></void>

](https://wechaty.github.io/wechaty/#Room+del) | Delete a contact from the room | | method | [

quit(): Promise<void></void>

](https://wechaty.github.io/wechaty/#Room+quit) | Bot quit the room itself | | method | [

topic(): Promise<string></string>

](https://wechaty.github.io/wechaty/#Room+topic) | GET topic from the room | | method | [

topic(newTopic: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#Room+topic) | SET topic from the room | | method | [

announce(text: string): Promise<void></void>

](https://wechaty.github.io/wechaty/#Room+announce) | SET/GET announce from the room | | method | [

qrcode(): Promise<string></string>

](https://wechaty.github.io/wechaty/#Room+qrcode) | Get QR Code of the Room from the room, which can be used as scan and join the room. | | method | [

alias(contact: Contact): Promise<string></string>

](https://wechaty.github.io/wechaty/#Room+alias) | Return contact's roomAlias in the room | | method | [

roomAlias(contact: Contact): Promise<string null></string>

](https://wechaty.github.io/wechaty/#Room+roomAlias) | Same as function alias | | method | [

has(contact: Contact): Promise<boolean></boolean>

](https://wechaty.github.io/wechaty/#Room+has) | Check if the room has member

contact

| | method | [

memberAll(query?: string): Promise<contact></contact>

](https://wechaty.github.io/wechaty/#Room+memberAll) | Find all contacts or with specific name in a room | | method | [

member(query: string): Promise<null contact></null>

](https://wechaty.github.io/wechaty/#Room+member) | Find all contacts in a room, if get many, return the first one. | | method | [

memberList():Promise<contact></contact>

](https://wechaty.github.io/wechaty/#Room+memberList) | get all room member from the room | | method | [

owner(): null \| Contact

](https://wechaty.github.io/wechaty/#Room+owner) | Get room's owner from the room. |

4.1 Class

RoomInvitation

Accept room invitation

| RoomInvitation | API | Description | | :--- | :--- | :--- | | method | [

accept(): Promise<void></void>

](https://wechaty.github.io/wechaty/#RoomInvitation+accept) | accept Room Invitation | | method | [

inviter(): Contact

](https://wechaty.github.io/wechaty/#RoomInvitation+inviter) | get the inviter from room invitation | | method | [

roomTopic(): Promise<string></string>

](https://wechaty.github.io/wechaty/#RoomInvitation+inviter) | get the room topic from room invitation | | method | [

date(): Promise<date></date>

](https://wechaty.github.io/wechaty/#RoomInvitation+date) | the time it was created | | method | [

age(): Promise<number></number>

](https://wechaty.github.io/wechaty/#RoomInvitation+age) | the number of seconds since it has been created |

:eyeglasses: TEST

NPMDockerCoverage StatusKnown 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

:pencil: RELEASE NOTES

:saxophone: Views Since Feb 15, 2019

HitCount

:sparkling_heart: POWERED BY WECHATY

Powered by Wechaty

:sparkles: Wechaty Badge

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

Get more embed html/markdown code from Wiki:PoweredByWechaty

:star2: 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:PoweredByWechaty

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

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

:notes: See Also

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

:two_hearts: Contributors

GitHub issuesGitHub pull requestsOpen Collective BackersOpen Collective Sponsors

contributorcontributorcontributorcontributorcontributorcontributorcontributorcontributor

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


Contribute

:sunglasses: Backers

Backers on Open Collective

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

Open Collective Wechaty

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

:point_down: Multi-language Wechaty

Wechaty in PythonWechaty in KotlinWechaty in GoWechaty in Scala

  • Wechaty - Conversatioanl AI Chatot SDK for Wechaty Individual Accounts (TypeScript)
  • Python Wechaty - Python WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Python)
  • Go Wechaty - Go WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Go)
  • Java Wechaty - Java WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Java)
  • Scala Wechaty - Scala WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (Scala)

:raised_hands: Authors

  1. Huan (李卓桓), Tencent TVP of Chatbot
  2. Rui (李佳芮), Microsoft AI MVP

Profile of Huan LI (李卓桓) on StackOverflow

:email: Copyright & License

  • Code & Docs © 2016 Huan, Rui, and Wechaty Contributors
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.