Callable

Callable

new Callable(object, callable, requiresopt)

Alternative constructors

When registering (Bot#register) a Handler or constructing a Requirement, you can also make use of alternative constructor signatures:

// (object)
new Callable({
  name: 'testCallable',
  callable: (done, processor) => {},
  options: { verbose: true }
});
// (name, callable, requires)
new Callable('testCallable', (done, processor) => {}, []);
// (namedFunction, requires)
new Callable(function testCallable(done, processor) {});

1. (object) - Object constructor

2. (callable, [requires]) - Named function constructor

3. (name, callable, [requires]) - Function constructor

Parameters:
Name Type Attributes Description
object object | function | string

Object, Callable function with name, or Callable's name

Properties
Name Type Attributes Description
name string

Callable's name

callable Callable~callable

Callable function

requires Array.<Requirement> <optional>

Requirements

callable Array.<Requirement> | function

Array of Requirements or Callable

requires Array.<Requirement> <optional>

Array of Requirements

Source:

Methods

prepareRequirements(objectopt)

Flattens the Callback's requires tree to this.requirements

Parameters:
Name Type Attributes Description
object Callable <optional>

Object that might have requires node

Source:

Type Definitions

callable(done, processor)

Since Callable is extended by two classes, and a Callable itself cannot be used, these classes have their own documentation of the callable in which you might be interested:

A callable itself looks like this:

(done, processor) => {
  done();
}

You can also overload parameters to the done callback. See Handler~done and Requirement~done for further information

You can also filter specific properties from the Processor object using the ES6 destruction syntax:

(done, { data, send }) => {
  // send() can not be used as is!
}

Regarding the send method, please read Processor#send!

To be able to destruct the processor to use relevant properties and have access to a working send method, you can use the processor's processor property:

(done, { data, send, processor } => {
  processor.send('message', data);
})

Binding the Processor to the function

Using a function, the Processor is bound to the callable. That means, all properties of Processor can also be accessed through this inside of the callable function, so the processor parameter is optional.

By adding a name to the function, you can leave out the parameter for the Callable name.

// (namedFunction, requires)
new Callable(function testCallable(done, { data }) {
  this.data === processor.data;
  this.send('message', data)
});
Parameters:
Name Type Description
done function

Must be called from the callable when done

processor Processor

Processor object containing all relevant data

Source:
See: