Ever wanted to create a conversation with full validation of entries and control over the flow of the dialogue, looping back to change previously entered values and finally being able to execute logic based on what the user is happy with. Well, BotFlow is here. BotFlow is a new dialogue flow generator, which from a simple CSV file, will generate all the required AIML files.
A new feature in v1.8.0 ( released today 16th Jan 2018 ) is Bot Dialog ( or Flow ) Generator. AIML can be a tough learning curve at times, and trying to learn the various mechanisms for controlling flow, validating input and handling execution requires some effort.
As an example, imagine a basic flight booking system, that asks you were from and where do you want to fly, on what date, how many passengers and what class you want to fly. This can be defined in a basic CSV file as follows
```csv
Step,Prompt,Variable,Type, Next, Condition
SOURCE,Where would you like to fly from,City,"Select(London, Edinburgh, Glasgow, Manchester)", DEST, =*, LONDON, =London
LONDON,Where from in London are you flying from,London,"Select(Stanstead, Heathrow, Gatwick)", DEST, =*
DEST,Where would you like to fly to,Destination,"Select(New York, Washington, San Francisco)",DATE, =*
DATE,When would you like to fly,Date,Date(DD/MM/YYYY),PASSENGERS, =*
PASSENGERS,How many people are flying,Passengers,"Int(1,5)", CLASS, =*
CLASS,What class do you want to fly,Class,"Select(Economy, Premium Economy, Business, First)",
```
The steps are as follows
* SOURCE - Ask the user which city they want to fly from
* LONDON - If the user says London, an optional additional step that asks which airport in London to fly from
* DEST - Where do they want to fly to
* DATE - When do they want to fly
* PASSENGERS - How many are flying ( between 1 and 5 allowed )
* CLASS - Which class do they want to fly
Imagine running this through a simple command line which is able to create the following fully complete AIML File
```xml
START FLIGHTBOOK
FLIGHTBOOK
FLIGHTBOOK STEP SOURCE
FLIGHTBOOK STEP SOURCE
Where would you like to fly from - (London, Edinburgh, Glasgow, Manchester or exit)
*
Where would you like to fly from *
FLIGHTBOOK STEP LONDON
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP SOURCE
EXIT
Where would you like to fly from *
EXIT FLIGHTBOOK
FLIGHTBOOK STEP LONDON
Where from in London are you flying from - (Stanstead, Heathrow, Gatwick or exit)
*
Where from in London are you flying from *
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP DEST
FLIGHTBOOK STEP LONDON
EXIT
Where from in London are you flying from *
EXIT FLIGHTBOOK
FLIGHTBOOK STEP DEST
Where would you like to fly to - (New York, Washington, San Francisco or exit)
*
Where would you like to fly to *
FLIGHTBOOK STEP DATE
FLIGHTBOOK STEP DATE
FLIGHTBOOK STEP DATE
FLIGHTBOOK STEP DEST
EXIT
Where would you like to fly to *
EXIT FLIGHTBOOK
FLIGHTBOOK STEP DATE
When would you like to fly - (DD/MM/YYYY or exit)
*
When would you like to fly *
VALID DATE
FLIGHTBOOK STEP PASSENGERS
FLIGHTBOOK STEP DATE
EXIT
When would you like to fly *
EXIT FLIGHTBOOK
FLIGHTBOOK STEP PASSENGERS
How many people are flying - (1 to 5 or exit)
*
How many people are flying *
VALID INT 1 5
FLIGHTBOOK STEP CLASS
FLIGHTBOOK STEP PASSENGERS
EXIT
How many people are flying *
EXIT FLIGHTBOOK
FLIGHTBOOK STEP CLASS
What class do you want to fly - (Economy, Premium Economy, Business, First or exit)
*
What class do you want to fly *
EXECUTE FLIGHTBOOK
EXECUTE FLIGHTBOOK
EXECUTE FLIGHTBOOK
EXECUTE FLIGHTBOOK
FLIGHTBOOK STEP CLASS
EXIT
What class do you want to fly *
EXIT FLIGHTBOOK
```
## Configuration
The first line of the csv should have the follow headers
```csv
Step,Prompt,Variable,Type,Next,Condition
```
Each preceeding line should then match these columns headers as follows
* Step - The name of the step, used to direct the flow
* Prompt - Text to display as the question ( template )
* Variable - The name of the variable capturing the user input
* Type - The type of the variable ( see below )
* Next - Next Step ( repeats see below )
* Condition - The condition that would move the flow to the Next Step ( repeats see below )
### Type
BotFlow currently supports the follow types of variable
#### Int.
An integer value that can have optional min and max restrictors
* Int - Int no min or max value
* Int(m) - Int with a max value
* Int(n,m) - Int with a min n, and max m value
* If the validation fails then the same question is asked for again
#### Select.
A list of items for the user to select from.
* Select(Item1, Item2, ... ItemN)
* If the validation fails then the same question is asked for again
#### Date.
A date value in the format dd/mm/yyyy
* A future release will allow the developer to set the date validation format
* If the validation fails then the same question is asked for again
### Entry/Exit
Flowbot creates a single entry step called START 'FLOWNAME', which you can call from outside of the flowbot grammar. Typically you would include in your grammar the following
```xml
I WANT TO BOOK A FLIGHT
START FLIGHTBOOK
```
When the conversation finishes, the bot calls EXECUTE 'FLOWNAME', This grammar is not included and you should create your own static grammar to pick up the variables and process them. An example would be
```xml
EXECUTE FLIGHTBOOK
Ok, I'll book a flight matching the following:
flying from ,
,
to ,
on ,
with passengers,
in Class,
```
### Next/Condition
A list of pairs consisting of a Destination tag which should be a valid step in a subsequent item and a condition for which the step should be moved to. Typically this is one of the items from a Select statement. The first of the pairs should be =* which is the default Step if no other validation succeeds or exists.
## Execution
Botflow is contained within the src\utils\botflow, there is a basic shell script for running the util
```bash
#!/usr/bin/env bash
clear
export PYTHONPATH=./src:.
python3 src/botflow.py -flow "../../../bots/botflow/flow/flightbook.csv" -topic flightbook -aiml "../../../bots/botflow/aiml"
```
This will execute the neccassary flow generator for a flight booking bot contained within bots\botflow folder.
The script takes 4 parameters
* -flow - CSV Flow file to load and process
* -topic - Topic name
* -lib - Library of aiml files. Flowbot uses prewritten aiml files for validation, these are copied into your aiml folder during the generation process
* -aiml - Directory to create aiml files in