在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:wechaty开源软件地址:https://gitee.com/wechaty/wechaty开源软件介绍:WechatyConnecting ChatbotsWechaty 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. :spider_web: https://wechaty.js.org Breaking NewsVoice of Developers
See more at Wiki:Voice Of Developer Join UsWechaty 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. Scan now, because other Wechaty developers want to talk with you too! (secret code: wechaty)
ResourceWechaty 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 JavaScriptconst { 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()
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
Getting Started
We have a Wechaty starter repository for beginners with the simplest setting. It will be just work out-of-the-box after you 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 1. Npmnpm initnpm 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
2.1. Run JavaScript # for JavaScriptdocker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.js 2.2. Run TypeScript # for TypeScriptdocker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.ts
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 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 :
Learn more about Wechaty Puppet from the Puppet Wiki:
APIRead the Full Documentation at Wechaty Official API Reference 1 Class |
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 |
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 puppet-padplus supported). |
method | self(): boolean | check if contact is self |
method | name(): string | get the name from a contact |
method | alias(): Promise<string> | get the alias for a contact |
method | alias(newAlias: string): Promise<void> | set or delete the alias for a contact |
method | friend(): boolean | check if contact is friend |
method | type(): ContactType | return the type of the Contact |
method | province(): string | get the region 'province' from a contact |
method | city(): string | get the region 'city' from a contact |
method | avatar(): Promise<FileBox> | get avatar picture file stream |
method | gender(): ContactGender | get gender from a contact |
ContactSelf
Class ContactSelf
is extended from Contact
.
ContactSelf | API | Description |
---|---|---|
method | avatar(file: FileBox): Promise<void> | set avatar for bot |
method | qrcode(): Promise<string> | get qrcode for bot |
method | signature(text: string): Promise<void> | set signature for bot |
Friendship
Send, receive friend request, and friend confirmation events.
Friendship | API | Description |
---|---|---|
static | add(contact: Contact, hello?: string): Promise<void> | send a friend invitation to contact |
method | accept(): Promise<void> | accept Friend Request |
method | hello(): string | get the hello string from a friendship invitation |
method | contact(): Contact | get the contact from friendship |
method | type(): FriendshipType | return the Friendship Type(unknown, confirm, receive, verify) |
Message
All wechat messages will be encapsulated as a Message.
Message | API | Description |
---|---|---|
static | find(query: string): Promise<null | Message> | find message in cache and return the first one |
static | findAll(query: string): Promise<Message[]> | find messages in cache, return a message list |
method | from(): Contact | get the sender from a message |
method | to(): Contact | get the destination of the message |
method | room(): null | Room | get the room from the message.(If the message is not in a room, then will return null ) |
method | text(): string | get the text content of the message |
method | say(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). |
method | type(): MessageType | get the type from the message |
method | self(): boolean | check if a message is sent by self |
method | mention(): Contact[] | get message mentioned contactList. |
method | mentionSelf(): boolean | check if a message is mention self |
method | forward(to: Contact): Promise<void> | Forward the received message |
method | age(): number | the number of seconds since it has been created |
method | date(): Date | the time it was created |
method | toFileBox(): Promise<FileBox> | extract the Media File from the Message, and put it into the FileBox. |
method | toContact(): Promise<Contact> | get Share Card of the Message |
Room
All wechat rooms(groups) will be encapsulated as a Room.
Room | API | Description |
---|---|---|
static | create(contactList: Contact[], topic?: string): Promise<Room> | create a new room |
static | find(query: string): Promise<null | Room> | Try to find a room by filter. If get many, return the first one. |
static | findAll(query: string): Promise<Room[]> | Find all contacts in a room |
static | load(query: string): Room | load room by room id |
property | id: readonly string | |
event | join | emit when anyone join any room |
event | topic | emit when someone change room topic |
event | leave | emit when anyone leave the room |
event | invite | emit when receive a room invitation |
method | sync(): <Promise<void> | force reload data for room, sync data from lowlevel API again. |
method | say(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). |
method | add(contact: Contact): Promise<void> | Add contact in a room |
method | del(contact: Contact): Promise<void> | Delete a contact from the room |
method | quit(): Promise<void> | Bot quit the room itself |
method | topic(): Promise<string> | GET topic from the room |
method | topic(newTopic: string): Promise<void> | SET topic from the room |
method | announce(text: string): Promise<void> | SET/GET announce from the room |
method | qrcode(): Promise<string> | 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> | Return contact's roomAlias in the room |
method | roomAlias(contact: Contact): Promise<string | null> | Same as function alias |
method | has(contact: Contact): Promise<boolean> | Check if the room has member contact |
method | memberAll(query?: string): Promise<Contact[]> | Find all contacts or with specific name in a room |
method | member(query: string): Promise<null | Contact> | Find all contacts in a room, if get many, return the first one. |
method | memberList():Promise<Contact[]> | get all room member from the room |
method | owner(): null | Contact | Get room's owner from the room. |
RoomInvitation
Accept room invitation
RoomInvitation | API | Description |
---|---|---|
method | accept(): Promise<void> | accept Room Invitation |
method | inviter(): Contact | get the inviter from room invitation |
method | roomTopic(): Promise<string> | get the room topic from room invitation |
method | date(): Promise<Date> | the time it was created |
method | age(): Promise<number> | the number of seconds since it has been created |
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 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:
[![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
Pull Request is welcome to add yours!
Learn more about Projects Using Wechaty at Wiki:Projects Using Wechaty
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 |
In 2017 ...
Huan's daily life/work depends on too much chat on wechat.
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.
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers!
请发表评论