Skip to content

Latest commit

 

History

History
203 lines (127 loc) · 4.87 KB

cms.md

File metadata and controls

203 lines (127 loc) · 4.87 KB

Botkit CMS Plugin Class Reference

← Botkit Documentation ← Class Index

This is a class reference for all the methods exposed by the botkit-plugin-cms package.

Classes

Interfaces


BotkitCMSHelper

A plugin for Botkit that provides access to an instance of Botkit CMS, including the ability to load script content into a DialogSet and bind before, after and onChange handlers to those dynamically imported dialogs by name.

controller.use(new BotkitCMSHelper({
     uri: process.env.CMS_URI,
     token: process.env.CMS_TOKEN
}));

// use the cms to test remote triggers
controller.on('message', async(bot, message) => {
  await controller.plugins.cms.testTrigger(bot, message);
});

To use this class in your application, first install the package:

npm install --save botkit-plugin-cms

Then import this and other classes into your code:

const { BotkitCMSHelper } = require('botkit-plugin-cms');

This class includes the following methods:

Create a new BotkitCMSHelper()

Parameters

Argument Type Description
config CMSOptions

Properties and Accessors

Name Type Description
name string Botkit Plugin name

BotkitCMSHelper Class Methods

after()

Bind a handler function that will fire after a given dialog ends. Provides a way to use BotkitConversation.after() on dialogs loaded dynamically via the CMS api instead of being created in code.

Parameters

Argument Type description
script_name string The name of the script to bind to
handler A handler function in the form async(results, bot) => {}
controller.plugins.cms.after('my_script', async(results, bot) => {

console.log('my_script just ended! here are the results', results);

});

before()

Bind a handler function that will fire before a given script and thread begin. Provides a way to use BotkitConversation.before() on dialogs loaded dynamically via the CMS api instead of being created in code.

Parameters

Argument Type description
script_name string The name of the script to bind to
thread_name string The name of a thread within the script to bind to
handler A handler function in the form async(convo, bot) => {}
controller.cms.before('my_script','my_thread', async(convo, bot) => {

 // do stuff
 console.log('starting my_thread as part of my_script');
 // other stuff including convo.setVar convo.gotoThread

});

init()

Botkit plugin init function Autoloads all scripts into the controller's main dialogSet.

Parameters

Argument Type description
botkit any A Botkit controller object

loadAllScripts()

Load all script content from the configured CMS instance into a DialogSet and prepare them to be used.

Parameters

Argument Type description
botkit Botkit

onChange()

Bind a handler function that will fire when a given variable is set within a a given script. Provides a way to use BotkitConversation.onChange() on dialogs loaded dynamically via the CMS api instead of being created in code.

Parameters

Argument Type description
script_name string The name of the script to bind to
variable_name string The name of a variable within the script to bind to
handler A handler function in the form async(value, convo, bot) => {}
controller.plugins.cms.onChange('my_script','my_variable', async(new_value, convo, bot) => {

console.log('A new value got set for my_variable inside my_script: ', new_value);

});

testTrigger()

Uses the Botkit CMS trigger API to test an incoming message against a list of predefined triggers. If a trigger is matched, the appropriate dialog will begin immediately.

Parameters

Argument Type description
bot BotWorker The current bot worker instance
message Partial<BotkitMessage> An incoming message to be interpretted

Returns

Returns false if a dialog is NOT triggered, otherwise returns void.

Interface CMSOptions

Fields

Name Type Description
controller Botkit
token string
uri string