ContentManager

ContentManager

The Content Manager is mainly in charge of storing and retrieving all the content that is stored and known by the bot. The content includes (but is not limited to) the messages that the bot sends to users.

Source:
See:

Example

bp.contentManager

Methods

(async, static) createOrUpdateCategoryItem()

Creates or updates an Element

Source:
Parameters:
Name Type Attributes Description
options.itemId= String <optional>

The id of the element to add

options.categoryId String

The category of the element

options.formData Object

The content of the element

(async, static) getItem(query) → {ContentManager.ElementProvider}

Retrieves one item

Source:
Parameters:
Name Type Description
query String

Usually the id of the ContentManager.Element, but can also be a call to a ContentManager.ElementProvider.

Example
await bp.contentManager.getItem('#!trivia-12345')
await bp.contentManager.getItem('#trivia-random()')

(static) listAvailableCategories() → {Array.<ContentManager~Category>}

Returns all the categories

Source:
Returns:
Type:
Array.<ContentManager~Category>

(async, static) listCategoryItems(categoryId) → {Array.<ContentManager~Element>}

Returns the elements of a given category

Source:
Parameters:
Name Type Attributes Default Description
categoryId String

The category, for example text or trivia.

options.from Number <optional>
0

Pagination parameter (where to start)

options.count Number <optional>
50

Pagination parameter (how many elements to return)

options.searchTerm= String <optional>

Only return the elements containing this term

options.orderBy Array.<String> <optional>
['createdOn']

A list of properties to order the elements by.

Returns:
Type:
Array.<ContentManager~Element>

(static) registerGetItemProvider(name, fn)

Register a new item provider, which is used when parsing query for ContentManager~getItem

Source:
Parameters:
Name Type Description
name String

The name of the provider, e.g. random

fn ContentManager.ElementProvider

A content provider function

Example
// returns a random element from a given category
const randomProvider = (knex, category, args) => {
  return knex('content_items')
    .where({ categoryId: category })
    .orderBy(knex.raw('random()'))
    .limit(1)
    .get(0)
}

bp.contentManager.registerGetItemProvider('random', randomProvider)

Type Definitions

ElementProvider(knex, category, args)

Source:
Parameters:
Name Type Description
knex KnexInstance

An instance of Knex

category String

The name of the category

args String

A string with whatever was passed in the parans e.g. "random(25)"

Example
const randomProvider = (knex, category, args) => {
return knex('content_items')
  .where({ categoryId: category })
  .orderBy(knex.raw('random()'))
  .limit(1)
  .get(0)
}

Category

Properties:
Name Type Description
id String
title String
description String
count Number

The number of elements in that category

schema ContentManager~CategorySchema
Source:
Type:
  • Object

CategorySchema

Properties:
Name Type Description
json Object

The JSONSchema

ui String

The UI JSONSchema

description String
renderer String

The name of the Content Renderer

Source:
Type:
  • Object

Element

Source:
Type:
  • Object