I have working code for a BotBuilder dialog. I now want to have the dialog started at 8:30 am each Monday-Friday using node-schedule like below.
var rule = new schedule.RecurrenceRule();
// Run the task Mondays-Fridays
rule.dayOfWeek = [0, new schedule.Range(1, 5)];
rule.hour = 8;
rule.minute = 30;
schedule.scheduleJob(rule, beginStatusDialog);
console.log('Schedule initialzed.');
When running this "Schedule initialized" is written as expected. So, I have wrapped my dialog code in the function beginStatusDialog like below.
function beginStatusDialog() {
// Begin dialog - This is a question bot that uses a waterfall technique to prompt users for input.
const bot = new builder.UniversalBot(connector, [
function (session) {
session.send("Welcome to the daily status check " + session.message.user.name + ".");
builder.Prompts.text(session, "What did you do yesterday?");
},
function (session, results) {
session.dialogData.yesterday = session_yesterday = results.response;
builder.Prompts.text(session, "What will you do today?");
},
function (session, results) {
session.dialogData.today = session_today = results.response;
builder.Prompts.text(session, "Are there any obstacles holding you up? Note: An email will be sent with your responses.");
},
function (session, results) {
session.dialogData.obstacles = session_obstacles = results.response;
session_username = session.message.user.name;
// Write responses to DB
executeStatement(session_username, session_yesterday, session_today, session_obstacles);
//Process request and display details
session.send(`Daily status details: <br/>Yesterday: ${session.dialogData.yesterday} <br/>Today: ${session.dialogData.today} <br/>Obstacles: ${session.dialogData.obstacles}`);
session.dialogData = {};
session.endDialog();
}
]).set('storage', inMemoryStorage); // Register in-memory storage
}
When I run this in the botframework-emulator I receive the following error:
Is it wrong to wrap the dialog in a function? If so what is the correct way for the scheduler to call the dialog? Anyone else have experience with this particular scenario?
Any help/pointers will be greatly appreciated. :)
Thank you.
Edit:
Gary Liu's comment got me to thinking. So I instantiated the bot ouside of the function like the below and it no longer throws an error but it doesn't do anything at the scheduled time.
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
Then I start it up inside the function with bot.dialog - or at least that is my intention:
function beginStatusDialog() {
// Begin dialog - This is a question bot that uses a waterfall technique to prompt users for input.
//const bot = new builder.UniversalBot(connector, [
bot.dialog([
function (session) {
session.send("Welcome to the daily status check " + session.message.user.name + ".");
builder.Prompts.text(session, "What did you do yesterday?");
Anyway I am looking at this further.
As always any help/pointers will be appreciated - thank you.