Options
All
  • Public
  • Public/Protected
  • All
Menu

bBot

Index

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

Condition

Condition: object

One or more condition key/value pairs.

Type declaration

ConditionCollection

ConditionCollection: object

Collection of condition types assigned to named keys.

Type declaration

ConditionKeys

ConditionKeys: keyof ConditionKey

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: Adapters = new Adapters()

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

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

Const expression

expression: Expression = new Expression()

Const global

global: Path = new Path()

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

json

json: json

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 memory

memory: Memory = new Memory()

Const middleware

middleware: object

Type declaration

Const middlewareTypes

middlewareTypes: string[] = ['hear', 'listen', 'understand', 'act', 'respond', 'remember']

Collection of allowed middleware types for loading.

Const middlewares

middlewares: Middlewares = new Middlewares()

Const models

models: object

Type declaration

  • [key: string]: Model<Document>

Const packageJSON

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

Const request

request: Request = new Request()

Const settings

settings: Settings = new Settings()

Access the settings instance, to replace options and reload config

Const store

store: Store = new Store()

timestamp

timestamp: timestamp

Functions

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

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(): 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

    Returns RegExp

directPatternCombined

  • directPatternCombined(regex: RegExp): RegExp
  • Build a regular expression for bot's name combined with another regex

    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>

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

hyphenate

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

    Parameters

    • str: string

    Returns string

isCondition

  • isCondition(c: any): boolean
  • Type guard to check type of Condition.

    Parameters

    • c: any

    Returns boolean

isConditionCollection

  • isConditionCollection(c: any): boolean
  • Type guard to check type of ConditionCollection

    Parameters

    • c: any

    Returns boolean

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

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>

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>

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>

start

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

    example

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

    Returns Promise<void>

timeoutPromise

  • timeoutPromise(ms: number, promise: Promise<any>): Promise<any>
  • Create a promise wrapper, that rejects if timeout met before resolved

    Parameters

    • ms: number
    • promise: Promise<any>

    Returns Promise<any>

Const use

  • use(bot: any): Mongo
  • use(bot: any): Rocketchat
  • use(bot: "/Volumes/x/code/amazebot/bbot/src/index"): Shell

userById

  • userById(id: string, meta?: any): User
  • Get a user by ID. If found and given meta, updates 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

usersByName

  • usersByName(name: string): User[]

Object literals

Const _defaults

_defaults: object

ignoreCase

ignoreCase: true = true

ignorePunctuation

ignorePunctuation: false = false

matchWord

matchWord: true = true

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"

request-timeout

request-timeout: object

default

default: number = 1500

describe

describe: string = "Maximum milliseconds to wait for a http/s request to resolve"

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 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