BotCaptain Classes Overview
Overview of Classes their methods, and cardinality

Disclaimer

The following document assumes, at the very least, a general understanding of Microsoft Bot Framework SDK including basic state management and dialog implementation. The contents of BotCaptain make heavy use of the SDK.
Cardinality relationships are limited to the scope of what was developed with the SDK and other modules. This is to avoid tracking cardinalities within the SDK and/or libraries themselves.

Context Handlers

Context handler classes read, modify, and record context objects directly. Functions include logging, channel specific text sanitation, and inspection for the presence of a dialog and/or adaptive card command.
Cardinality between the messageParser and index (main) classes should remain as a one-to-one relationship. Branching occurs within messageParser when calling separate dialogs which results in one-to-many relationship(s).
​Dialogs may possess one-to-one relationships with supporting methods including aforementioned sanitation and "prompts" for input validation.
Cardinality plot for Context Handlers

class messageParser

Main context handler for the bot.
Requires:
  • const botbuilder(ActivityTypes)
  • const botbuilder-dialogs(DialogSet, DialogTurnStatus)
  • const CassandraService
  • var crypto
  • const MessageQueue
  • const Message
  • const config
  • const EmailDialog
  • const ReminderDialog
  • const TaskDialog
  • const ProfileDialog
  • const RoleDialog
  • const AssignDialog
  • const MinutesDialog
  • const xAPI_Statements
  • const fileIO
  • const jsonfile

async onTurn(turnContext)

TurnContext Parameters:
  • activity.channelId
  • activity.from.name
  • activity.from.id

class scheduler

Utility class that handles all scheduling functions for the bot.
Requires:
  • var node-schedule
  • var nodemailer
  • var jsonfile
  • const log
  • const config

static email(address, date, time, message)

Sends scheduled email to address denoted in student's profile.
"date" argument must adhere to TimeEx format. Click here for more details on the format.

class channelValidation

Fixes channel specific errors.

static validateChannel(turnContext)

Returns:
  • Sanitized value

Dialogs

Dialogs are Microsoft Bot framework's main method of allowing one-on-one conversations between a user and the bot. They tend to follow a waterfall structure and follow an "ask-respond" type of pattern.
All dialogs with the exception of profileDialog are activated via the user denoting the dialogs name with the "!" symbol followed by the name of the dialog.
Dialogs utilize "prompts" for input validation. Dialogs may also leverage supporting methods for miscellaneous tasks (sanitizing messages, setting schedules etc.)
As explained in the Context Handlers section, cardinality in relationship to the messageParser class is one-to-many. Cardinality in relationship to supporting methods (prompts, channel validation, and scheduler) is one-to-one.
Dialog-Prompt Composition Relationship
Because only one student should be interfacing with a dialog at a given time, messageParser will record a GUID for a student who initiates a dialog within that channel in the "dialogID.json" file. This file is checked with each prompt to ensure that only the student who initiated the dialog is interfacing with the bot (i.e. a student is not sending data to the bot in the context of another student).
// Logic for calling dialog from messageParser.js
let command = utterance.slice(1);
let dialog = command.concat('Dialog');
fileIO.setDialog(channelID, userID);
log.info(`[INFO] User ${user} initiated a command.`);
await dc.beginDialog(`${dialog}`, user);
// Example GUID's used for comparison
{
"test": {
"dialogID": "user1"
},
"emulator": {
"dialogID": "55c9ad7c-9ea0-43fb-8d0a-0afcfd769a5b"
},
...
}

class profileDialog

Sets up user profile upon first arrival. Extends ComponentDialog.
TurnContext Parameters:
  • activity.from.name
  • activity.text
Requires:
  • const botbuilder-dialogs(ComponentDialog, TextPrompt, WaterFallDialog)
  • const ClassPrompt
  • const TeamPrompt
  • const EmailPrompt
  • const NickPrompt
Returns:
  • User profile object

class reminderDialog

Sets email reminders for tasks that are in team database. Extends ComponentDialog.
TurnContext Parameters:
  • activity.from.name
  • activity.text
User Parameters
  • Profile.email
  • Profile.class
Requires:
  • const botbuilder-dialogs(ComponentDialog, TextPrompt, WaterFallDialog
  • const TaskPrompt
  • const DatePrompt
  • const TimePrompt
Returns:
  • Email schedule job
  • values.schedule
  • xAPI Record to LRS if installed

class taskDialog

Returns requested task description and due date in the channel. Extends ComponentDialog.
TurnContext Parameters:
  • activity.from.name
  • activity.text
Requires:
  • const botbuilder-dialogs(ComponentDialog, TextPrompt, WaterFallDialog)
  • const jsonfile
  • const TaskPrompt
Returns:
  • Profile.class
  • Task Description, Status and Due Date
  • xAPI Record to LRS if installed

Prompts

Prompts are reusable components that perform input validation for dialog steps. Cardinality between prompts and dialogs can be a one-to-many relationship, provided the prompt is reused.
All prompts perform a comparison with the dialogID.json file to ensure that only the student that initialized the dialog is sending inputs in the dialog step.
Prompts association diagram

class classPrompt

Checks that user inputs a valid class number. Extends TextPrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const botbuilder-dialogs(TextPrompt)
  • const fs
  • const fileIO
  • const log
Returns:
  • Boolean
  • Class number for user profile if true
​

class datePrompt

Checks that user inputs a valid class number. Extends DateTimePrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const botbuilder-dialogs(DateTimePrompt)
  • const fileIO
  • const log
Returns:
  • Boolean
  • Date for scheduler if true
​

class emailPrompt

Checks that user inputs correct email. Extends TextPrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const validator
  • const botbuilder-dialogs(TextPrompt)
  • const channelValidation
  • const fileIO
  • const log
Returns:
  • Boolean
  • Email for user profile if true
​

class nickPrompt

Checks that user inputs a valid nick name. Extends TextPrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const botbuilder-dialogs(TextPrompt)
  • const fileIO
  • const log
Returns:
  • Boolean
  • Nick name for user profile if true
​

class taskPrompt

Checks that user inputs a valid task. Extends ChoicePrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const botbuilder-dialogs(ChoicePrompt)
  • const fileIO
  • const log
Returns:
  • Boolean
  • Task if true
​

class teamPrompt

Checks that user inputs a valid team. Extends ChoicePrompt.
TurnContext Parameters:
  • activity.channelID
  • activity.from.id
Requires:
  • const botbuilder-dialogs(ChoicePrompt)
  • const fileIO
  • const log
Returns:
  • Boolean
  • Team if true