使用 Node-Schedule 开始 BotBuilder 对话
Use Node-Schedule to begin a BotBuilder Dialog
我有 BotBuilder 对话框的工作代码。我现在想让对话在每个星期一至星期五的 8:30 开始,使用如下节点时间表。
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.');
当运行ning 这个"Schedule initialized" 写的很正常。所以,我将我的对话框代码包装在 beginStatusDialog 函数中,如下所示。
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
}
当我在 botframework-emulator 中 运行 时,我收到以下错误:
用函数包裹对话框是不是错了?如果是这样,调度程序调用对话框的正确方法是什么?还有其他人有过这种特殊情况的经验吗?
任何 help/pointers 将不胜感激。 :)
谢谢。
编辑:
Gary Liu 的评论让我开始思考。所以我像下面这样实例化了函数之外的机器人,它不再抛出错误,但它在预定的时间没有做任何事情。
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
然后我用 bot.dialog 在函数内部启动它 - 或者至少这是我的意图:
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?");
无论如何,我正在进一步研究。
一如既往,任何 help/pointers 将不胜感激 - 谢谢。
我可以通过将调度程序放在 conversationUpdate 中来使其工作。按照 Reccurance Rule Scheduling 的示例,我将 scheduleJob 放在一个匿名函数中,然后调用 bot.beginDialog()。 beginDialog 创建对话堆栈并开始对话流。传递 message.address 是必要的,因为它将当前用户信息分配给堆栈。
在我的测试中,我每分钟 运行(查看日志时间戳)。
我尝试使用命名函数代替匿名函数来创建它来调用 bot.beginDialog() - 调度程序似乎不喜欢这样(至少在启动机器人的上下文中).它没有响应。
希望得到帮助!
var rule = new schedule.RecurrenceRule();
// Run the task Mondays-Fridays
rule.dayOfWeek = [0, new schedule.Range(1, 5)];
rule.hour = 13;
// rule.minute = 08;
// schedule.scheduleJob(rule, beginStatusDialog);
console.log('Schedule initialzed.');
var bot = new builder.UniversalBot(connector);
bot.set('storage', new builder.MemoryBotStorage());
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
schedule.scheduleJob(rule, function () {
bot.beginDialog(message.address, '/');
})
}
});
}
});
bot.dialog('/', [
function (session) {
builder.Prompts.text(session, "What is your name?");
},
function (session) {
session.send("You said %s", session.message.text);
}
]);
我有 BotBuilder 对话框的工作代码。我现在想让对话在每个星期一至星期五的 8:30 开始,使用如下节点时间表。
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.');
当运行ning 这个"Schedule initialized" 写的很正常。所以,我将我的对话框代码包装在 beginStatusDialog 函数中,如下所示。
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
}
当我在 botframework-emulator 中 运行 时,我收到以下错误:
用函数包裹对话框是不是错了?如果是这样,调度程序调用对话框的正确方法是什么?还有其他人有过这种特殊情况的经验吗?
任何 help/pointers 将不胜感激。 :)
谢谢。
编辑:
Gary Liu 的评论让我开始思考。所以我像下面这样实例化了函数之外的机器人,它不再抛出错误,但它在预定的时间没有做任何事情。
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
然后我用 bot.dialog 在函数内部启动它 - 或者至少这是我的意图:
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?");
无论如何,我正在进一步研究。
一如既往,任何 help/pointers 将不胜感激 - 谢谢。
我可以通过将调度程序放在 conversationUpdate 中来使其工作。按照 Reccurance Rule Scheduling 的示例,我将 scheduleJob 放在一个匿名函数中,然后调用 bot.beginDialog()。 beginDialog 创建对话堆栈并开始对话流。传递 message.address 是必要的,因为它将当前用户信息分配给堆栈。
在我的测试中,我每分钟 运行(查看日志时间戳)。
我尝试使用命名函数代替匿名函数来创建它来调用 bot.beginDialog() - 调度程序似乎不喜欢这样(至少在启动机器人的上下文中).它没有响应。
希望得到帮助!
var rule = new schedule.RecurrenceRule();
// Run the task Mondays-Fridays
rule.dayOfWeek = [0, new schedule.Range(1, 5)];
rule.hour = 13;
// rule.minute = 08;
// schedule.scheduleJob(rule, beginStatusDialog);
console.log('Schedule initialzed.');
var bot = new builder.UniversalBot(connector);
bot.set('storage', new builder.MemoryBotStorage());
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
schedule.scheduleJob(rule, function () {
bot.beginDialog(message.address, '/');
})
}
});
}
});
bot.dialog('/', [
function (session) {
builder.Prompts.text(session, "What is your name?");
},
function (session) {
session.send("You said %s", session.message.text);
}
]);