Wechaty Plugin Contrib Package for the Community
Image Credit: What is Plugin
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.
- Wechaty v0.40 or above versions
You are welcome to send your plugin to our contrib by creating a Pull Request!
# | Plugin | Author | Feature |
---|---|---|---|
1 | DingDong | @huan | Reply dong if bot receives a ding message. |
2 | EventLogger | @huan | Log Wechaty Events for 'scan' | 'login' | 'message' ... etc. |
3 | QRCodeTerminal | @huan | Show QR Code for Scan in Terminal |
4 | Heartbeat | @huan | Send emoji periodically |
5 | ChatOps | @huan | Forward DM & Mention messages to a room |
6 | RoomConnector | @huan | Connect rooms together with 1:N , M:1 , and M:N modes |
7 | FriendshipAccepter | @huan | Accept friendship automatically, and say/do something for greeting. |
8 | RoomInviter | @huan | Invite user to rooms by keyword |
9 | EventHotHandler | @huan | Hot reloading event handler module files |
10 | RoomInvitationAccepter | @huan | Automatically accepting any room invitations |
11 | MessageAwaiter | @ssine | Wait for a particular message using await syntax #13 |
- Description: Reply
dong
if bot receives ading
message. - Author: @huan
import { DingDong } from 'wechaty-plugin-contrib'
const config = {
mention : true, // default: true - Response to Mention Self (@/at) Message in Room
contact : true, // default: true - Response to Direct Message
room : true, // default: true - Response to Rooms Message
self : true, // default: true - Response to Message that send from the bot itself
}
wechaty.use(DingDong(config))
config
can also be a function which receives a message: Message
and returns a boolean
result to decide whether response a ding
message.
Config: (message: Message) => boolean | Promise<boolean>
- Description: Log Wechaty Events:
"dong" | "message" | "error" | "friendship" | "heartbeat" | "login" | "logout" | "ready" | "reset" | "room-invite" | "room-join" | "room-leave" | "room-topic" | "scan"
- Author: @huan
import { EventLogger } from 'wechaty-plugin-contrib'
const config = ['login', 'ready', 'message']
// Do not provide an config will log all events.
wechaty.use(EventLogger(config))
- 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))
- 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))
- 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))
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
: useRoomMatcherOptions
to specify the source roomstarget
: useRoomFinderOptions
to specify the target rooms
ManyToManyRoomConnector
have one option to specify:many
: usestring[]
as list of room ids to broadcast to
import { OneToManyRoomConnector, OneToManyRoomConnectorConfig } from 'wechaty-plugin-contrib'
const config: OneToManyRoomConnectorConfig = {
blacklist: [ async () => true ],
many: [
'20049383519@chatroom', // 小句子测试
'5611663299@chatroom', // 'ChatOps - Mike BO'
],
map: async message => message.talker().name() + '(one to many): ' + message.text(),
one: '17237607145@chatroom', // PreAngel 动态
whitelist: [ async message => message.type() === Message.Type.Text ],
}
wechaty.use(OneToManyRoomConnector(config))
import { ManyToOneRoomConnector, ManyToOneRoomConnectorConfig } from 'wechaty-plugin-contrib'
const config: ManyToOneRoomConnectorConfig = {
blacklist: [ async () => true ],
many: [
'20049383519@chatroom', // 小句子测试
'5611663299@chatroom', // 'ChatOps - Mike BO'
],
map: async message => message.talker().name() + '(many to one): ' + message.text(),
one: '17237607145@chatroom', // PreAngel 动态
whitelist: [ async message => message.type() === Message.Type.Text ],
}
wechaty.use(ManyToOneRoomConnector(config))
import { ManyToManyRoomConnector, ManyToManyRoomConnectorConfig } from 'wechaty-plugin-contrib'
const config: ManyToManyRoomConnectorConfig = {
blacklist: [ async () => true ],
many: [
'20049383519@chatroom', // 小句子测试
'5611663299@chatroom', // 'ChatOps - Mike BO'
],
map: async message => message.talker().name() + '(many to many): ' + message.text(),
whitelist: [ async message => message.type() === Message.Type.Text ],
}
wechaty.use(ManyToManyRoomConnector(config))
import { SourceToTargetRoomConnector, SourceToTargetRoomConnectorConfig } from 'wechaty-plugin-contrib'
const config: SourceToTargetRoomConnectorConfig = {
blacklist: [ async () => true ],
source: [
'5611663299@chatroom',
/source room topic/i,
],
target: [
'20049383519@chatroom',
/target room topic/i,
],
map: async message => message.talker().name() + '(source to target): ' + message.text(),
whitelist: [ async message => message.type() === Message.Type.Text ],
}
wechaty.use(SourceToTargetRoomConnector(config))
Accept friendship automatically, and say/do something for greeting.
import { FriendshipAccepter, FriendshipAccepterConfig } from 'wechaty-plugin-contrib'
const config: FriendshipAccepterConfig = {
greeting: 'we are friends now!',
keyword: '42',
}
wechaty.use(FriendshipAccepter(config))
greeting
will be sent after the friendship has been accepted.keyword
if set, the friendship must match thekeyword
text.
Invite a contact to the room with password
, welcome
(public message), and rule
(private message) options supported.
import { RoomInviter, RoomInviterConfig } from 'wechaty-plugin-contrib'
const config: RoomInviterConfig = {
password : 'wechaty',
room : '18171595067@chatroom',
welcome : 'Welcome to join the room!',
rule : 'Please be a good people',
repeat : 'You have already in our room',
}
wechaty.use(RoomInviter(config))
Hot reloading event handler module files.
import { EventHotHandler, EventHotHandlerConfig } from 'wechaty-plugin-contrib'
const config: EventHotHandlerConfig = {
login: './handlers/on-login',
logout: './handlers/on0-logout',
}
wechaty.use(EventHotHandler(config))
Automatically accepting any room invitations.
import { RoomInvitationAccepter } from 'wechaty-plugin-contrib'
wechaty.use(RoomInvitationAccepter())
- Description: Wait for a particular message using
await
syntax (await messagePrompter(message)(...)
). - Author: @ssine (refactored by @huan)
import { messageAwaiter } from 'wechaty-plugin-contrib'
wechaty.on('message' async (message) => {
const prompter = messagePrompter(message)
const reply = prompter('Hello')
if (reply) {
await message.say('hint message')
// do anything you want...
}
})
Other arguments include regex
which is tested on the message andtimeoutSecond
which automatically rejects the dialog after specified seconds.
Learn more from:
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.
- WebPanel by @Leo_chen - help you quickly access the web panel
- Intercom by @huan - helps you to manage your customers/leads/users in the WeChat Room, with the power of the Intercom service.
- Wechaty Vorpal by @huan - CLI for Chatbot - Extensible Commands for ChatOps, Powered by Vorpal.
- Freshdesk by @huan - Managing Conversations in WeChat Rooms by Freshdesk.
- QnAMaker by @huan - Wechaty QnAMaker Plugin helps you to answer questions in WeChat with the power of https://QnAMaker.ai.
- Weixin OpenAI by @windmemory - Wechaty Weixin OpenAI Plugin helps you to answer questions in WeChat with the power of https://openai.weixin.qq.com.
- YouDao Translate by @Chs97 - Wechaty YouDao Translate Plugin helps you to translate word in WeChat with the power of https://ai.youdao.com/.
- 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-fanli by @Leo_chen - help you quickly access the rebate robot about taobao
- Add
SourceToTargetRoomConnector
to connect a source room to a target room by forward messages to target room. - Support ES Modules
- Deprecated
EventHotHandler
due to ESM
- Deprecated
- Change
MessageAwaiter
plugin tomessagePrompter
helper function. (#60)
- Add
types.SayableMessage
andtypes.toSayableMessage
- Normalize config option:
dm
renamed tocontact
at
renamed tomention
- Export
talkers.*
,finders.*
, andmatchers.*
- Add Mustache template & view support for all talkers.
- Add
mappers.messageMapper()
- Add
matcher.languageMatcher()
Add more helper utility functions.
- Matchers:
RoomMatcher
,ContactMatcher
,MessageMatcher
- Talkers:
RoomTalker
,ContactTalker
,MessageTalker
- Finders:
RoomFinder
,ContactFinder
- New Plugins:
OneToManyRoomConnector
,ManyToOneRoomConnector
, andManyToManyRoomConnector
. - New Plugin:
FriendshipAccepter
for setting to accept friendship automatically. - New Plugin:
RoomInviter
for invite user to rooms withpassword
,rule
, andwelcome
options support. - New Plugin:
EventHotHandler
for hot reloading event handler module files.
- New plugin:
ChatOps
: forward all DM & Mention messages to a Room for logging.
Added the following Wechaty Plugins:
- DingDong
- EventLogger
- QRCodeTerminal
- Heartbeat
The wechaty-plugin-contrib
project was kicked off by the issue Wechaty Plugin Support with Kickout Example #1939 and the PR feat: added wechaty plugin #1946.
- Code & Docs © 2020 Wechaty Contributors https://github.com/wechaty
- Code released under the Apache-2.0 License
- Docs released under Creative Commons