Node People Magic

    bot-worker-engine

    0.1.3 • Public • Published

    Bot Worker Engine

    Build StatusJavaScript Style Guide

    A simple bot engine dispatching workers. (mostly and deliberately without OOP)

    Installation

    npm install bot-worker-engine
    

    Usage

    Here is a simple counting echo bot as example. This might be inside the function which received a web hook call and normalized the input data from one messaging event

    const {orchestrate} = require('bot-worker-engine')
    const {send, userDate} = require('<platform-dependent-connector>')
    const persistence = require('<persistence-layer')
    // these are where your code goes
    const helpers = require('./helpers') // any helper functions you might need
    // example worker just
    const workers = {
      main: (dispatcher, store, bot, helpers) => {
        const {text, session} = store.getState().input
        bot.send.text(`Echo (${session.count}): ${text}`)
        store.dispatch({type: 'INCREMENT_COUNT'})
        dispatcher.emit('finished')
      }
    }
    const reducer = (action, state) => {
      switch(action.type) {
        case 'INCREMENT_COUNT':
          const session = state.session
          session.count++
          return Object.assign({}, state, {session})
        default:
          return state
      }
    } // Redux reducer function
    const sessionDefaults = {count: 1} // defaults for empty sessions
     
    // this starts the whole process of the normalized input
    orchestrate({input, sessionDefaults, workers, reducer, persistence, send, userData, helpers})

    Install

    npm i bot-worker-engine

    DownloadsWeekly Downloads

    2

    Version

    0.1.3

    License

    MIT

    Last publish

    Collaborators

    • heitzerj.dpm
    • timmyjs.dpm
    • thomas.limp
    • antesberger