We have serval issues when we providing a Chatbot service, like:
Single Point Of Failure (SPOF)
Heartbeat & Keepalive
1 Single Point Of Failure (SPOF)
The Problem #1
Currently we have only one bot on WeChat, which means that if the bot was offline, then our service will be stopped.
The Solution #1
Use two (3 or even 4 will be better) WeChat bot at the same time, with the different wechaty-puppet providers (for example: padlocal + windows).
So when an issue event has come, we can use a RR (round robin) or other very easy to implementing algorithm to make our service both load-balancable and high-available.
When a Wechaty bot is started and logged in, it is mostly liked to be work as expected for sending/receiving messages.
However, sometimes it might run into trouble for some unknown reason, which caused it can not work anymore, but we have nothing to know about that.
In order to check whether a Wechaty bot is available, we need to take a test on it to see if it can send & receive the message successfully.
How can archive that? It is not a good idea if we send a message to another Wechaty bot because it is not stable enough for this kind of online service.
The Solution #2
We can set up an Official Account for WeChat, with an auto-responding strategy that will reply a dong when it receives a ding.
So we let our Chatie Official Account takes the responsibility to provide this service.
HAProxy Requirement
If you want to use HAProxy, please make sure every bot account has followed the ChatieIO WeChat Official Account by scanning the above QR Code.
Usage
import { HAWechaty } from 'ha-wechaty'
import { Wechaty } from 'wechaty'
const wechaty1 = new Wechaty({
puppet: 'wechaty-puppet-service',
puppetOptions: {
token: 'puppet-service-token'
}
})
const wechaty2 = new Wechaty({
puppet: 'wechaty-puppet-padlocal',
puppetOptions: {
token: 'padlocal-token'
}
})
// 1. Configure HAWechaty
const haWechaty = configureHa()
// 2. Add Wechaty instances to HA
haWechaty.add(wechaty1, wechaty2)
// 3. Start HA
await haWechaty.start()
// 4. Find room by our bots
const room = await haWechaty.Room.find({ topic: 'ding room' })
if (room) {
// 5. Send message to room with load balancing and high availabilities
await room.say('ding')
}
High Available (HA) Wechaty
HA Wechaty is a Load Balance for providing High Availability for Wechaty Chatbot by spreading requests across multiple WeChat individual accounts.
One two three, chatbots team up!
Background
How to delivering high levels of SLA uptime?
The Problem of Single Point Of Failure (SPOF)
We have serval issues when we providing a Chatbot service, like:
1 Single Point Of Failure (SPOF)
The Problem #1
Currently we have only one bot on WeChat, which means that if the bot was offline, then our service will be stopped.
The Solution #1
Use two (3 or even 4 will be better) WeChat bot at the same time, with the different wechaty-puppet providers (for example: padlocal + windows).
So when an issue event has come, we can use a RR (round robin) or other very easy to implementing algorithm to make our service both load-balancable and high-available.
2 Heartbeat and Keepalive
The Problem #2
When a Wechaty bot is started and logged in, it is mostly liked to be work as expected for sending/receiving messages.
However, sometimes it might run into trouble for some unknown reason, which caused it can not work anymore, but we have nothing to know about that.
In order to check whether a Wechaty bot is available, we need to take a test on it to see if it can send & receive the message successfully.
How can archive that? It is not a good idea if we send a message to another Wechaty bot because it is not stable enough for this kind of online service.
The Solution #2
We can set up an Official Account for WeChat, with an auto-responding strategy that will reply a
dongwhen it receives ading.So we let our Chatie Official Account takes the responsibility to provide this service.
HAProxy Requirement
If you want to use HAProxy, please make sure every bot account has followed the
ChatieIOWeChat Official Account by scanning the above QR Code.Usage
Environment Variables
1
HA_WECHATY_PUPPETThe wechaty puppet list, seprated by a colon (
:).Examples:
2
HA_WECHATY_PUPPET_TOKENWechaty Puppet Service Tokens that required by the puppets.
This is a token list, seprated by a colon (
:), map to each puppet fromHA_WECHATY_PUPPET.The token set to this environment variable will become the default value of
puppetOptions.tokenwhen instantiating Wechaty.To specify more tokens for a specific puppet, use a colon (
:) to separate them, for example:Development
Redux Remote DevTools
Links
Backoff Alghorithm
See issue: Backoff straitegy #2
Redux
RxJS Testing
RxJS Operators
History
master v0.9 (Sep 12, 2021)
v0.7 (Jun 4, 2021)
BREAKING CHANGE
HA_WECHATY_PUPPET_${PROTOCOL}_TOKENtoHA_WECHATY_PUPPET_TOKENfor easy understanding and prevent mis-configuration.v0.4 (Jun 7, 2020)
v0.0.1 (Apr 2020)
This module was originally design for the project OSSChat #58
Author
Huan LI (李卓桓) zixia@zixia.net
Copyright & License