Configuration

This document covers all you need to know to configure your bot. Regarding credentials, refer to Getting started.

Configuration files

A configuration file is a .js file exporting a configuration object:

module.exports = {
  ...
};

It is passed as an argument to a command (train, start or test). For example, to run a start command (which runs the bot) with a configuration file name botfuel-config.js:

BOTFUEL_APP_TOKEN=... BOTFUEL_APP_ID=... BOTFUEL_APP_KEY=...  yarn run start botfuel-config

You can omit the .js extension when passing the config file name to the bot command.

Configuration files allow you to configure many parts and behaviors of the bot.

Adapter

The adapter is configured using the adapter key.

module.exports = {
  ...
  adapter: {
    name: 'botfuel',
  },
  ...
};

Parameters:

Parameter Descrition Values Default
name Adapter name botfuel , messenger , shell , test shell

See the adapters document for more about adapters.

Brain

The brain is configured using the brain key. For example:

module.exports = {
  ...
  brain: {
    name: 'memory',
    conversationDuration: 86400000, // ms ==> 1 day
  },
  ...
};

Parameters:

Parameter Descrition Values Default
name Brain name memory , mongo memory
conversationDuration The maximum duration of a conversation beyond which a new conversation is created number (ms) 86400000 (1 day)

See brains document for more about brains.

Locale

The language is configured using the locale key. The default value is 'en' (English).

module.exports = {
  ...
  locale: 'en',
  ...
};

Possible values are:

  • 'en' (English)
  • 'fr' (French)
  • 'es' (Spanish)

Logging

Botfuel Dialog uses the Logtown logging facade together with the Winston logger.

The logger is configured using logger key. The default value is 'info' that logs only messages with severity greater than or equal to 'info'.

module.exports = {
  ...
  logger: 'info',
  ...
};

Pre-configured loggers

Botfuel Dialog comes with three pre-configured loggers:

  • 'debug'
  • 'info'
  • 'error'

Custom loggers

It is also possible to define your own logger.

For example, let's define a logger that mutes the brain of the bot. Simply add logger: 'mute' to your config file and, under the root of the bot, a file loggers/mute.js with the following content:

const WinstonWrapper = require('logtown-winston');
const winston = require('winston');

const transports = [
  new winston.transports.Console({
    json: false,
    colorize: true,
    prettyPrint: true,
    timestamp: true,
    handleExceptions: true,
    align: false,
    level: 'debug',
  }),
];

const options = {
  exitOnError: false,
};

module.exports = {
  wrapper: new WinstonWrapper(transports, options),
  config: {
    namespaces: {
      Brain: {
        disable: ['debug'],
      },
      MongoBrain: {
        disable: ['debug'],
      },
      MemoryBrain: {
        disable: ['debug'],
      },
    },
  },
};

Modules

Configuration of modules is defined with the key modules. The value is the array of module names (with the same syntax as the corresponding Node.js packages). The default value is [].

Here is an example of a bot using a module called botfuel-module-facetedsearch.

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

See modules document for more about modules.

Natural Language Understanding

Configuration of the natural language understanding service is defined by the key nlu. The default value is { name: 'botfuel'} corresponding to the Botfuel Natural Language Understanding service.

module.exports = {
  ...
  nlu: {
    name: 'botfuel',
  },
  ...
};

This value would need to be changed if you intend to use a different NLU service.

Spell checking

Botfuel provides a spell checking API.

To enable it in your bot, simply add spellchecking: true to the NLU section of your config file.

module.exports = {
  ...
  nlu: {
    spellchecking: true,
  },
  ...
};

Custom configuration

You can define custom configuration using the custom key in your config file.

module.exports = {
  ...
  custom: {
    foo: 'bar',
  },
  ...
};

This custom configuration will be accessible in all your dialogs.

const { BaseDialog } = require('botfuel-dialog');

class MyDialog extends BaseDialog {
  dialogWillDisplay(userMessage, data) {
    console.log(this.config.foo); // This will log 'bar'
  }
}