-
Notifications
You must be signed in to change notification settings - Fork 2
/
reminderDialog.js
90 lines (72 loc) · 3.35 KB
/
reminderDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { ComponentDialog, TextPrompt, WaterfallDialog} = require('botbuilder-dialogs');
const reminderId = 'reminderDialog';
const jsonfile = require('jsonfile');
//Module for scheduling emails
const {scheduler} = require('./scheduler.js');
//Prompt for Date
const { DatePrompt } = require('./prompts/datePrompt');
const GET_DATE_PROMPT = 'datePrompt';
//Prompt for Time
const { TimePrompt } = require('./prompts/timePrompt');
const GET_TIME_PROMPT = 'timePrompt'
//Prompt for Task
const { TaskPrompt } = require('./prompts/taskPrompt');
const GET_TASK_PROMPT = 'taskPrompt';
//Module for recording xAPI statements
const { xAPI_Statements } = require('./xAPI_Statements');
class ReminderDialog extends ComponentDialog {
constructor(id){
super(id);
this.initialDialogId = reminderId; //*** Not needed? */
this.addDialog(new TextPrompt('textPrompt'));
this.addDialog(new WaterfallDialog(reminderId, [
this.promptForTask.bind(this),
this.captureTask.bind(this),
this.promptForDate.bind(this),
this.promptForTime.bind(this),
this.completeReminder.bind(this)
]));
//Create xAPI_Handler Object
this.xAPI_Handler = new xAPI_Statements();
//Add Prompts
//GET_TASK_PROMPT Will validate user tasks
this.addDialog(new TaskPrompt(GET_TASK_PROMPT));
//GET_DATE_PROMPT will validate input date
this.addDialog(new DatePrompt(GET_DATE_PROMPT));
//GET_TIME_PROMPT Will validate input time
this.addDialog(new TimePrompt(GET_TIME_PROMPT));
}
async promptForTask(step){
step.values.task = {};
step.values.profile = {};
step.values.profile = step.options.profile;
var tasks = jsonfile.readFileSync(`./Resources/Classes/${step.values.profile.class}/Teams/${step.values.profile.team}/tasks.json`);
let task_list = Object.keys(tasks);
return await step.prompt(GET_TASK_PROMPT, 'What task would you like to see?',task_list);
}
async captureTask(step){
var tasks = jsonfile.readFileSync(`./Resources/Classes/${step.values.profile.class}/Teams/${step.values.profile.team}/tasks.json`);
step.values.task = tasks[`${step.result.value}`]
return await step.next();
}
async promptForDate(step){
step.values.date = {}
return await step.prompt(GET_DATE_PROMPT, 'What date would you like this reminder to be sent?');
}
async promptForTime(step){
step.values.date = step.result;
step.values.time = {};
return await step.prompt(GET_TIME_PROMPT, 'What time would you like this reminder to be sent?');
}
async completeReminder(step){
step.values.time = step.result;
step.values.schedule = {};
step.values.schedule.date = step.values.date[0].value;
step.values.schedule.task = step.values.task.description;
scheduler.email(`${step.values.profile.email}`,`${step.values.schedule.date}`, `${step.values.time}`, `${step.values.schedule.task}`);
this.xAPI_Handler.recordSchedule(step.values.profile.email);
await step.context.sendActivity(`Reminder will be sent to ${step.values.profile.email}, on ${step.values.schedule.date}, at ${step.values.time}.`)
return await step.endDialog(step.values.schedule);
}
}
exports.ReminderDialog=ReminderDialog;