也许我很傻,但是我真的不懂如何阅读node.js version of Microsoft's bot framework sdk。我试图弄清楚如何在beginDialogAction()中使用endConversationAction()或ConsoleConnector bot。该文档说它在触发时会注册一个动作,但没有提及如何触发它。我想利用它可以在正常流程之外的调用栈中间添加对话框的想法。
抱歉,我无法提供代码,但是我可以提供此代码...
var connector = new builder.ConsoleConnector().listen();
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector);
bot.dialog('/', [
function( session ) {
builder.Prompts.text(session, "blah blah blah?");
},
function( session, results ) {
// ...
session.beginDialog('/foo');
session.endDialog();
}
]);
bot.dialog('/foo', [
function( session, args ) {
// ...
},
function( session, results ) {
// ...
session.endDialog();
}
]);
bot.use({ botbuilder: function( session, next ) {
// CALL THE ACTION 'bar' HERE TO ADD '/help' to the callstack
// ...
next();
}});
bot.beginDialogAction('bar', '/help');
bot.dialog('/help', [
function( session, args ) {
// ...
},
function( session, results ) {
// ...
session.endDialog();
}
]);
最佳答案
我理解和使用它的方式:动作是可以在对话框流中调用以触发其他对话框和参数的显式操作。
例如,这是您的机器人的正常流程,该流程由对话框输入触发:
bot.dialog('/', new builder.IntentDialog()
.matches(/^command1/i, '/command1')
.matches(/command2/i, '/command2')
.onDefault(..));
bot.dialog('/command1', [
function (session) {
session.send('Hello.');
}
]);
例如,您可以使用对话框动作直接触发动作,而不是路由到函数:
.onDefault(builder.DialogAction.send("Hello World!"))
至于beginDialogAction(),请将其视为两者之间的交叉。考虑以下卡片示例:
// An actions is just a normal card of any type that
// features a dialogAction with the respective parameters.
bot.dialog('/Action', [
function (session) {
// Create a new message. Note that cards are managed as attachments
// that each channel can interpret as they see fit. Remember that some
// channels are text only, so they will have to adapt.
var msg = new builder.Message(session)
.textFormat(builder.TextFormat.xml)
.attachments([
// This is the actual hero card. For each card you can add the
// specific options like title, text and so on.
new builder.HeroCard(session)
.title("Hero Card")
.subtitle("Microsoft Bot Framework")
.text("Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.")
.images([
builder.CardImage.create(session, "https://bot-framework.azureedge.net/bot-icons-v1/bot-framework-default-7.png")
])
.buttons([
builder.CardAction.dialogAction(session, "News", "https://blog.botframework.com/", "Get news")
])
]);
// Send the message to the user and end the dialog
session.send(msg);
session.endDialog();
}
]);
请注意,此卡通过按钮触发一个名为“新闻”的操作,该操作的参数为“ https://blog.botframework.com/”。将此功能视为在对话框中按下卡上的按钮即可调用的功能。现在定义该函数,我们这样做:
// An action is essentially a card calling a global dialog method
// with respective parameters. So instead of using choice prompts
// or a similar waterfall approach, you can link to separate
// dialogs.
// The dialog action will route the action command to a dialog.
bot.beginDialogAction('News', '/News');
// Create the dialog itself.
bot.dialog('/News', [
function (session, args) {
session.endDialog("Loading news from: " + args.data);
}
]);
因此,我们可以根据其他对话框触发的传递的参数来显示通用新闻对话框。
说得通?