Options
All
  • Public
  • Public/Protected
  • All
Menu

bBot

Index

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

NLUKeys

NLUKeys: keyof NLUKey

NaturalLanguageCriteria

NaturalLanguageCriteria: object

Collection of NLU matching criteria by key

Type declaration

NaturalLanguageResults

NaturalLanguageResults: object

Collection of NaturalLanguageResult instances by key

Type declaration

NaturalLanguageResultsRaw

NaturalLanguageResultsRaw: object

Collection of raw NLU results by key (also used for matched subset)

Type declaration

Variables

Const adapterTypes

adapterTypes: string[] = ['message', 'nlu', 'storage']

Collection of allowed adapter types for loading.

Const adapters

adapters: object

Collection of adapter types and their loaded adapter.

Type declaration

align

align: align

Const argsInfo

argsInfo: "All option can be provided as environment variables, with the prefix `BOT_`.Config can also be declared in `package.json` with the key: "botConfig".For more information, see http://bbot.chat/docs/config'" = `All option can be provided as environment variables, with the prefix \`BOT_\`.Config can also be declared in \`package.json\` with the key: "botConfig".For more information, see http://bbot.chat/docs/config'`

Const bits

bits: object

Keep all created bits, for getting by their ID as key

Type declaration

  • [id: string]: Bit

colorize

colorize: colorize

combine

combine: combine

Const eventDelay

eventDelay: __promisify__ = promisify(setImmediate)

Await helper, pauses for event loop

Const events

events: Events = new Events()

Event Emitter for listening to bot events.

example

As module import * as bbot from 'bbot' bbot.events.on('started', () => console.log('bbot is ready'))

example

As script module.exports = (bot) => { bot.events.on('started', () => console.log('bbot is ready')) }

Const global

global: Path = new Path()

Global path to process any state not within specific isolated context.

json

json: json

Const keepExcludes

keepExcludes: string[] = ['bot']

Set keys to remove from data before keep

Const logger

logger: Logger = winston.createLogger({level: process.env.BOT_LOG_LEVEL,transports: [new winston.transports.File({filename: 'error.log',level: 'error',maxsize: 500000,format: combine(timestamp(), json())}),new winston.transports.File({filename: 'combined.log',level: 'debug',maxsize: 500000,format: combine(timestamp(), json())}),new winston.transports.Console({format: combine(colorize(), align(), winston.format.printf((nfo: any) => {return `${nfo.level}: ${nfo.message}`}))})],exceptionHandlers: [new winston.transports.File({ filename: 'exceptions.log' })],exitOnError: (err: Error) => (typeof (err as any).middleware === 'undefined')})

Winston logger provides a logging interface common to many Node apps, with custom levels, filters, and outputs, and service integrations. It will also handle exceptions and exit after logging (except middleware).

By default, all log items will write to console and a combined log file, errors also write to a an error log file. Log level can be set globally or for each transport:

example

Suppress all bot error file logs import { logger } from 'bbot/logger' logger.level = 'silent' logger.transports.errors.level = 'error'

Const middlewares

middlewares: object

Collection of middleware types and their stacks.

Type declaration

Const models

models: object

Type declaration

  • [key: string]: Model<Document>

Const packageJSON

packageJSON: IPackage = require('../../package.json')

Const settings

settings: Settings = new Settings()

Access the settings instance, to replace options and reload config

timestamp

timestamp: timestamp

Functions

actMiddleware

  • actMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute with catch-all match

    Parameters

    Returns void

Const argsError

  • argsError(msg: string, err: Error): void

camelCase

  • camelCase(str: string): string
  • Utility for converting option keys, from foo-bar to fooBar

    Parameters

    • str: string

    Returns string

clearMemory

  • clearMemory(): void
  • Empty memory and start fresh with minimal empty collections

    Returns void

clearSaveInterval

  • clearSaveInterval(): void

convertInstance

  • convertInstance(data: any): any
  • Convert instance to plain object for storage

    Parameters

    • data: any

    Returns any

counter

  • counter(prefix?: string): string
  • Get the next value in global counter

    Parameters

    • Default value prefix: string = "uid"

      Key for counter, prepend to return value

    Returns string

Const deepClone

  • deepClone(obj: any): any
  • Magic function to un-weird weird things

    Parameters

    • obj: any

    Returns any

directPattern

  • directPattern(regex: RegExp): RegExp
  • Build a regular expression that matches text prefixed with the bot's name

    • matches when alias is substring of name
    • matches when name is substring of alias

    Parameters

    • regex: RegExp

    Returns RegExp

dispatch

  • Initiate chain of thought processes for an outgoing envelope. This is for sending unprompted by a branch. Final state is remembered.

    Parameters

    Returns Promise<State>

doBit

  • doBit(id: string, b: State): Promise<void>
  • Execute a bit using its ID, providing current bot state

    Parameters

    Returns Promise<void>

find

  • find(collection: string, params?: any): Promise<any>
  • Query store for subset matching params, via adapter

    Parameters

    • collection: string
    • Default value params: any = {}

    Returns Promise<any>

findOne

  • findOne(collection: string, params: any): Promise<any>
  • Query store for single value matching params, via adapter

    Parameters

    • collection: string
    • params: any

    Returns Promise<any>

get

  • get(key: string, collection?: string): any
  • Retrieve value from memory by key within given (or default) collection.

    Parameters

    • key: string
    • Default value collection: string = "private"

    Returns any

Const getConfig

  • getConfig(): Arguments
  • Return config directly, without updating those in the settings instance

    Returns Arguments

getModel

  • getModel(collection: string): Model<Document>

getStatus

  • getStatus(): string
  • Find out where the loading or shutdown process is at.

    Returns string

hearMiddleware

  • hearMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute before any matching

    Parameters

    Returns void

hyphenate

  • hyphenate(str: string): string
  • Utility for converting option keys, from fooBar to foo-bar

    Parameters

    • str: string

    Returns string

keep

  • keep(collection: string, data: any): Promise<void>
  • Keep serial data in collection, via adapter (converted to plain objects)

    Parameters

    • collection: string
    • data: any

    Returns Promise<void>

listenMiddleware

  • listenMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute after branch match

    Parameters

    Returns void

load

  • load(): Promise<void>
  • Load all components. Extensions/adapters can interrupt or modify the stack before start.

    Returns Promise<void>

loadAdapter

  • loadAdapter(adapterPath?: undefined | string): any
  • Require adapter module from local path or NPM package. If a module name is given, it will be required as normal or from the parent module path. If that fails, attempt to load from the included adapters path. If local path given, attempt to resolve a number of possible locations in case bBot running from tests or as a local dependency (in development).

    Parameters

    • Optional adapterPath: undefined | string

    Returns any

loadAdapters

  • loadAdapters(): void
  • Load all adapters, but don't yet start them.

    Returns void

loadMemory

  • loadMemory(): Promise<void>
  • Update internal memory with any data set (mostly used on load)

    Returns Promise<void>

loadMiddleware

  • loadMiddleware(): void
  • Thought process middleware collection. Contains pieces for async execution at each stage of input processing loop.

    Returns void

lose

  • lose(collection: string, params: any): Promise<void>
  • Remove anything from collection in storage that matches params

    Parameters

    • collection: string
    • params: any

    Returns Promise<void>

pause

  • pause(): Promise<void>
  • Stop temporarily. Allow start to be called again without reloading

    Returns Promise<void>

random

  • random(prefix?: undefined | string): string
  • Generate a random unique ID value

    Parameters

    • Optional prefix: undefined | string

      Optionally prepend ID type

    Returns string

receive

  • receive(message: Message, path?: bot.Path): Promise<State>
  • Initiate sequence of thought processes for an incoming message. Branch callbacks may also respond. Final state is remembered.

    Parameters

    • message: Message
    • Optional path: bot.Path

    Returns Promise<State>

rememberMiddleware

  • rememberMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute before storing data

    Parameters

    Returns void

reset

  • reset(): Promise<void>
  • Scrub it clean! Would allow redefining classes before calling start again, mostly for tests.

    Returns Promise<void>

respond

  • Initiate a response from an existing state. Sequence does not remember because it will usually by triggered from within the receive sequence.

    Parameters

    Returns Promise<State>

respondMiddleware

  • respondMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute before sending any response

    Parameters

    Returns void

saveMemory

  • saveMemory(): Promise<void>
  • Save internal memory back to storage adapter (as memory type)

    Returns Promise<void>

set

  • set(key: string, value: any, collection?: string): "/home/circleci/repo/src/index"
  • Save key-value pair under the collection namespace, extend existing data. Set is used for temporal in-memory data for common interactions. For large data sets that will be infrequently accessed, use keep instead.

    Parameters

    • key: string
    • value: any
    • Default value collection: string = "private"

    Returns "/home/circleci/repo/src/index"

setSaveInterval

  • setSaveInterval(newInterval?: undefined | number): void
  • Save memory every x milliseconds

    Parameters

    • Optional newInterval: undefined | number

    Returns void

setStatus

  • setStatus(set: "waiting" | "loading" | "loaded" | "starting" | "started" | "shutdown"): void
  • Private helper for setting and logging loading status.

    Parameters

    • set: "waiting" | "loading" | "loaded" | "starting" | "started" | "shutdown"

    Returns void

setupBit

  • setupBit(options: IBit): string
  • Add new bit to collection, returning its ID

    Parameters

    Returns string

shutdown

  • shutdown(exit?: number): Promise<void>
  • Make it stop! Stops responding but keeps history and loaded components. Will wait until started if shutdown called while starting.

    example

    import * as bbot from 'bbot' bbot.shutdown()

    Parameters

    • Default value exit: number = 0

    Returns Promise<void>

shutdownAdapters

  • shutdownAdapters(): Promise<void[]>
  • Run shutdown on each adapter concurrently, to resolve when all shutdown

    Returns Promise<void[]>

shutdownMemory

  • shutdownMemory(): Promise<void>
  • Save data and disconnect storage adapter

    Returns Promise<void>

start

  • start(): Promise<void>
  • Make it go!

    example

    import * as bbot from 'bbot' bbot.start()

    Returns Promise<void>

startAdapters

  • startAdapters(): Promise<void[]>
  • Start each adapter concurrently, to resolve when all ready.

    Returns Promise<void[]>

startMemory

  • startMemory(): Promise<void>
  • Populate brian with temporal data from storage adapter and get started

    Returns Promise<void>

understandMiddleware

  • understandMiddleware(middlewarePiece: IPiece): void
  • Register middleware piece to execute with NLU before intent match

    Parameters

    Returns void

unloadAdapters

  • unloadAdapters(): void

unloadMiddleware

  • unloadMiddleware(): void

unset

  • unset(key: string, collection?: string): "/home/circleci/repo/src/index"
  • Remove item from memory by key and collection namespace (optional).

    Parameters

    • key: string
    • Default value collection: string = "private"

    Returns "/home/circleci/repo/src/index"

Const use

userById

  • userById(id: string, meta?: any): User
  • Get a User object by ID. If found and given meta, overwrites and returns updated user. if given meta and ID not found, creates new user.

    Parameters

    • id: string
    • Optional meta: any

    Returns User

users

  • users(): object
  • Shortcut to get the user collection from memory

    Returns object

    • [id: string]: User

usersByName

  • usersByName(name: string): User[]

Object literals

Const counts

counts: object

Maintain a list of global counters against their prefix key

uid

uid: number = 0

Const initOptions

initOptions: object

Initial array of config options, can be extended prior and post load.

alias

alias: object

describe

describe: string = "Alternate name for the bot."

type

type: "string" = "string"

auto-save

auto-save: object

default

default: boolean = true

describe

describe: string = "Save data in the brain every 5 seconds (defaults true)."

type

type: "boolean" = "boolean"

log-level

log-level: object

default

default: string = "info"

describe

describe: string = "The starting minimum level for logging events (silent|debug|info|warn|error)."

type

type: "string" = "string"

message-adapter

message-adapter: object

alias

alias: string = "m"

default

default: string = "./adapters/shell"

describe

describe: string = "Local path or NPM package name to require as message platform adapter"

type

type: "string" = "string"

name

name: object

alias

alias: string = "n"

default

default: string = "bot"

describe

describe: string = "Name of the bot in chat. Prepending any command with the name will trigger `direct` branches."

type

type: "string" = "string"

nlu-adapter

nlu-adapter: object

alias

alias: string = "l"

default

default: null = null

describe

describe: string = "Local path or NPM package name to require as message platform adapter"

type

type: "string" = "string"

nlu-min-length

nlu-min-length: object

default

default: number = 15

describe

describe: string = "Minimum string length for NLU parsing to apply on message"

type

type: "number" = "number"

storage-adapter

storage-adapter: object

alias

alias: string = "s"

default

default: null = null

describe

describe: string = "Local path or NPM package name to require as storage engine adapter"

type

type: "string" = "string"

Const intervals

intervals: object

Save tracking vars

save

save: object

value

value: number = 5000

Const memory

memory: object

Internal storage for data, can hold any key/value collection

private

private: object

Type declaration

users

users: object

Type declaration

Const status

status: object

Internal index for loading status

loaded

loaded: 0 = 0

loading

loading: 0 = 0

shutdown

shutdown: 0 = 0

started

started: 0 = 0

starting

starting: 0 = 0

waiting

waiting: 1 = 1

Generated using TypeDoc