Skip to content
/ actor Public

Wechaty Actor Model, Powered by XState, Mailbox, and CQRS

License

Notifications You must be signed in to change notification settings

wechaty/actor

Repository files navigation

Wechaty Actor

Wechaty Actor Model, Powered by XState, Mailbox, and CQRS

NPM Version NPM Mailbox.Duckula Specification ES Modules

Wechaty Actor

Image source: RoPA

Wechaty Actor is an wrapper for Wechaty that applies the Actor Model with XState and CQRS.

Actor Model

Actors

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...

Features

  1. Working with wechaty-cqrs by receiving the CQRS Commands and Queries, and responding Responses.
  2. Implemented with XState and Mailbox
  3. Native designed for Domain Driven Design (DDD)

Usage

Install

npm install wechaty-actor wechaty-cqrs wechaty

Quick start

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

Getting Started

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

API Reference

Read Wechaty Actor API Reference at: https://paka.dev/npm/wechaty-actor

Blogs

Resources

History

main

v0.0.1 (May 8, 2022)

Author

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

Copyright & License

  • Code & Docs © 2022 Huan (李卓桓) <[email protected]>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons