0.0.2 • Published 7 years ago

wiz-js v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

wiz-js

Reactive framework for bot development

Warning this is for experimental use only

Install

npm install wiz-js --save

Example of use

const { Wiz, Action, Context, Provider } = require('wiz-js');

function setActionContext(ctx, next) {
    ctx.pushAction('HELLO_WORLD');
    next();
}

class MyProvider extends Provider {
    constructor(bar) {
        super();
        this.foo = bar;
    }

    someMethod() {
        return this.foo;
    }
}

const HELLO_WORLD = new Action([
    {
        rule: ctx => ctx.of('action:HELLO_WORLD'),
        action: (ctx, { MyProvider }) => {
            console.log(MyProvider.someMethod(), MyProvider.context());
            return `Hello ${ctx.input()}`;
        },
    },
]);

const wiz = new Wiz({
    middlewares: [
        setActionContext,
    ],
    actions: [
        HELLO_WORLD,
    ],
    providers: [
        new MyProvider('MyConfigurationValues-1283628192hd82'),
    ],
});

wiz.listen(new Context({
    input: 'world',
})).subscribe((botAnswer) => {
    console.log(botAnswer);
});
0.0.2

7 years ago

0.0.1

7 years ago