When you find yourself writing repetitive code, it’s time to extract it into a plugin.
Wechaty has a great support for using Plugins by calling Wechaty.use(WechatyPlugin()). A Wechaty Plugin is a JavaScript function that returns a function which accepts a Wechaty instance.
The first Wechaty Plugin system was design by our core team developer @gcaufy from issue #1939(Wechaty Plugin Support with Kick out Example) to PR #1946(feat: added wechaty plugin).
This package is for publishing the Wechaty Plugins that are very common used by the core developer team.
import { EventLogger } from 'wechaty-plugin-contrib'
const config = ['login', 'ready', 'message']
// Do not provide an config will log all events.
wechaty.use(EventLogger(config))
3 QR Code Terminal
Description: Show QR Code for Scan in Terminal
Author: @huan
import { QRCodeTerminal } from 'wechaty-plugin-contrib'
const config = {
small: false, // default: false - the size of the printed QR Code in terminal
}
wechaty.use(QRCodeTerminal(config))
4 Heartbeat
Description: Send emoji periodically
Author: @huan
import { Heartbeat } from 'wechaty-plugin-contrib'
const config = {
contact: 'filehelper', // default: filehelper - Contact id who will receive the emoji
emoji: {
heartbeat: '[爱心]', // default: [爱心] - Heartbeat emoji
},
intervalSeconds: 60 * 60, // Default: 1 hour - Send emoji for every 1 hour
}
wechaty.use(Heartbeat(config))
5 ChatOps
Description: Forward DM & Mention messages to a ChatOps room for logging.
Author: @huan
import { ChatOps } from 'wechaty-plugin-contrib'
const config = {
room : 'xxx@chatroom', // required: room id for ChatOps
mention? : true, // default: true - Response to Mention Self (@/at) Message in Room
contact? : true, // default: true - Response to Direct Message
whitelist?: ChatOpsFilter, // whitelist for messages that allow to send to ChatOps Room
blacklist?: ChatOpsFilter, // blacklist for messages that forbidden to send to ChatOps Room
}
wechaty.use(ChatOps(config))
6 RoomConnector(s)
Connect rooms together, it supports three modes:
1:N - OneToManyRoomConnector can broadcast the messages in one room to others.
M:1 - ManyToOneRoomConnector can summary messages from rooms into one room.
M:M - ManyToManyRoomConnector will broadcast every message between rooms.
M:N - SourceToTargetRoomConnector will broadcast every message from source room(s) to target room(s).
The difference between SourceToTargetRoomConnector and ManyToManyRoomConnector is that:
SourceToTargetRoomConnector have two options to specify:
source: use RoomMatcherOptions to specify the source rooms
target: use RoomFinderOptions to specify the target rooms
ManyToManyRoomConnector have one option to specify:
many: use string[] as list of room ids to broadcast to
The Wechaty Plugin Contrib will only accept simple plugins which does not dependence very heavy NPM modules, and the SLOC (Source Line Of Code) is no more than 100.
There are many great Wechaty Plugins can not be included in the contrib because they are too powerful. They will be published as a NPM by itself.
We are listing those powerful Wechaty Plugins outside the contrib as in the following list, and you are welcome to add your plugin below if you have published any!
VoteOut Plugin by @gcaufy - help you to have a vote and kick out feature for you room.
Schedule by @gcaufy - easily schedule jobs for your Wechaty bots.
GotKicked by @JesseWeb - monitor whether your bot got kicked out of group chat. Just few line of code to implement this instead fussy judging.
Log Monitor by @ArchyWillHe - For log-related DevOps using only WeChat! Fully functional! Very loose coupling! Pretty much pure (other than side effects in I.O.)! Also contains features like QR Rescue (aka 掉线给码) for 2 Wechaties to rescue one another when one is disconnected from the grpc server.
Wechaty Xyao by @watertao - Wechaty Xyao Plugin gives bot ability to execute instruction with distributed brain module.
wechaty-plugin-contrib
Wechaty Plugin Contrib Package for the Community
Introduction
When you find yourself writing repetitive code, it’s time to extract it into a plugin.
Wechaty has a great support for using Plugins by calling
Wechaty.use(WechatyPlugin()). A Wechaty Plugin is a JavaScript function that returns a function which accepts a Wechaty instance.The first Wechaty Plugin system was design by our core team developer @gcaufy from issue #1939(Wechaty Plugin Support with Kick out Example) to PR #1946(feat: added wechaty plugin).
This package is for publishing the Wechaty Plugins that are very common used by the core developer team.
Requirements
Plugins Contrib
You are welcome to send your plugin to our contrib by creating a Pull Request!
dongif bot receives adingmessage.'scan' | 'login' | 'message'… etc.1:N,M:1, andM:Nmodesawaitsyntax #131 DingDong
dongif bot receives adingmessage.configas a Functionconfigcan also be a function which receives amessage: Messageand returns abooleanresult to decide whether response adingmessage.Config: (message: Message) => boolean | Promise<boolean>2 EventLogger
"dong" | "message" | "error" | "friendship" | "heartbeat" | "login" | "logout" | "ready" | "reset" | "room-invite" | "room-join" | "room-leave" | "room-topic" | "scan"3 QR Code Terminal
4 Heartbeat
5 ChatOps
6
RoomConnector(s)Connect rooms together, it supports three modes:
1:N-OneToManyRoomConnectorcan broadcast the messages in one room to others.M:1-ManyToOneRoomConnectorcan summary messages from rooms into one room.M:M-ManyToManyRoomConnectorwill broadcast every message between rooms.M:N-SourceToTargetRoomConnectorwill broadcast every message from source room(s) to target room(s).The difference between
SourceToTargetRoomConnectorandManyToManyRoomConnectoris that:SourceToTargetRoomConnectorhave two options to specify:source: useRoomMatcherOptionsto specify the source roomstarget: useRoomFinderOptionsto specify the target roomsManyToManyRoomConnectorhave one option to specify:many: usestring[]as list of room ids to broadcast to6.1
OneToManyRoomConnector()6.2
ManyToOneRoomConnector()6.3
ManyToManyRoomConnector()6.4
SourceToTargetRoomConnector()7 FriendshipAccepter
Accept friendship automatically, and say/do something for greeting.
greetingwill be sent after the friendship has been accepted.keywordif set, the friendship must match thekeywordtext.8 RoomInviter
Invite a contact to the room with
password,welcome(public message), andrule(private message) options supported.9 EventHotHandlerDEPRECATED after v0.15Hot reloading event handler module files.
10 RoomInvitationAccepter
Automatically accepting any room invitations.
11 messagePrompter
awaitsyntax (await messagePrompter(message)(...)).Other arguments
includeregexwhich is tested on the message andtimeoutSecondwhich automatically rejects the dialog after specified seconds.Learn more from:
Wechaty Plugin Directory
The Wechaty Plugin Contrib will only accept simple plugins which does not dependence very heavy NPM modules, and the SLOC (Source Line Of Code) is no more than 100.
There are many great Wechaty Plugins can not be included in the contrib because they are too powerful. They will be published as a NPM by itself.
We are listing those powerful Wechaty Plugins outside the contrib as in the following list, and you are welcome to add your plugin below if you have published any!
History
master v1.0
SourceToTargetRoomConnectorto connect a source room to a target room by forward messages to target room.EventHotHandlerdue to ESMMessageAwaiterplugin tomessagePrompterhelper function. (#60)v0.14 master
types.SayableMessageandtypes.toSayableMessagedmrenamed tocontactatrenamed tomentionv0.10 (Jun 14, 2020)
talkers.*,finders.*, andmatchers.*mappers.messageMapper()matcher.languageMatcher()v0.8 (Jun 13, 2020)
Add more helper utility functions.
RoomMatcher,ContactMatcher,MessageMatcherRoomTalker,ContactTalker,MessageTalkerRoomFinder,ContactFinderv0.6 (Jun 9, 2020)
OneToManyRoomConnector,ManyToOneRoomConnector, andManyToManyRoomConnector.FriendshipAccepterfor setting to accept friendship automatically.RoomInviterfor invite user to rooms withpassword,rule, andwelcomeoptions support.EventHotHandlerfor hot reloading event handler module files.v0.4 (May 2020)
ChatOps: forward all DM & Mention messages to a Room for logging.v0.2 (May 2020)
Added the following Wechaty Plugins:
v0.0.1 (Apr 2020)
The
wechaty-plugin-contribproject was kicked off by the issue Wechaty Plugin Support with Kickout Example #1939 and the PR feat: added wechaty plugin #1946.Contributors
Maintainers
Copyright & License