Overview

Modules allow developers to easily add functionality to their bots and reuse it across bots, for example:

  • Dialogs and views - to handle specific types of conversations
  • Adapters - to connect to messaging platforms
  • Brains - to expand the range of the type of databases in which bot data can be stored
  • NLU units - to connect to your preferred natural language understanding platforms

Intents, static content and templates are out of scope for the moment.

Having these functionalites implemented in modules, rather than in the SDK itself, gives the developer more freedom and limit breaking changes in the SDK.

Resolution

Botfuel components are resolved in the following order:

  • Bot components
  • Module components (in the order of appearance in config.modules)
  • SDK components

Botfuel modules and external modules

There are two types of modules: Botfuel modules and external modules.

Botfuel modules are edited by Botfuel and are named following this pattern: botfuel-module-XXX.

How to use a module in a bot

In order to use module module-XXX, you need to declare it in package.json and in the bot config file.

Adding a module module-XXX to package.json

Adding a module module-XXX to package.json using yarn

yarn add module-XXX

Adding a module module-XXX to package.json using npm

npm install module-XXX

Adding a module to the bot configuration file

The bot config has a member modules that lists the package names that will be taken into account at resolution time.

module.exports = {
  modules: [..., 'module-XXX'],
};

How to create a module

Structure of a module

Modules have the same structure as bots. Currently, the following directories are supported:

  • Adapters
  • Brains
  • Dialogs
  • Nlus
  • Views

index.js

The file index.js of the module exports a member botfuelModuleRoot that points to that file tree (eg src or build).

Module code exposed by botfuelModuleRoot is required by Botfuel Dialog. It can rely on babel presets latest and stage-2 (details here).

Sample module

This sample module can be used as a starting point when creating a new module.

It is used in package test-modules.