bot-graph-dialog
This node module is an extension for Microsoft Bot Framework.
Use this library to define graph-based dialogs instead of the waterfall dialogs supported today. Also, instead of hard coding your dialogs, use this library to define your dialogs as jsons. These dialogs can be loaded dynamically from any external data source (db, file system, etc.)
Code sample for how to use this library can be found here.
Getting Started
Usage
npm install [--save] bot-graph-dialog
Code Sample
var builder = ;var BotGraphDialog = ; var connector = appId: '<microsoft_bot_id>' appPassword: '<microsoft_bot_password>' ;var bot = connector;var intents = ; bot; // handler for loading scenarios from external datasource { return { console; // implement loadScenario from external datasource. var scenarioObj = ... ; };} BotGraphDialogGraphDialog // attach stomach pain graph dialog to handle 'stomach' message ;
See sample bot app here
Sample Scenarios
Follow these samples as a reference to create your own scenarios.
Schema Break Down
Each step\scenario in the schema is recursive.
id
- The id for the steptype
[required] - The type of the step:text
sequence
prompt
score
heroCard
carousel
handler
end
steps
- An array of steps or other scenariosmodels
- see [#Models]
Steps Types
type: "text"
Display a text which can also be formatted with dialog variables.
Properties:
type: "sequence"
This step is a wrapper of one or more subsidiary steps.
Properties:
type: "prompt"
Prompt for a defined user response.
Properties:
Prompt types can be one of:
text
[default] - Prompts for free text. This options is set in case notype
property is providednumber
- Request for a valid numbertime
- Request for a time construct like "2 hours ago", "yesterday", etc.confirm
- Yes \ No
type: "score"
Get a text from the user and resolve the intent against a single or multiple intent recognition (Luis) APIs.
Properties:
For models, see [#Models].
Under models, specify one or more models you have defined under models
property.
Under scenarios, define a condition for expected intent and which scenario \ step it should jump to.
type: heroCard
Creates a Hero Card, displaying images and using buttons
type: carousel
Creates a Carousel control, which is a list of Hero Card controls in the same structure as demonstrated above:
type: "handler"
Enables providing a custom code to handle a specific step.
Properties:
name
the name for this handler. This will be provided to the callback for loading this handler.
The data that is collected during the dialog can be found in session.dialogData.data[<variable name>]
type: "end"
End the dialog and ignore any further steps.
Properties:
Models
This property defined the models that can be used for intent recognition throughout the dialog.
Text Format
When prompting or displaying text, it is possible to use a format to insert session variables like that:
,
Validations
There following validations are currently supported for validating user input. When a node contains a validation condition, the user will be prompted to provide the value until it satisfies the validation condition:
date validation
regex validation