Library class
A library of related dialogs used for routing purposes. Libraries can be chained together to enable the development of complex bots. The UniversalCallBot class is itself a Library that forms the root of this chain. Libraries of reusable parts can be developed by creating a new Library instance and adding dialogs just as you would to a bot. Your library should have a unique name that corresponds to either your libraries website or NPM module name. Bots can then reuse your library by simply adding your parts Library instance to their bot using UniversalCallBot.library(). If your library itself depends on other libraries you should add them to your library as a dependency using Library.library(). You can easily manage multiple versions of your library by adding a version number to your library name.
To invoke dialogs within your library bots will need to call session.beginDialog()
with a fully qualified dialog id in the form of ':'. You'll typically hide
this from the devloper by exposing a function from their module that starts the dialog for them.
So calling something like myLib.someDialog(session, { arg: '' });
would end up calling
session.beginDialog('myLib:someDialog', args);
under the covers.
Its worth noting that dialogs are always invoked within the current dialog so once your within a dialog from your library you don't need to prefix every beginDialog() call your with your libraries name. Its only when crossing from one library context to another that you need to include the library name prefix.
Library(string) | Creates a new instance of the library. |
name | Unique name of the library. |
dialog(string, Dialog | IDialog |
Registers or returns a dialog from the library. |
find |
Searches the library and all of its dependencies for a specific dialog. Returns the dialog if found, otherwise null. |
library(Library | string) | Registers or returns a library dependency. |
Creates a new instance of the library.
new Library(name: string)
Parameters
- name
-
string
Unique name of the library.
name: string
Property Value
string
Registers or returns a dialog from the library.
function dialog(id: string, dialog?: Dialog | IDialogWaterfallStep[] | IDialogWaterfallStep)
Parameters
- id
-
string
Unique ID of the dialog being regsitered or retrieved.
- dialog
(Optional) dialog or waterfall to register.
- dialog: {Dialog} - Dialog to add.
- dialog: {IDialogWaterfallStep[]} - Waterfall of steps to execute. See IDialogWaterfallStep for details.
- dialog: {IDialogWaterfallStep} - Single step waterfall. Calling a built-in prompt or starting a new dialog will result in the current dialog ending upon completion of the child prompt/dialog.
Returns
Searches the library and all of its dependencies for a specific dialog. Returns the dialog if found, otherwise null.
function findDialog(libName: string, dialogId: string)
Parameters
- libName
-
string
Name of the library containing the dialog.
- dialogId
-
string
Unique ID of the dialog within the library.