# BotCaptain Classes Overview

## Disclaimer

The following document assumes, at the very least, a general understanding of [Microsoft Bot Framework SDK ](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-overview?view=azure-bot-service-4.0)including basic state management and dialog implementation. The contents of BotCaptain make heavy use of the SDK.&#x20;

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).&#x20;

[Dialogs ](#dialogs)may possess one-to-one relationships with supporting methods including aforementioned sanitation and "[prompts](#prompts)" for input validation.

![Cardinality plot for Context Handlers](https://2970422944-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIy853ylmwJWOGNM8Ow%2Fuploads%2FeR8mi9sjet8qJav6THxz%2Fimage.png?alt=media\&token=69e21cf6-4927-4dda-adb6-15610fc29833)

### 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.

{% hint style="warning" %}
"date" argument must adhere to TimeEx format. Click [here](https://hexdocs.pm/timex/Timex.html) for more details on the format.
{% endhint %}

### 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.&#x20;

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](#prompts)" for input validation. Dialogs may also leverage supporting methods for miscellaneous tasks (sanitizing messages, setting schedules etc.)

As explained in the[ Context Handlers ](#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](https://2970422944-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIy853ylmwJWOGNM8Ow%2Fuploads%2Ff4AkRdRSzlk1sP0EkCre%2Fimage.png?alt=media\&token=a689640a-066a-4866-9758-31affcca5141)

{% hint style="info" %}
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).
{% endhint %}

```javascript
   // 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);
```

```json
// 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](https://2970422944-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIy853ylmwJWOGNM8Ow%2Fuploads%2FLrSfv1t64OqZw2cwQ16g%2Fimage.png?alt=media\&token=0cc34e96-ab2a-4d33-9ff7-3648c541639a)

### 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**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n0m4d.gitbook.io/botcaptain/developers/main-classes-overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
