flowchat

    0.3.3 • Public • Published

    flowchat

    Join the chat at https://gitter.im/flowchat/github npm version Build Status Coverage Status Dependency Status Documentation

    flowchat is a modern ES6 reactive framework for building scalable, maintainable and testable chat bots.

    With flowchat your chat bot consists of multiple flows that are triggered by incoming messages or by other flows.

    Flows

    Each flow determines how the state of the conversation changes and how the bot responds.

    A flow consists of three elements:

    • activator - a function that determines whether the flow should run for a given input and conversation state. Synchronous or Promise-based.
    • reducer - a redux reducer that specifies how the conversation state should change for a given input.
    • saga - a redux-saga that allows running asynchronous code for a given input at ease, including replying to the user or communicating with APIs.

    I/O

    flowchat provides Subject input, output and state, making no assumptions on where the conversation input comes from and where the output should go, or how you persist the conversation state. Using Subject for input, output and state also allows for their easy and modular mapping.

    The Gist

    helloFlow.js

    import { send } from 'flowchat';
     
    const activator = (input, state) => input === 'hello';
     
    const reducer = (input, state) => Object.assign({}, state, { saidHello: true });
     
    function* saga (input, state, sessionId) {
      yield send('Hello, user!', sessionId);
    }
     
    export const helloFlow = [activator, reducer, saga];

    app.js

    import { Flowchat } from 'flowchat';
     
    import { helloFlow } from './helloFlow';
     
    const bot = new Flowchat();
    let sessionId = Math.random();
     
    bot.flow('/hello', ...helloFlow);
     
    bot.state.subscribe(({ state, sessionId }) => console.log('state:', newState));
    bot.output.subscribe(({ data, sessionId }) => console.log('data:', data));
     
    bot.input.onNext({ data: 'hello', state: { saidHello: false }, sessionId });
    // logs "state: { saidHello: true }"
    // logs "data: Hello, user!"
     

    Getting started

    Install

    $ npm install --save flowchat

    or

    $ yarn add flowchat

    Documentation

    Basics concepts

    • Getting started [COMING SOON]
    • Session [COMING SOON]
    • Creating a Facebook Messenger chat bot [COMING SOON]

    Advanced topics

    • Plugging AI [COMING SOON]
    • i18n
    • Creating a middleware [COMING SOON]
    • Using with Immutable.js [COMING SOON]

    Install

    npm i flowchat

    DownloadsWeekly Downloads

    13

    Version

    0.3.3

    License

    none

    Last publish

    Collaborators

    • maciejzasada