Wechaty Actor Model, Powered by XState, Mailbox, and CQRS
Image source: RoPA
Wechaty Actor is an wrapper for Wechaty that applies the Actor Model with XState and CQRS.
The Actor Model is a computational model for designing concurrent, distributed systems around the principal of self-contained Actors which operate on sending and receiving messages.
— Introduction to the Actor Model...
- Working with wechaty-cqrs by receiving the CQRS Commands and Queries, and responding Responses.
- Implemented with XState and Mailbox
- Native designed for Domain Driven Design (DDD)
npm install wechaty-actor wechaty-cqrs wechaty
Here's the Actor version of the Wechaty bot usage:
import * as ACTOR from 'wechaty-actor'
import * as CQRS from 'wechaty-cqrs'
import * as WECHATY from 'wechaty'
const wechaty = WechatyBuilder.build()
await wechaty.init()
const actor = ACTOR.from(wechaty)
const BOT_ID = 'BotMachine'
const botMachine = createMachine({
id: BOT_ID,
on: {
'*': {
actions: Mailbox.actions.proxy(BOT_ID)(actor),
},
},
})
const interpreter = interpret(botMachine)
.onEvent(e => console.info(e))
.start()
const startCommand = CQRS.commands.StartCommand(wechaty.puppet.id)
interpreter.send(startCommand)
const dingCommand = CQRS.commands.DingCommand(wechaty.puppet.id)
interpreter.send(dingCommand)
await firstValueFrom(from(actor).pipe(
// filter(CQRS.is(CQRS.events.DongReceivedEvent)),
filter(CQRS.is(CQRS.responses.DingCommandResponse)),
take(1),
))
Learn how to build a Ding Dong BOT with Actor from our examples/ding-dong-bot.ts
Here's a video introduction for CQRS Wechaty with live demo, presented by Huan:
To-be-recorded
The getting started ding-dong-bot.ts in the video: https://github.com/wechaty/getting-started/blob/main/examples/actor/ding-dong-bot.ts
Read Wechaty Actor API Reference at: https://paka.dev/npm/wechaty-actor
- The actor model in 10 minutes
- Node.js actor framework
- Beautiful State Machines - XState Catalogue is a collection of professionally designed state machines you can drop into your projects. Get started by browsing the catalogue, interacting with the machines, and copying the code.
- XState: Should this be an action or a service?
- Introduction to the Actor Model for Concurrent Computation, John Murray, Sep 29, 2015, Tech Talks @ AppNexus
- Kotlin Concurrency with Actors, Jag Saund, Jun 14, 2018
- Pure UI using Xstate and ReactJS
- v0.0.1 (Mar 6, 2022): Init README & Draft design from bot5-assistant#1
Huan LI is a serial entrepreneur, active angel investor with strong technology background. Huan is a widely recognized technical leader on conversational AI and open source cloud architectures. He co-authored guide books "Chatbot 0 to 1" and "Concise Handbook of TensorFlow 2" and has been recognized both by Microsoft and Google as MVP/GDE. Huan is a Chatbot Architect and speaks regularly at technical conferences around the world. Find out more about his work at https://github.com/huan
- Code & Docs © 2022 Huan (李卓桓) <[email protected]>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons