Skip to content

Latest commit

 

History

History
68 lines (55 loc) · 2.34 KB

README.md

File metadata and controls

68 lines (55 loc) · 2.34 KB

ubibot-util

Core engine of ubibot framework.

Currently alpha code

installation

npm install @numical/ubibot-util

usage

Treat as a library of utility functions:

const { respondTo } = require("@numical/ubibot-engine");
...
const reponse = respondTo(command);

api

This module exports a single function:

###respondTo(request, respond)

  • iteratively calls itself whilst respond(request) results in a function;
    arguments
    - request (any) : arbitary argument passed to respond function;
    - respond (function) : accepts a single argument
    returns
    (any) - the first non-function response in the iterative chain

usage

This library provides a single function to create or access a configuration object used by an ubibot implementation.

'setter' mode

Pass arguments to create a configuration object:

  • sets default values;
  • merges in domain-specific configuration;
  • validates the result.

Typical usage follows this pattern:

const { configure } = require("@numical/ubibot-config");
const domainOptions = { ... };
const config = configure(domainOptions);
...

The resultant config object is then used as an argument for any package that instantiates an ubibot instance - generally a channel package such as @numical/ubibot-channel-cli.

'getter' mode

If no arguments are passed this simply returns the default or last generated configuration.

const { configure } = require("@numical/ubibot-config");
const config = configure();
...

The package guards against modification after the getter has been called - see api for details.

api

This module exports a single function:

###configure([options], [allowModifyAfterGet])

  • creates or returns a previously created configuration object for an ubibot implementation;
    arguments
    - options (optional Object) : a dictionary to be merged with default configuration; will be validated;
    - allowModifyAfterGet (optional boolean) : default behaviour is to throw an error if this function is called as a setter after having been called as a getter; set this value to true to override this; returns
    (object) - the created (setter) or previously created (getter) configuration.