Processor

Processor

Exists while a Handler is being processed. Contains all data a Handler and Requirement might need and gets passed to all Handlers and Requirements as the second parameter in their Callable~callable

Constructor

new Processor()

Properties:
Name Type Description
data object

Data to handle

bot Bot

Bot that invoked the handling

handler Handler

Handler, containing its options, etc

params object

Requirements' values

apiUrl string

Request's passed API URL

route string

Request's route

processor this

The processor itself, for use when destructing

Source:

Methods

handle(callback)

Handles the update data

Parameters:
Name Type Description
callback function

Called when Handler is done executing

Source:

send(method, update, callback, optionsopt)

Sends an update using the request's API URL instead of the bot's

this

// wrong
(done, { send }) => {
  send('message', { text: "doesn't work!" });
}

The reason this given example doesn't work is that send is called from out of the Processor object. Since the send method uses the Bot stored in the Processor (which is normally located at this), a ReferenceError is thrown.

The following way, send is executed from within the processor object.

// fix: call from the processor
(done, processor) => {
  processor.send('message', { text: 'works!' });
}
// fix: make use of that the processor object contains itself
(done, { data, processor }) => {
  processor.send('message', data.text)
}

As stated in Callable~callable, when a normal function is used as the callable instead of an arrow function, this is bound to the Processor object, so that can also be used.

// fix: call send from `this` in a normal function
function someCallable(done, { data }) {
  console.log('can still use the destructed processor to have easier' +
   'access to properties like', data);
  this.send('sendMessage', { text: 'works!' })
}
Parameters:
Name Type Attributes Description
method string

Is appended to the API's URL

update object

The update object that should be sent

callback Bot~response

Callback containing error, response and body

options object <optional>

Options object

Properties
Name Type Attributes Description
silent boolean <optional>

Will not log the response if true

apiUrl string <optional>

Custom API URL

Source: