Botmaster

The Botmaster class to rule them all

Kind: global class

new Botmaster(settings)

sets up a botmaster object attached to the correct server if one is set as a parameter. If not, it creates its own http server

Param Type
settings object

Example

// attach the botmaster generated server to port 5000 rather than the default 3000
const botmaster = new Botmaster({
  port: 5000,
});

Example

const http = require('http');

const myServer = http.createServer()
// use my own server rather than letting botmaster creat its own.
const botmaster = new Botmaster({
  server: myServer,
});

botmaster.addBot(bot) ⇒ Botmaster

Add an existing bot to this instance of Botmaster

Kind: instance method of Botmaster
Returns: Botmaster - returns the botmaster object for chaining

Param Type Description
bot BaseBot the bot object to add to botmaster. Must be from a subclass of BaseBot

botmaster.getBot(options) ⇒ BaseBot

Extract First bot of given type or provided id.

Kind: instance method of Botmaster
Returns: BaseBot - The bot found of a class that inherits of BaseBot

Param Type Description
options object must be { type: 'someBotType} or { id: someBotId }.

botmaster.getBots(botType) ⇒ Array

Extract all bots of given type.

Kind: instance method of Botmaster
Returns: Array - Array of bots found

Param Type Description
botType string (there can be multiple bots of a same type)

botmaster.removeBot(bot) ⇒ Botmaster

Remove an existing bot from this instance of Botmaster

Kind: instance method of Botmaster
Returns: Botmaster - returns the botmaster object for chaining

Param Type
bot Object

botmaster.use(middleware) ⇒ Botmaster

Add middleware to this botmaster object This function is just sugar for middleware.__use in them

Kind: instance method of Botmaster
Returns: Botmaster - returns the botmaster object so you can chain middleware

Param Type
middleware object

Example

// The middleware param object is something that looks like this for incoming:
{
 type: 'incoming',
 name: 'my-incoming-middleware',
 controller: (bot, update, next) => {
   // do stuff with update,
   // call next (or return a promise)
 },
 // includeEcho: true (defaults to false), opt-in to get echo updates
 // includeDelivery: true (defaults to false), opt-in to get delivery updates
 // includeRead: true (defaults to false), opt-in to get user read updates
}

// and like this for outgoing middleware

{
 type: 'outgoing',
 name: 'my-outgoing-middleware',
 controller: (bot, update, message, next) => {
   // do stuff with message,
   // call next (or return a promise)
 }
}

botmaster.useWrapped(incomingMiddleware, outgoingMiddleware) ⇒ Botmaster

Add wrapped middleware to this botmaster instance. Wrapped middleware places the incoming middleware at beginning of incoming stack and the outgoing middleware at end of outgoing stack. This function is just sugar middleware.useWrapped.

Kind: instance method of Botmaster
Returns: Botmaster - returns the botmaster object so you can chain middleware

Param Type Description
incomingMiddleware object
outgoingMiddleware object The middleware objects are as you'd expect them to be (see use)

results matching ""

    No results matching ""